Rule #1: Life is supposed to be fun!

August 23, 2019

How to use Timer in GTM to track real time on page (Google Tag Manager)

GA calculates time spent on a given page by taking the difference between the timestamp of that pageview and the timestamp of the subsequent hit. But if a pageview is the last (or only) hit in the session, GA will assign it a time of zero.

For example: If a person entered the website, then spent around 20 minutes reading your page, and gather all the information he needed, then he exit the page. He  is an potential customer, but in Google Analytics, he is count as a bounce, and session duration is 0.

How to use Google Tag Manager to track user’s time on page

Now, we can use Google Tag manager, timer trigger to fix that problem, by identify the real time-on-page for a particular page.

*** This trick should only be use in some specific pages, such as blog pages, or key pages, since it will send multiple hits to GA, and send multiple event than normal.

See more: Track every user behaviors by sending client ID

1, Send a hit after user spend 30 seconds on page.

Create the Timer trigger as follows:

  1. Add a new trigger. Choose Timer as the event type.
  2. Enter the desired timer interval in milliseconds, e.g. For a 30 seconds timer, enter 30000, and set the timer limit to 1 (only fire once per page)
  3. At the conditions, you enter Page Url -> contains -> URL of the pages you want to track. Leave domain for all pages
  4. This trigger fire on all timers

Now, you create a universal analytics event, with category and label as you wish. This will not affect any reports. The correct set up should look like this


2. Multiple timer on a page

What if you want to record multiple timer events from the same timer? A single 30 second timer is better than nothing, but what if visitors are spending 5, 10, or as much as 20 minutes on a single page before leaving your site? With only a 30-sec timer, your session duration metric could still be hugely misleading.

The set up will be quite the same, as following instructions below:

1, Create a timer trigger. Set up the same as above, but you should leave limit blank. This will allow the timer listener to fire indefinitely until the user leaves the page or closes their browser.


2, Create two new variables to capture the timerEventNumber and timerInterval auto-event variables as follows. At least right now, GTM does not create these macros by default:

Create a new variable named timerEventNumber, set to the value of the gtm.timerEventNumber variable in the data layer. This will return the count of the number of times that the timer listener has fired on the page.



Create a new variable named timerInterval exactly as above, but with gtm.timerInterval as the data layer variable name. This will return the timer interval that you have specified in the listener tag.

3, Configure a variable , custom javascript

Then input the following code into the custom Javascript

function() {
var elapsed = {{gtm.timerEventNumber}} * {{gtm.timerInterval}} / 1000;
var min = elapsed/60;
return min + ‘m ‘;


4, Configure your Universal Analytics event tag as follows.


Finally, in Google Analytics, it will look something like this


Posted in Google Analytics, Tag Manager
  • John

    It would be nicer to have time converted to seconds in steps of ten. How long is 0.166666666666666 minutes?

    11:15 am November 5, 2020 Reply
    • Hi John,

      Thank you for your comment. To convert it into minutes and seconds, you could change the timerEventNumber as follow:

      function() {
      var elapsed = {{gtm.timerEventNumber}} * {{gtm.timerInterval}} / 1000;
      var min = Math.floor(elapsed/60);
      var second = elapsed % 60
      return min + ‘m ‘ + second + ‘s’;

      11:31 am November 5, 2020 Reply
    • It will look something like this

      11:33 am November 5, 2020 Reply
  • Jayden Greenwood

    Can I set it up without Google Tag Manager?

    9:11 am November 15, 2020 Reply
Write a comment