Reputation: 125
How do I know how long a user or a single IP address spent on a page of my site? Can I use any event of JavaScript?
Upvotes: 3
Views: 402
Reputation: 1
Use Ajax to send keep-alive information to your backend. Save it as session data in your database.
The session data can save the current page the user is watching and was active last time. Send the keep-alive information using, for example, setInterval
every x seconds (depending on resolution needs).
There is no need for cron...
Upvotes: 0
Reputation: 16084
I will go for a Redis installation that keeps tracks of a specific hash created by a combination of IP address, USERAGENT and login information (if you have it).
Save the stuff in Redis with a timestamp (use hashes or whatever you like) and then add a "farewell" timestamp when the user logs out or leaves the site for an external link or unloads the page.
Upvotes: 0
Reputation: 45124
To implement inside your application
In this way, I can keep track of users accurately to the minute. Just divide by 60 to get the hours.
Else
Google Analytics. You can check out it's features here.
Upvotes: 0
Reputation: 219834
This is what Google Analytics is for. It keeps track of visitors to your website and reports statistics to you like such as length of visit. They even offer an API to help you get this information.
Upvotes: 5