Beginners’ guide to Triggers and Variables in Google Tag Manager

 

This article is related to Google Tag Manager (GTM). If you are brand new to GTM then read the following two articles first:

  1. Beginner’s guide to Google Tag Manager
  2. Google Tag Manager Implementation & deployment Guide

Introduction to Triggers in Google Tag Manager

A trigger is a condition that must evaluate to either true or false at run time. In GTM, triggers are an integral part of a tag creation process. So you can not create a tag without first creating corresponding trigger. There are two methods of creating a trigger in GTM. One is while you are creating a new tag and one is through the triggers menu:

Now watch this short video to improve your understanding of GTM triggers:

.

There are two categories of triggers in GTM:

  1. Firing triggers (commonly known as triggers)
  2. Blocking triggers

Firing triggers

A firing trigger (or firing rule) is a condition which must be met (must evaluate to true) at run time, for a tag to fire/execute. A firing trigger tells GTM when the tag should fire. Following is an example of a firing trigger:

{{url}} matches http://www.abc.com/cart/thankyou.html

This trigger fires the tag, when the URL of the currently loaded page matches http://www.abc.com/cart/thankyou.html

There are two categories of firing triggers:

  1. Built-in firing triggers
  2. User-defined firing triggers (also known as custom triggers)

Built-in and User defined firing Triggers

Built-in triggers are predefined firing triggers. These are ready to use triggers. User defined triggers are the one defined by people like me and you. There are two methods to see the list of built-in and user-defined triggers. One is while you are creating/editing a tag and one is through the triggers menu.

Method-1: While creating/editing a tag

In order to see the list of built-in and user-defined triggers, follow the steps below:

Step-1: Create or edit a new tag.

Step-2: Click on the ‘Choose a trigger to make this tag fire…’ button:

Step-3: Click on the ‘+’ button on the top right hand side:

Step-4: Click on ‘Choose a trigger type to begin setup’:

You will now see the list of available built-in triggers:

For each built-in trigger there is a corresponding user defined trigger available. In other words, GTM let you customise built-in triggers.

For example, in order to customize a built-in trigger say ‘DOM Ready‘ just click on it and then select ‘Some DOM Ready Events‘:

Following is a complete list of built-in triggers along with their corresponding user defined trigger:

Method-2: Using the ‘Triggers’ menu

In order to see the list of built-in and user-defined triggers using the ‘Triggers’ menu, follow the steps below:

Step-1: Click on the ‘Triggers’ menu:

Step-2: Click on the ‘New’ button:

Step-3: Click on ‘Choose a trigger type to begin setup’:

You will now see the list of available built-in triggers:

Blocking triggers

A blocking trigger is a condition which must be met (must evaluate to true) for a tag to not fire/execute. A blocking trigger tells GTM when the tag should not fire. You can create a blocking trigger (or blocking rule) by clicking on the ‘Add Exception‘ link while creating/editing your tag. Follow the steps below:

Step-1: Create/edit a tag

Step-2: Scroll down to the ‘Triggering’ section and hover your mouse over this section. You should now see a ‘Pencil’ button. Click on it:

Step-3: Once you clicked on the ‘Pencil’ button you will see an ‘Ad Exception’ link. Click on it:

The rest of the process of creating a blocking trigger is similar to the process of creating a firing trigger.

Note: Whenever your firing trigger contradicts with your blocking trigger then the blocking trigger takes precedence.

For example, if you set a trigger to fire tag on all pages of your website and then you set a blocking trigger which prevents the same tag from firing on the ‘order confirmation’ page then then your tag will not fire on the ‘order confirmation’ page even when the tag is supposed to fire on all pages of your website according to the firing trigger.

Introduction to GTM Variables

A variable is a storage location in the computer memory. It has got ‘name‘ and ‘value‘. A variable is referenced by its name. Value is that expression that can not be solved any further. For example the expression ‘2+3’ is not a value because it can be solved further into 5. However the expression ‘5’ can not be solved further, so it can be used as value.

In the context of GTM, a variable is a function which can be called from within a tag, trigger or another variable. A variable tells GTM where to fire a tag. For example,

{{url}} matches RegEx .* // fire the tag on any page that is downloaded by a user.

Here {{url}} is a built-in variable (predefined variable) which refers to the URL of currently loaded page.

Following is the syntax for calling/referencing a variable in GTM:

{{Variable Name}}

You can reference/call a variable in any text field in GTM wherever you can see the ‘variable’ button:

Note: The value of GTM variable is populated during run time.

A variable is used to store data that is used in defining a trigger and/or to pass information (like product price, google analytics account id etc) to tag(s) at runtime from:

  • Data layers
  • JavaScript Variables
  • First Party Cookies
  • HTML DOM

In GTM there are two categories of variables:

  1. Built-in variables (or predefined variables)
  2. User defined variables

Built-in Variables in Google Tag Manager

Built-in variables are predefined variables. These variables can not be customised. In order to see the list of built-in variables available to you, click on the ‘Variables’ menu:

Configuring a built-in variable means activating or deactivating the variable from within the GTM interface. Only a particular set of built-in variables are enabled by default:

Once a built-in variable is activated it can be used just like any user defined variable. Activate all of the built-in variables so that they are available to be used anytime. 

In GTM the number and type of built-variables that are available depend upon the type of GTM container being used. Following are the different types of GTM containers:

  1. Web container
  2. AMP container
  3. Android container
  4. IOS container
  5. Legacy mobile containers

 

User defined Variables in Google Tag Manager

User defined variables are the variables defined by people like me and you. If you have created user defined variables then you can see them by clicking on the ‘Variables’ menu:

The real power of Google Tag Manager lies in the usage of variables.

Announcement about my new books

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and Beyond
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Himanshu Sharma

Certified web analyst and founder of OptimizeSmart.com

My name is Himanshu Sharma and I help businesses find and fix their Google Analytics and conversion issues.
If you have any questions or comments please contact me.

  • Over eleven years' experience in SEO, PPC and web analytics
  • Certified web analyst (master level) from MarketMotive.com
  • Google Analytics certified
  • Google AdWords certified
  • Nominated for Digital Analytics Association Award for Excellence
  • Bachelors degree in Internet Science
  • Founder of OptimizeSmart.com and EventEducation.com

I am also the author of three books: