21 Apr 2016
Bart with a slingshot: sometimes it is so difficult to score with a slingshot as wiht a tag manager event trigger
Reading time: 17 mins.
|
Difficulty:

GUIDE: Google Tag Manager Triggers

Contents: everything you need to know about triggers in GTM

What is a Google Tag Manager trigger and what is it for?

Google Tag Manager triggers are the conditions that cause tags to fire in different parts of the website or key event, where we say and when we say. Consequently, the tags are fired (or not) when the conditions that trigger them are met. Each tag must have a minimum of one trigger in order to be fired.

In some cases, triggers can also be “exceptions” or “blockers”, given that, if the trigger’s conditions are met, the tag is not fired. For example, we could select the All Pages trigger and create exceptions in the form of circumstances under which the tag will not be fired.

Triggers google tag manager: exceptions

*All Pages is the only default trigger in GTM and will fire the tag on all of the pages that incorporate the Tag Manager code snippet (and have published their container). This is the trigger we use for Google Analytics trackers, Hotjar, remarketing pixels, etc.

**In order to be able to create an exception we must have previously selected at least one trigger. Otherwise, creating an exception doesn’t make sense.

Each trigger is comprised of at least one event (which defines when we want to fire the trigger) and, optionally, one or more conditions (which limit the event to the specific circumstances under which we want the tag to fire).

In turn, these conditions are each comprised of a GTM variable that we compare to a particular value.

Tag Manager triggers: events and conditions
*We’ll also see that some triggers have additional settings, but let’s not get in over our heads just yet…

⇑ Article content (Back to top) ⇑

How to create a trigger in Google Tag Manager

We can create triggers quickly, albeit with certain simplifications, via the tag creation interface itself. However, there’s also a dedicated Triggers menu, which offers a more complete range of settings.

In the tag creation interface we can also click on More/New to access the same options:

Triggers google tag manager (inside tag)

If we move onto the more complete menu, the first thing to do when creating the trigger is to select the event type. Different types can have different settings:
Eventos de Google Tag Manager

The settings for each type of trigger will be different, based on the event selected. Let’s look at each of them in turn.

⇑ Article content (Back to top) ⇑

Automatic event triggers

This is the most commonly used trigger type and is based on automated GTM events. These events have now been “standardized” and are available to everyone; they form part of the programming of GTM itself and can therefore be used even by those without a great deal of web development knowledge. One of the great advantages of using GTM is that we are able to measure and fire tags and codes for events of the following types:

        • page view (fired using good old fashioned page rules)
        • link clicks (e.g. PDF downloads, external links, one-off key links, etc.)
        • element clicks (e.g. buttons)
        • forms (only some kinds)
        • timers (i.e. fire a tag after X seconds have passed)
        • JS errors (send JavaScript errors to Google Analytics)
        • history listener (to detect the user’s browsing without URL changes)

Normally we can do this without adding any additional code to the page (except for maybe an ID or Class identifier), using just the existing firing structures and variables that can be created in GTM.

⇑ Article content (Back to top) ⇑

Page View event trigger

This trigger is centered on the loading of one or more specific URLs. The most common way to load simple conversion tags is to use the Page View event.

If we configure the trigger via the Triggers menu or the More/New option, we’ll see that we have three different trigger events for page loading: gtm.js (when loading begins – Page View), gtm.dom (when the HTML has loaded – DOM Ready) and gtm.load (when all external files have also been loaded – Window Loaded). These three events are always sent in the initial GTM load page data layer:

When we use this menu the Page View option will be selected by default:
Events triggers google tag managerTriggers google tag manager: pageview, dom or load

We have to decide if the tag will be fired on all page views or just some of them.

Triggers google tag manager all or some pages

If we select the Some Page Views option, the following filters or conditions appear:

Triggers page condition google tag manager

In order to understand these conditions and exercise the option of specifying on which page(s) we want to fire the tag, we can use the built-in page type variables (we have to activate this option beforehand in the Variables menu). We can also use custom variables created to our own specifications. But let’s start with the easiest option, the built-in page variables:

Page variables for tag manager triggers

      • Page URL: For creating comparisons with the complete page URL.
      • Page Hostname: For comparing with the domain name only.
      • Page Path: For comparing with the path (i.e. the part that comes after the hostname.com in the bar).
      • Referrer: For filtering by the page the user arrived from (e.g. firing a tag only if the traffic comes from AdWords).

TAKE NOTE! If we select Some Page Views via the tag creation interface we’ll be offered simpler settings that only apply to the standard Page View event at the time of loading.

Triggers google tag manager all pages
Triggers google tag manager some pages

⇑ Article content (Back to top) ⇑

Click and Click Link triggers

We can also load custom HTML or tracker tags when elements or links are clicked. If we choose this option, we first have to decide between clicks on Just Links (<a href>) or All Elements (any <html> tag).

 

All Elements VS Just Links triggers tag manager

We then need to decide whether to fire on all clicks or just certain ones (the latter is the more common option).

All VS some click triggers google tag manager

Selecting Some Clicks will cause the filters or conditions to appear. TAKE NOTE! To create click filters, first we must go to Variables and activate the predefined click variables (Click ID, Classes, Element, and Text). We can also create custom ones.

Click variables for google tag manager triggersVariables for click triggers google tag manager

If we choose Segmentation: Click Links there’s an extra step (prior to the conditions stage) we need to take in order to configure the trigger, called Enable When:

Triggers linkclick tag manager

*In general, we leave it to measure link clicks on All Pages (regular expression .*).

This field is ONLY for page filters.

⇑ Article content (Back to top) ⇑

Send Form event trigger

In theory, this trigger should be used to fire a tag when a form is sent correctly. The settings are similar to those for Click triggers, and first of all we need to decide whether we want to measure all forms or just some of them.

Additional settings:

      1. Check Validation: If there’s a preexisting JavaScript operation (validation operation) connected to the form, it will be executed first, and if an error is returned the trigger won’t fire. However, in many cases this function doesn’t work; for example, with forms that use AJAX or for server-side validation. In short, this GTM event trigger is pretty limited.
      2. Wait for Tags: This option allows us to wait until the rest of the tags are loaded (or up to a limit of two seconds) before executing the sending of the form.

Form variables for google tag manager triggers  Form triggers google tag manager

In the real world, in the majority of cases, we’ll use custom events to track the correct sending of forms. We can perform a test with the forms on our page (to check that the automatic event trigger works correctly). Otherwise, we can send the data layer, as described in this article on Google Tag Manager and WordPress. If you use Contact Form 7, you’re in luck! We’ve given you a solution 😉

⇑ Article content (Back to top) ⇑

Timer event trigger

Here, we can measure, count and send events. This option is fine for customizing bounce rate and launching calls to action, forms, surveys, etc. It’s very easy to configure: all we need to specify are an event name, the number of milliseconds and the amount of times we want to execute the timer. For example, to create a timer trigger that fires 30 seconds after the page has loaded, we do the following:

Timer trigger google tag manager

We specify 30,000 milliseconds and set the limit at 1 to make sure the count is only made once, not repeated periodically.

⇑ Article content (Back to top) ⇑

 

JavaScript Error event trigger

Javascript error google analytics tag managerQuite simply, this trigger detects errors in JS code. If we want an example, we can try triggering the example code and tag in the following article: simoahava.com/analytics/fun-with-google-tag-manager-part-1. See how easy it is? 🙂

Basically, it involves configuring a Google Analytics event tag which we can use to compile these errors. Following Simo’s example again, and defining the event fields to our own liking, we could do the following:

   – In the Category field we can select the generic Errors category.

   – In Action we can specify the type of error, which in this case is a JS Error.

   – In Label we have a breakdown of the error info: {{Error URL}} – {{Error Message}} – {{Error Line}}.

   – If we want, we can put something in Value, but as we can’t use negative integers, there’s not much point.

   – It’s essential that we select Non-Interaction Hit – True in order to avoid generating hits with errors that could distort the bounce rate.

   https://support.google.com/analytics/answer/1033068#Anatomy

Error variables for google tag manager triggersJavascript error trigger google tag manager Javascript error trigger tag manager

⇑ Article content (Back to top) ⇑

History Listener event trigger

In order to track AJAX and HTML5 browsing on a page without URL changes we need to fire the variables and tags specified in this post: simoahava.com/analytics/google-tag-manager-history-listener.

