How to Measure True Time with Google Analytics

If you are familiar with how web analytics tools measure time spent on page or site, you know that time spent on the last page is (usually) counted as 0 seconds. With other words, time on last page is not measured.

The reason this isn't measured is simply that the web analytics tool need to have a start point and a end point. On the last page of the visitors visit, there isn't a end point normally to calculate time against.

To be able to get time spent on last page you have to be able measure 2 things:

  1. Clicks on Back Button
  2. Visitors leaving by Closing their Browser or Browser Tab

In this article I show you how you can measure "True" Time spent on your website with Google Analytics by measuring Back Button and Visitors who leave by Closing their Browser.


The time difference between Standard Time Measurment and True Time Measurement can be huge.

How to measure "True" Time by Tracking Back Button and users who leave by Closing their Browser

There are 3 steps you have to do to be able to do this tracking.

Step 1.
The first thing you should do is to create a new Google Analytics profile with a new profile ID. You shouldn't implement this measurement in your regular Google Analytics profile. This method will "kill" your Bounce Rate in addition to that your time spent reports of course will be inflated. With other words, we are going to track data to 2 different profiles in Google Analytics.

The principle for tracking to 2 different profiles is shown below using Google Analytics Asynchronous code.

Remove formatting from Code

  1. <!-- Google Analytics code for Tracking to 2 profiles -->
  2. <script type="text/javascript">
  3. var _gaq = _gaq || [];
  4. _gaq.push(
  5. ['_setAccount', 'UA-XXXXX-1'], //Main Google Analytics profile
  6. ['_trackPageview'],
  7. ['pageTrackerTime._setAccount', 'UA-XXXXX-2'], //Profile for True Time Tracking
  8. ['pageTrackerTime._trackPageview']
  9. );
  10. </script>
  11. <script type="text/javascript">
  12. (function() {
  13. var ga = document.createElement('script');
  14. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  15. ga.setAttribute('async', 'true');
  16. document.documentElement.firstChild.appendChild(ga);
  17. })();
  18. </script>

Step 2.
The next thing you have to do is to download this ZIP-file. The ZIP-file contains 2 files and is necessary in the measurement of the Back Button.

  1. Blank.html - This is an empty HTML-file that you must upload to the root of your domain (yourdomain.com/blank.html).
  2. Backfix.js - This is the javascript that does all the magic that is necessary to be able to track the Back Button

The solution I'm using to track the Back Button is a slightly modified solution borrowed from the Browser Back Button Detection article by Brook Bryan. The original solution was creating 404-errors that Google Analytics counted, so the only thing I have done is to fix that.

Upload backfix.js to for example a folder called script.

Step 3.
This is the last step. Copy and paste the code below between <head> and </head> on your website.

Remove formatting from Code

  1. <!-- Google Analytics script - Track Closing Browser -->
  2. <script type="text/javascript">
  3. leaveSiteStart = new Date;
  4. function leftSite() {
  5. var leaveSiteEnd = (new Date - leaveSiteStart )/1000;
  6. var roundleaveSiteEnd = Math.round(leaveSiteEnd,1);
  7. _gaq.push(['pageTrackerTime._trackEvent','Track Time','Closed Browser', document.location.href, roundleaveSiteEnd]);
  8. }
  9. window.onbeforeunload=leftSite;
  10. </script>
  11.  
  12. <!-- Google Analytics script - Track Back Button -->
  13. <script type="text/javascript" src="/script/backfix.js"></script>
  14. <script script type="text/javascript">
  15. bajb_backdetect.OnBack = function() {
  16. var leaveSiteEnd2 = (new Date - leaveSiteStart )/1000;
  17. var roundleaveSiteEnd2 = Math.round(leaveSiteEnd2,1);
  18. _gaq.push(['pageTrackerTime._trackEvent','Track Time','Back Button', document.location.href, roundleaveSiteEnd2]);
  19. }
  20. </script>

If you have done everything correctly, you should if you drill down to you Event Tracking Report find a report called Track Time. There you will find a report similar to the screenshot below.

Event Labels in that report will be the URL the visitor was on before he either clicked the back button or closed the browser. Event Value reported is the number of seconds from the visitor arrived to the page and until the browser was closed or the back button was clicked.

If you drill down even more in your numbers you will perhaps get the same feeling as me:

Time spent on page or site isn't the same as time spent interaction with your content.

To be honest, I think the image below sums up the behavior to many of my visitors. They do hopefully not fell asleep, but they leave the page open and do some other things before they close the page.

Cat sleeping on computer
Some readers may spend long time on your website due to other reasons than reading. Image by notemily.

Things to be aware of - and Why did I do this?

First, I'm not a programmer so if you find any errors or don't like mye code, please tell it nicely.

This measurement method also shows why this method isn't a standard method in web analytics tools - this method isn't accurate. Only around 80 % of my visitors are measured using this method, which is why I have written "True" Time and not True Time in this blog post.

Since I'm normally a person that will speak out for actionable analytics, which this isn't, so why did I do this?

An important part of web analytics is to be curious. If you aren't curious you will find it more difficult to be friend with your data. With other word, the reason for me to do this was simply because I was curious and had some geek time to use.

Some final words

If you look around on my site you have probably noticed that everything else is written in Norwegian. Since this blog normally is in Norwegian, and I haven't had time to implement a multilingual blog system, you find some explanations of how to comment below:

Click "Legg til kommentar" below. Than fill out your name (Navn) (Mandatory), e-mail (Epost) (Mandatory) and your website (Ditt nettsted) if you have a website. HTML formatting doesn't work in my comment field, use BBCode formatting instead. You can drag the comment field around if you want to. If you want to preview what you have written, click on "Forhåndsvis". When you are done and want to save your comment, click on "Lagre". If you haven't had any comments approved on this blog before, I will have to approve your comment manually.

Related articles

Du kan følge kommentarer til denne posten med RSS. Du må ha javascript aktivert for å kunne kommentere. Tilbaketråkk er deaktivert.

Tags : , ,

  • Comments are closed

XClick to move the comment field