Accurate tracking of time on site

Ecommerce benchmarks for Shopify stores

There’s a flaw in the way Google Analytics measures ‘time on site’: the counter only starts from the second page visited, so all one-page visits are counted as zero time on site.

If a visitor comes to your page, stays for 10 minutes reading – and then closes the window… that’s counted as ZERO time.

With landing pages that have lots of interaction, or the call to action is a phone call rather than a click, this can be a real problem.

Pasting the Javascript below onto all the pages of your site will fix the problem.

The script logs an event to Google Analytics for every 10 seconds the visitor stays on the page, regardless of whether they bounced or not. But it won’t affect your bounce rate or time on site for historical comparison *.

We suggest you look closely at how visitors drop off after 10, 20 and 30 seconds to see which of your web content could be improved.

Paste this into the source of your all your pages, after the Google Analytics script

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” bg-color=”#abb8c3″ theme=”dark” language=”javascript” wrapped=”yes” copy-text=”Copy Code” copy-confirmed=”Copied”]

<!-- Time on Site tracking -->
(function(e){var t=true;var n=0;var r=true;var i=function(){t=false};var s=function(){t=true};if(window.addEventListener){window.addEventListener("blur",i,true);window.addEventListener("focus",s,true)}else if(window.attachEvent){window.attachEvent("onblur",i);window.attachEvent("onfocus",s)}var o=function(e){return Math.floor(e/60)+":"+(e%60==0?"00":e%60)};var u=window.setInterval(function(){e=e+10;if(t){n=n+10;if(typeof _gaq==="object"){_gaq.push(["_trackEvent","Time","Log",o(n),n,r])}else if(typeof ga==="function"){ga("send",{hitType:"event",eventCategory:"Time",eventAction:"Log",eventLabel:o(n),eventValue:10,nonInteraction:"true"})}}},1e4);window.setTimeout(function(){clearInterval(u)},601e3)})(0)


What you’ll see

In Google Analytics go to Behaviour .. Events .. Top Events and click on the event category ‘Time’.

Time Logging

Searching for a particular time will find all the people who have stayed at least that length of time. e.g. 0:30 finds people who have stayed more than 30 seconds.

Search for time logging


Does this affect the way I compare bounce rate or time-on-site historically?
No. The script sends the timer events as ‘non-interactive’ meaning they won’t be counted in your other metrics. Without this, you would see a sharp drop in bounce rate and an increase in time on site, as every visitor was counted as ‘non-bounce’ after 10 seconds. If you prefer this, see below about adapting the script.

Will this work for all browsers?
Yes, the functions have been tested on all major, modern browser: IE 9+, Chrome, Safari and Firefox.

What if I upgrade to Universal Analytics?
Don’t worry – our script already checks which of the two tracking scripts you have (ga.js or analytics.js) and sends the appropriate log.

Will this max out my Google Analytics limits?
The script cuts off reporting after 5 minutes, so not to violate Google’s quota of 200 – 500 events that can be sent in one session

Can I adapt this myself?
Sure. The full source file is here.

Comments 5
  1. Will this affect the count of ‘active users on site’ in the real time dashboard?
    We are seeing a crazy amount of unattributed traffic (WAY higher than normal) ever since we implemented the code. Any insights here?

    1. Hi Sarah. Can you explain what you mean by unattributed traffic? The timing events should fire after the pageview, but if your tracking code was not on every page to start with you may see a lot of (not set) in the top landing pages.

Comments are closed.

How to read the frequency report in Google Analytics
Frequency report in Google Analytics

How to read the frequency report in Google Analytics

Google Analytics engagement reports can provide great insight into user

How to track time on page with Google Tag Manager
google tag manager

How to track time on page with Google Tag Manager

Our script for accurate tracking of time on page beats Google’s default

You May Also Like