Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do analytics applications (like StatCounter or GoogleAnalytics) measure time spent on page? Is that possible without JavaScript?

I guess they reloading 1x1 web-bug or something after certain amount of time, am I right?

share|improve this question

You could use a web-bug, AJAX tag or an iframe with a refresh meta tag, but those still don't really account for tabbed browsers or people who have multiple browser windows open (or people leaving their desk with a window open).

The Nielson meter supposedly gives credit only to the in-focus tab/window and measures mouse/keyboard activity so that if there's more than 30 minutes of inactivity, only 1 minute is credited. But this requires each user to install desktop software.

You could also potentially estimate time spent with only log file analysis. But that requires setting an abandonment threshold so that if, say, there is over 30 minutes between requests, then you assume the user abandoned the first page after a minute. Ideally, you'd analyze the page content to determine what the abandonment threshold ought to be. E.g. if it's a long, unpaginated article that takes 30 minutes to read, then you might make the abandonment threshold bigger than a page that just has contact info on it.

But without installing some kind of desktop client, it would be very hard to get accurate measurements.

share|improve this answer

There is a JavaScript event called onunload, which is called when the page is closed or the back button is clicked. Using that combined with an event listener for keyboard or mouse inputs should give a fairly accurate time-on-page analysis for users with JavaScript enabled.

For users without JavaScript, you're probably left to comparing timestamps and referrers between internal pages.

share|improve this answer
Be aware that, in Mozilla, onunload only fires when a tab is closed or a page is navigated away from. If the user simply closes the browser window, it will not fire. Also most browsers still capture mouse movements over the page while a window is out of focus, so that will also introduce some level of error. But this is still a good way to get a rough estimate. – Lèse majesté Nov 22 '10 at 17:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.