Our script for accurate tracking of time on page beats Google’s default measurement to give you an accurate picture of how long users are spending on your page open and in focus.

This post translates the approach into Google Tag Manager. The setup consists of two tags (one custom), one firing rule and two variables.

Step by step:

1. Add the timer script as a custom HTML tag

2. Add two variables to access the data layer variables

One for the formatted time, which will feed through the event label

timeinfocus

And one for the number of seconds in focus since the last event, which will feed through the event value

intervalseconds

3. Add the firing rule for the event

littledata-timer

4. Add the tag that reports the timer event to Google Analytics

time-tag

Options and further information

You can change the timer interval in the custom HTML tag – the reporting will adjust accordingly. Choosing the interval is a trade-off between the resolution of the reporting and the load on the client in sending events, as well as Google’s 500 hit per session quota.

We’ve chosen ten seconds because we think the users who are in ‘wrong place’ and don’t engage at all will leave in under ten seconds, anything more is some measure of success.

If you’d like assistance implementing this or something else to get an accurate picture of how users interact with your site, get in touch!

 

Get Social! Follow us on LinkedIn, Twitter, and Facebook and keep up-to-date with our Google Analytics insights.
Edward

Founder of Littledata, Technical Lead and Product Consultant. He has broad experience helping companies with business strategy, product development and technology management.

View all posts

4 Responses

  • Chris 4 years ago

    Curious, the HTML script when do you fire that code? Should that not be fired on each page?

    • Edward Upton 4 years ago

      GTM injects the HTML onto the page according to the firing rules. Yes, i’d run it on every page – but you could set to only run for landing pages.

  • Chris 4 years ago

    Curious, the HTML script when do you fire that code? Should that not be fired on each page?

    • Edward Upton 4 years ago

      GTM injects the HTML onto the page according to the firing rules. Yes, i’d run it on every page – but you could set to only run for landing pages.