Timer Triggers in Google Tag Manager

timer-triggers-in-google-tag-manager-1Although Google Analytics does calculate time on page, it only looks at the difference between the timestamp of a page view and the timestamp of a subsequent hit. This means if the page is the last or only hit in a session, it receives zero seconds. Timer triggers are necessary to receive data about time on page, session durations, and bounce rates.

How to Create Timer Triggers

To create a trigger, you will need permission to edit the Google Tag Manager container of the website. In your GTM account, add a new trigger, choosing “timer” as the trigger type. Set the event name, the limit (how many times you want the trigger to fire), and the interval. Note that the interval is how much time you want to pass between the activation of the trigger in milliseconds. For instance, 10 seconds would be 10,000 milliseconds.

When setting up a trigger, you also have the option to set the timer just on certain pages — you’ll find this under “Enable When.” Plus, you can fire a trigger on all timers or just some.

Once you have set the criteria, click “Save.” You’ll need to create a new Universal Analytics event tag, entering values for at least “Event Category” and “Event Action,” setting the tag to fire on the timer trigger you created.

Data Layer Variables

To take timer triggers a step further, you can create a new Data Layer Variable for any parameter in the data layer. Options include StartTime, ElapsedTime (in milliseconds), CurrentTime (for the most recent timer activation), Interval, EventNumber, and ID.

This last is probably the most useful. A unique identifier number for the timer (each timer on a page has a different ID), it allows you to stop the timer before the limit is reached. To do so, you’ll need to run the JavaScript command:

var timerId = {{DLV - gtm.timerId}};
window.clearInterval(timerId);

Bear in mind, it is impossible to restart the timer once it has stopped without a page refresh. This means it is best for single-page apps where you want to stop the timer when a new page loads.

The variable gtm.timerEventNumber is also very useful, as it allows you to see which iteration of the timer trigger has completed. Create the variable, refresh P&D Mode and the website, and wait for the trigger to fire. Then, go to “Preview and Debug” and find the “Variables” tab. You can create a trigger that activates after the second timer.timer-triggers-in-google-tag-manager-2

Beyond the Basics: Ideas for Using Timer Triggers

Delaying Popups

Most users rely on timer triggers to send an event to GA after a visitor has spent a certain amount of time on the page. However, you can also stop a tag from firing until an asynchronous request is complete. For instance, you can use timer triggers to delay the appearance of popups and widgets asking visitors to subscribe to an email newsletter or to download premium content.

Timer Limits

When creating a trigger, you can set a number in the timer limit field or leave it blank. If you leave it blank, you will be able to record multiple timer events with the same timer. You will likely only want to do this to pages with high exit rates to limit the events you generate.

You will need the auto-event variables timerEventNumber and timerInterval. You will also need to configure your Universal Analytics event tag to {{timerEventLabel}} as the custom JavaScript variable. This will be defined as a variation of:

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

Changing Bounce Rate

Another useful way to gain extra benefits from timer triggers is to make your bounce rate more meaningful. Normally, visitors who only access one page of your website contribute to the bounce rate. However, if many of these users are spending a long time on a single page, it could be more meaningful to count a bounced visit as a short time spent on your website.

You can set a timer trigger to activate and fire an event called “Visitor stayed for X seconds.” You will need to use the “non-interaction:false” setting, a default in GTM.

Before you decide to use a timer trigger in this way, you should consider that it will count all long visits from users. This includes visits when users may have left open a page from your website while they interact with another site.

Beyond being essential for giving you a better picture of how long users are staying on your webpages, timer triggers have additional capabilities. These can enhance website functionality and metrics.

If you like my articles,