I need to get an idea of the average "time on page" or "page view duration" for each page on my websites without client-side scripting (such as using onunload event handler).

Is any of the free log analyzers capable of doing this? I looked at Webalizer, AWStats and Analog, but they don't seem to have such a function. The closest thing is "visits duration" in AWStats, but I'd like to see "page view duration" instead.

I know that visitor tracking is inaccurate without client-side scripting, but I can bear with it. Google Analytics seems to provide a "time on page" metric without hooking the onunload event (but correct me if I'm wrong), so I believe this is possible.

5 Answers 5


I do commend to you the analog documentation on what is and is not knowable from your web logs, especially the part where the author writes:

You can't tell how long people spent reading each page. Once again, you can't tell which pages they are reading between successive requests for pages. They might be reading some pages they [cached] earlier. They might have followed a link out of your site, and then come back later. They might have interrupted their reading for a quick game of Minesweeper. You just don't know.

You can't tell how long people spent on your site. Apart from the problems in the previous point, there is one other complete show-stopper. Programs which report the time on the site count the time between the first and the last request. But they don't count the time spent on the final page, and this is often the majority of the whole visit.

Stephen Turner, the author of analog, is a bright guy - ex-Cambridge statistician - and I'm inclined to agree with him on this. He justifies his arguments in the link I sent above.

Analog will tell you what is definitely knowable from your web stats, and it will tell you very quickly. Trying to get more is guesswork, and if you want a guess, why pay someone else to make it? Random number generators are five a penny, so use one of them instead.

  • It's a useless statistic anyway. If I go to some commercial website, spend ages trying to find/buy something and then go to amazon, find it quickly and buy it using single click then page viewing statistics will probably show I spent much more time on the "other" site. Yet Amazon got my money - the "statistic" that actually mattered.
    – Rob Moir
    Dec 29, 2010 at 12:33
  • @Robert Moir What if you're trying to identify the portions of your site that your users have the most trouble navigating? i.e. yes, they're abandoning their carts to shop at Amazon, but is it because they can't find the "add to cart" button on the product page or because the product images aren't appealing or the price is too high or ..? Time on page helps identify your users' habits and define their experience - not necessary but not entirely useless, either.
    – danlefree
    Dec 29, 2010 at 16:42
  • Time on page would help you if you could know it, but you can't from your logs. If you want to take a bunch of test users and film them navigating your site, then you can know it.
    – MadHatter
    Dec 29, 2010 at 17:12
  • 1
    It's been 12 years, but this question is still valid and this answer is still useful! Just one update - the analog doc link is dead. Here's a link to the latest available version via the Wayback Machine: web.archive.org/web/20140701141905/http://analog.cx/docs/… Feb 17, 2023 at 18:33
  • @NathanBedford many thanks! And also for the updated link, which please feel free to edit into the answer.
    – MadHatter
    Feb 18, 2023 at 9:01

As Madhatter has written, relying on the logs for this information will not give an accurate picture. Also, as with most statistics, you have to spend a lot of time thinking about what you are actually measuring - are people spending time on the page because its interesting or because its hard to understand? Capturing the data in javascript will give quite different behaviour from looking at the logs (consider what happens when the user has multiple windows open).

AFAIK, there are no tools available, commercial or free which do this kind of analysis - including Google Analytics (malfy: can you provide a reference?). However writing your own is not overly taxing - but you'll certainly need to use mod_usertrack or require sessions throughout to differentiate between users - and log the relevant cookie along with the mimetype for a request - which means you're no longer using the standard log formats.

On the upside, the same machinery also allows you to start looking at caching effectiveness and clickstream analysis (also areas that most of the current generation of analysers are poor at).

  • In Google Analytics, if you go to "Content > Top Content", you can see the "time on page" column.
    – netvope
    Dec 29, 2010 at 18:53

Warning: This method may or may not summon unspeakable horrors to your webserver's performance.

If you're running PHP or a similar scripting language, you could do something really, really ugly - like this:

In the footer of pages you want to track:

<iframe src="/path/to/script.php?src=<?php echo htmlentities($_SERVER['REQUEST_URI']); ?>&user_ip=<?php echo $_SERVER['REMOTE_ADDR']; ?>" width="1" height="1" style="visibility:hidden;"></iframe>

In "script.php" or whatever you choose to name your timer script:

       if ( @isset( $_GET['src'] )
           $source = filter_var( $_GET['src'], FILTER_SANITIZE_STRING );
       } else {
           /* no source page to track */
       if ( @isset( $_GET['minute'] ) )
           $minute = (int) $_GET['minute'] + 1;
       } else {
           $minute = 0;
       $uri_refresh = ($_SERVER['HTTPS'] != 'on') ? 'http://' : 'https://';
       $uri_refresh .= $_SERVER['HTTP_HOST'];
       $uri_refresh .= '/path/to/script.php';
       $uri_refresh .= '?src=' . $source;
       $uri_refresh .= '&user_ip=' . $_SERVER['REMOTE_ADDR'];
       $uri_refresh .= '&minute=' . $minute;
     <meta http-equiv="refresh" content="60;url=<?php echo $uri_refresh; ?>">
     <title>Timed Logger</title>
   <body style="color:#FFFFFF;">
     <p>You have been viewing this page for <?php echo $minute; ?> minutes.</p>

... and then you can get a rough idea of how long people are viewing things by looking at the relative popularity of different minute values in your server logs.

  • Clever using an iframe to send the data, avoiding javascript. You needn't do all the calculation for each request; just accumulate the data and do all the heavy lifting when analyzing.
    – KevinHJ
    Oct 2, 2023 at 10:39

So use Google Analytics then? I've used it - works great.


Nihuo Web Log Analyzer support this function. It's not free, but there is 30 days free evaluation version with full function in their website.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .