I\'m looking to track users average time on a website (in the same way that Google analytics does) for internal administration.
What\'s the easiest way to do this?
Main way I can think of:
When the user first hits a page, you log, say, their IP address, the page loaded, and the time. Then, using some Javascript and AJAX, when they leave the page, you use the unload
event to send to an AJAX handler that records the page and when they leave.
You would need to use some sort of ID, apart from a session, to store the page visit. Say I have 5 instances of the homepage open, you'd want to log each one individually. So, something like this:
index.php
code: 2345
)If they visit index.php
again, you would generate another code, say, 36789
. Use something that generates a random GUID is best, so you can (essentially) ignore any possibilities of collisions on the same IP/page/code combination.