Welcome Guest, Not a member yet? Register   Sign In
Track users logged in time
#1

[eluser]steelaz[/eluser]
I need to track how much time users spend logged in on the website. Anyone did this before? Any pointers?
#2

[eluser]richthegeek[/eluser]
I assume with these users you have a database, so add two fields "login" and "action", both UNSIGNED integers.

When the user logs in, set login and action to time()

On each page load (and as such an authentication, so you can use an UPDATE and affected_rows rather than SELECT and num_rows) update action to time()

to work out the login time, do "action - login" for the number of seconds.
#3

[eluser]richthegeek[/eluser]
oh yes, if the site is an application, you can set up an AJAX heartbeat to update their action time.
#4

[eluser]steelaz[/eluser]
Thanks. What about when user goes idle? Maybe reduce session timeout and track sessions with cron?

'heartbeat' sounds good, but I'd like to avoid AJAX if possible.
#5

[eluser]richthegeek[/eluser]
steelaz - if you just use sessions for auth it won't be a problem - either that or do this on every request:
Code:
UPDATE `usersTable` SET `action` = '0' WHERE `action` = '($time - 900)'
#6

[eluser]Jakob Buis[/eluser]
Google Analytics does that (and much more stats!) for you. Why build it yourself?




Theme © iAndrew 2016 - Forum software by © MyBB