douqiao1983 2012-01-25 22:38
浏览 18

如何在网站上跟踪用户使用情况?

I am using PHP/MYSQL. Each time a user logs in we insert the time they logged in and the date they logged in. While its easy for us to tell how many users logged in a particular day i am not sure how to calculate how much time they spent on the site.

For instance, just like a user signs in and we insert record into login_tracking table we also update that record when the user hits "logout" with the time they logged out. That way we subtract the time logged in and logged out and we get each persons time spent, but what happens if majority of people don't hit "logout" and instead clear cookies/cache or just close the window/tab the site was open in?

Is there a better way to do this? I am using Google Analytics, which gives me users and visits that showed up everyday but i want something proprietary to track usage?

Any ideas what i can do?

Update: @Paul asked if i was using Sessions. I am and this is how i am using it:

$username = $_SESSION["username"];

  • 写回答

4条回答 默认 最新

  • dpoxk64080 2012-01-25 22:47
    关注

    I made a simple website chat script doing something kind of like this.

    What I did was store their session id and the time stamp in a table. Every page they visit, I would update the timestamp. When they log out, I destroy their log. I also had the update script check for other users that were "inactive" for 5 minutes and deleted them. You could accomplish the same thing by setting up a cron job to run every 5 or 10 minutes and check those timestamps which are older than 5-10 minutes and mark those users as inactive and then calculate total time spent on the site.

    If you just want a count of users active at a specific time, I would look into http://whos.amung.us/. Its a simple plugin that counts the number of people online at any given time and where they are coming from.

    评论

报告相同问题?