There’s also an updated post pending on this particular subject…

⇑ Article content (Back to top) ⇑

Custom event triggers in Google Tag Manager

This option lets us create a new, bespoke trigger for when automatic events aren’t working. We use them to send actions manually with the data layer, e.g. for AJAX forms, interaction with forms, tracking errors in purchasing/sign-up/login processes, etc.

If we want, we can send associated values such as event parameters or custom parameters, thereby taking advantage of the same data layer. Or, to put it another way, whenever we want to send custom values in a data layer it is advisable to also send a custom event. That way, we’ll have a specific point from which we can use these values and fire tags in the future.

Custom event trigger google tag manager

Below is an example of a data layer code and how to create a trigger based on a custom event that we’re sending via the data layer:

<script type="text/javascript">
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'event': 'myCustomEvent',
'eventAction': 'eventData',
'productID': 'A345789',
'language': 'es'
 });
</script>

⇑ Article content (Back to top) ⇑

Important: About triggers and how they interrelate

1. Firing vs. Exception/Blocking: How to create an exception in a tag

Triggers can not only activate, but also block (exceptions).

To create an exception or block trigger, first we need to select a trigger for the tag:

Exception triggers google tag manager

The process is the same as for any other trigger.

If a tag has triggers for activation and for blocking, their conditions are combined. In other words, the conditions for inclusion and blocking must be met at the same time in order for the tag to be fired.

For example: include “/thanks/” in the URI (inclusion), except if the hostname is “aaa.com” (blocking).

Outcome:

– At bbb.com/thanks/ the tag will be fired.

– But at aaa.com/thanks/ the tag will not be fired.

Blocking will take priority over activation, in the event of a conflict between triggers of different types. For example: include “/contact/thanks/” in the URI (inclusion), except if the URI contains “/thanks/” (blocking). In this case, the blocking trigger “wins” and the tag is blocked.

⇑ Article content (Back to top) ⇑

2. Several triggers and several conditions: Trigger vs. condition

We can define various triggers for the same tag.

If we have more than one firing/blocking trigger for the same tag, their relationship to each other is optional/alternative. In other words, if either of them is activated, the tag is fired/blocked as a consequence.

Here’s an example of two conflicting triggers, and an interesting point about how to prevent 0% bounce in Google Analytics::

All pages dom triggers analytcs 0% bounce rateIn this instance, we’ve defined two separate triggers: one Page View type (All Pages: the only trigger created by default in GTM, although if we had to define it ourselves we’d do it as shown in the left-hand screenshot below) and another DOM type. Consequently, 0% bounce is generated in Google Analytics, because the tag code is loaded twice and in two different events** (two page views in each URL = 0% bounce), like when the same UA- is repeated twice in a website.

 

All pages trigger google tag manager DOM ready trigger google tag manager

To reiterate: with two separate triggers, we’re saying that the tag will be fired WHEN a page is viewed in its entirety (gtm.dom event) OR WHEN the page begins to load (gtm.js event). It can only be one OR the other. And as we stated earlier, the gtm.js -> gtm.dom -> gtm.load events occur in sequence upon every page load, one after the other. Therefore, the tag in question is fired twice, i.e. gtm.js (first time) -> gtm.dom (second time) -> gtm.load

Important conclusion: we must make sure not to confuse the All Pages trigger (all pages in the Page View event or gtm.js) with the All Pages condition (e.g. {{Page URL}} regEx .*) that we apply to many tags. They’re totally separate things. The first is a trigger that fires upon completion of a Page View, and the other is a condition that can be added to any trigger and can be linked to any other event.

**IMPORTANT: Different events** >> is just a nuance, or an “extra turn of the screw”: if we use two alternative triggers simultaneously that refer to the same event (e.g. one trigger with the {{Click Classes}} condition and another with the {{Click ID}} condition for the same Click (gtm.click) event), this will not make the tag fire twice. It’s the only exception and something of an advanced case.

⇑ Article content (Back to top) ⇑

3. Several conditions within a trigger (examples)

However, if we have several conditions within the same trigger, they must all be met simultaneously in order for the trigger to fire. As described in point 1 above, we “combine” their activation and blocking conditions.

Triggers google tag manager multiple conditions

Fire this trigger when all of these conditions are true

As we can see above, different conditions can exist within the same trigger. These conditions all need to be met at the same time in order for the trigger to fire or block the tag.

Example 1:

Triggers google tag manager click conditions

Event: Click (gtm.click) / Segmentation: All Elements. This is fired when any HTML element on the page (regardless of whether or not it is a link; e.g. the <button> or <input> tag) is clicked.

Condition 1 – Activate: {{Click Text}} contains Buy now!. This will fire the tag if the element that is clicked on contains the specified text.

Condition 2 – Activate: {{Click Path}} contains /buy-. This will only fire the tag if the path also contains /buy-.

Outcome:
– Clicking on <button action=”/buy-product-872.php”>Buy now!</button> will fire the tag.
– Clicking on <button action=”/buy-next-week.php”>Buy next week</button> will NOT fire the tag.

 

Example 2:

Triggers google tag manager page conditions

Type: DOM Ready (gtm.dom): event fired when the page has fully loaded. This is useful for when we want to force a tag to fire after the rest of the code on the page; think of it as the equivalent of inserting a code at the end of </body>.

Condition 1 – Activate: {{Page Path}} coincides with RegEx (.*) encompasses all possible paths or URIs (the part that goes after the domain name: e.g. mydomainname.com/URI, including the forward slash).

Condition 2 – Activate: {{Page Hostname}} contains mydomainname.com. This ensures that the tag is only fired in our domain name.

Outcome:
– At mydomainname.com/uiopjasfjaf the tag is fired.
– At anotherdomainname.com the tag is NOT fired.

⇑ Article content (Back to top) ⇑

Advanced firing settings within GTM tags

Certain factors within the advanced settings for all GTM tags affect the firing of the tags independently of the triggers that are associated with them:

Advanced Settings

Google tag manager: tag advanced settings

All tags, regardless of their type, include common fields for advanced settings. In all cases, the use of these advanced settings is optional and on the majority of occasions we won’t need them. The settings in question are as follows:

      1. TAG FIRING SCHEDULE

This option allows us to define a certain date and time period within which the tag will be available. Outside of this period it will not fire. This may be useful if we wish to create and publish a tag in advance and don’t want it to become active until a specific date and time.

      1. ONLY FIRE IN PUBLISHED CONTAINERS

This option means the tag will not be fired if we are in test/debug mode. It will only fire when the container that includes it has been published. This may be useful for tags that could incur a financial cost or generate incorrect statistics if fired during testing.

      1. TAG FIRING PRIORITY

The Priority field for tag firing allows us to enter a numeric value that controls the relative firing priority for the tags in question. Tags with a greater value will fire first. In order for this feature to work, the prioritized tags must be fired at the same time or in relation to the same event. Documentation >

However, this option only offers partial control over the firing order, as it defines the order in which the firing begins but not in which it ends, and does not specify whether or not a tag must finish firing before another can begin.

It’s important to remember that all GTM tags are executed asynchronously.

      1. TAG SEQUENCING

This option lets us define a setup tag (activated directly before another) and a cleanup tag (activated directly after another). Once again, there is an extremely detailed explanation in this post by Simo Ahava on Tag Sequencing in Google Tag Manager.

After tag sequencing we should then look at the firing options, as the two are closely related. An example of tag sequencing can be found in this post.

      1. TAG FIRING OPTIONS

The various tag firing options are as follows:

      • The default option is “Once per event”, shared by all tags. Here, for each firing event generated in GTM – whether page-related, click-based, etc. – the tag will only fire once, even if there are various triggers whose conditions are met at the same time for the event in question. In general, a tag will never be fired twice for the same event, with the only exception being the tag sequences mentioned above.
      • Once per page”: Even if the firing event occurs more than once for the same URL, the tag will only be fired once (once for each page load).
      • Unlimited”: This option, which nullifies the above restrictions, is only intended and valid (almost exclusively) for sequences of tags, when it’s possible for a tag to be fired several times in the same event or page load. This will only happen if, in addition to meeting its trigger conditions, the correct sequence (i.e. the previous tag) is met for it to be fired. By default, the tag will only be fired once per event, although selecting the Unlimited option will cause it to fire twice.

Official Google documentation >

⇑ Article content (Back to top) ⇑

¡