0

How to measure a time spent on a page?

I came across the above thread, which has a solution, but the user could easily modify the inital date value making the time they spent on the page any time they wanted.

I need to somehow get a rough estimate of how long the user was on the page that the user cannot modify.

Any ideas?

Community
  • 1
  • 1
Max Hudson
  • 9,961
  • 14
  • 57
  • 107
  • 2
    Read the comment for the accepted [answer](http://stackoverflow.com/a/4667145/7613). – Andrew May 31 '12 at 21:22
  • While that is an option, a user could still send the end request early, potentially causing problems, or simply shortening their time. Something like this is not foolproof, your best bet is to do what you can and hope it works most of the time. – dpk2442 May 31 '12 at 21:27

1 Answers1

0

First, you need to determine how important seconds or minutes are.

Measure the time spent on page using javascript.

Implement a heart beat with an unique id per loaded page, which runs every n seconds or n minutes to update how long a user has stayed on your page.

Call the same heartbeat function using onbeforeunload too (which fails many times, but when it works it will improve your accuracy).

oxygen
  • 5,891
  • 6
  • 37
  • 69