I would like to measure how much time a user spends on my website. It\'s needed for a community site where you can say: \"User X has been spending 1397 minutes here.\"
A
What you could do is check if a user is active on the page and then send an ajax request to your server every X seconds (would 60 secs be fine?) that a user is active or not on the page.
Then you can use the second method you have mentioned to calculate the time difference between two 'active' timestamps that are not separated by more than one or two intervals. Adding these would give the time spent by the user on your site.