How to Improve Time On Site Metric in Google Analytics 2

In past articles we already covered What is Bounce Rate and why users abandon our site, and How to Fix a High Bounce Rate Metric in websites with just one page.

Through this article we’ll explain how the average time on site it’s calculated, in which we’ll see that the last page is never counted within the time on the visit, and we’ll detail what you need to implement in order to improve the accuracy of this metric by including time spent in the last page.


Google Analytics receives data about the navigation of the users principally as follows:

  • Tracking Code: piece of code included in every single page, that sends information about the viewed page to Google Analytics. This is done automatically by the code and requires no additional implementation.
  • Custom Code: Other features, such as event tracking, social tracking or eCommerce information,  will require including some custom code.

Google Analytics will classify every single request of information as a hit, regardless the method we are utilising.

How the Time On Site metric is calculated in Google Analytics

All the requests received in Google Analytics will be recorded with an amended timestamp, which will determine the exact time of the hit.

Utilising those timestamps recorded as reference, Google Analytics will calculate the time on site for a specific visit as per the following formula:

Av. Time On Site = Time of First Hit – Time of Last Hit

Time On Last Page

In the majority of implementations of Google Analytics, this installation is done by introducing the tracking code on every page of the site. This will allow the site sending information of every page, and measure the natural journey of the users. This is pretty easy for everyone, right? You just need to include the code and forget… Almost true!

Using this installation, Google Analytics is recording the timestamp of every page and at the end of the visit will execute the formula to calculate the time on site (Last hit on the last page – First hit on the first page).

Where’s the problem?

The issue of this method is that the time which the user spends in the last page is never counted! If we think about the normal behaviour of a user in a website, the last page is in most scenarios the most interesting one. This is normally the page in which they find what they are looking for: information about a product, the list of restaurants of the city or that article the user wants to read.

How to increase accuracy on Time On Site

Let’s say we are already using Event Tracking to measure specific actions on the site, such as clicks on link. Those events will contribute to the calculation of the time on site, as new timestamps are recorded, but those actions won’t be useful if the user is just reading content or watching a video for a while.

The previous paragraph is almost revealing you what is the solution to improve the accuracy of this metric. If we determine a way to use event tracking every once in a while, we’ll be recording different timestamps while the user is reading the page or watching the video. Spot on!

  1. Define your timeout interval: define every how much time you want to record the user time on the page. This shouldn’t be too small not to overload the site with requests. A good interval could be 20 seconds.
  2. Set up a timeout with milestones every 20 seconds. Use Javascript to create it. You should determine a limit of milestones per page, as for example 50.
  3. Execute a Google Analytics event when the timeout stops to send to Google Analytics information just to control the average time on site.

This is the event tracking that needs to be executed every 20 seconds on every page:

_gaq.push(['_trackEvent', 'Control', 'Time On Site', '']);

Note that we won’t use this event to create any reporting associated. This is just to allow Google Analytics increasing the accuracy when calculating the Time On Site metric.

If you are not comfortable with code

If you are not a developer or you are not comfortable with designing code, don’t worry. Just paste the following code before the </body> tag of your site, or tell your developers to do it.

for (var i=1;i<50;i++){
setTimeout(function(){_gaq.push([‘_trackEvent’, ‘Control’, ‘Bounce Rate’, ”])},Time in miliseconds);}

All you need to do is just replace Time in milliseconds for your desired timeout, for example 20,000 (20 seconds).

If you are using Google Tag Manager…

If you are utilising Google Tag Manager, it’s much easier. Just visit our post about Auto Event Tracking with Google Analytics – Timer Listener (coming soon).

2 thoughts on “How to Improve Time On Site Metric in Google Analytics

  1. Comentar WhitestFly abr 18, 2015 15:15

    Hi, thant’s exactly the info I was looking for, but I need some more detail, not being skilled with coding at all.
    Where can I past the code you are providing?

    for (var i=1;i<50;i++){
    setTimeout(function(){_gaq.push([‘_trackEvent’, ‘Control’, ‘Bounce Rate’, ”])},Time in miliseconds);}

    Please consider I’m running my blog on WordPress, which file should I edit to include your code?
    Thanks a lot!

    • Comentar Elías Nuevo ago 13, 2015 10:13

      Hi WhitesFly,

      Apologies, I think this comment was missed!

      This code will work or not depending on if you are using Universal Analytics or the previous version. Please check that first.

      With regards of the position, any of the files that can inject JavaScript on each page will work, as this is is a listener. I’m sure there are WordPress plugins to add JavaScript code to each page.


Escribir un comentario