How do I know how long a user or one IP address is spent on a page on my site?
How do I know how long a user or one IP address is spent on a page on my site? Can I use any JavaScript event ?
source to share
This is Google Analytics . It tracks visitors to your site and tells you statistics such as the length of the visit. They even offer APIs to help you get this information.
source to share
For implementation inside your application
- When a user loads a page, their "last page load time" is updated in the database.
- The cron script runs every minute. It looks for users whose "page load time" was at the last minute.
- Increase the time spent on the site for each user found.
This way I can track users down to the minute. Just divide by 60 to get the hours.
Else
Google Analytics . You can check it out here .
source to share
I'll go for a Redis setup that saves the tracks of a specific hash generated by a combination of IP address , USERAGENT, and login information (if you have one).
Save stuff in Redis with a timestamp (use hashes or whatever) and then add a goodbye timestamp when the user logs out or leaves the site for an external link or unloads the page.
source to share
Use Ajax to send keep-alive information to your server. Save it as session data in your database.
Session data can save the current page the user is viewing and was last active. Send keep-alive information using for example setInterval
every x seconds (depending on permission needs).
No cron needed ...
source to share