Beginner’s Guide to Triggers in Google Tag Manager

/

beginners-guide-to-triggers-in-gtm
Google Tag Manager makes it extremely simple to track different user interactions. The user interactions can be observed via Google Tag Manager and tracked in Google Analytics by sending something called a “Google Analytics Event.” Google Analytics Events can be defined and configured in Tag Manager by having a combination of a tag, triggers, and variables. Read more on this post to better understand the underlying mechanism of Google Tag Manager. But essentially,

  • A tag is used to collect and report an interaction to Google Analytics, or some other reporting tool.
  • A trigger is used to observe an interaction and to decide whether a tag should be fired or not.
  • A variable is used to capture some information off the page and provide that info to the triggers or tags when needed.

Google Tag Manager can automatically “listen” for actions happening on the page. When an interaction occurs, GTM will compare it against a list of expected interactions, aka triggers, and if a match is found, GTM will take action and fire the corresponding tag.

Sega Genesis Trigger

We love all types of triggers!

This blog reviews the many ways a trigger can be set up to observe, or listen to, an interaction happening on a page.

Triggers in Google Tag Manager

GTM offers several trigger types that can be used to fire tags. You can find a list of them when you create a new trigger.

Events in Google Tag Manager

  • Page View listens for the page being fully loaded and ready to view
  • Click trigger listens for any click on the page (on any type of elements)
  • Form Submission fires when a form is successfully validated and submitted
  • History Change fires when the browser history changes, i.e. a page change
  • Custom Event trigger listens to the events being pushed via the dataLayer
  • JavaScript Error fires when the scripts errors out
  • Timer fires after an interval of time

Let’s go through a few examples to see when and how some of these triggers could be used.

Page View Triggers

You want to track the pageviews, i.e. every time a page is being viewed. Which one of the above triggers do you choose? The Page View trigger. Note that within Page View triggers, there are three separate trigger types to choose from:

  • Page View fires when the GTM container code is loaded on the page. It fires even before you can see the page content. This trigger is the most basic trigger which is used often to fire a Pageview Tag. This is our “as soon as possible” trigger.
  • DOM Ready fires when the Document Object Model is ready, which means the browser is finished putting all the HTML elements in their appropriate positions. We use this if we need something to be present on the page before we fire a tag.
  • Window Loaded is the last chronologically and fires when the browser has finished rendering and displaying everything on the page.

Page View Trigger has a dropdown menu

Click Triggers

This type of trigger listens for the most common interaction a user will take, clicking their mouse.

There are two different trigger types for this trigger:

  • All Elements will literally fire anytime the mouse is left clicked. This could be on an image, a button, a link, or form element.
  • Just Links fires only when an HTML link is clicked on.

All Elements Trigger

If you want to find out if a button is being clicked on, i.e. a button with no links in it. Which trigger would you use? The Click trigger, with the All Elements trigger type. When you create a click trigger, behind the scenes, GTM would listen to every single click that is happening on the page and compare it against the conditions in the trigger you defined. Once a match is found, GTM will fire the corresponding tag.

Google Tag Manager Click Trigger Types

Here is an example showing you how to set up a trigger to track clicks on a button with class callToAction:

  • Choose Event: Click
  • Configure Trigger: Targets = All Elements
  • Fire On: Some Clicks -> Click Element — matches CSS selector — button.callToAction

Notice how we are using the CSS Selector to make sure we are only targeting buttons with the class callToAction and not any other element that might have that class. Be specific when you define your triggers.

Google Tag Manager Click Trigger Example - Tracking a button with class call to action

Link Click Triggers

You want to track the links in the navigation menu, or you want to track any link on the page, like file downloads or emails. Which trigger would you choose now? A Click trigger with a trigger type of Just Links. Check out this complete tutorial to learn how to track link clicks on your site.

For a link click trigger, select just links from menu

Another example use case for link click triggers would to track file downloads. We know to download a file we need to click on a link, so we use a link click trigger to track that action. Basically, on every link click, GTM would examine whether or not the link is meant to download a file, and if it is, GTM would fire a tag to report the download action to Google Analytics.

Sidenote: We’ve created easy, importable recipes for Google Tag Manager to tackle some of the most common tracking challenges, like our file download link recipe. We also have a outbound link recipe for links on your website that point to other websites, like your social pages or partners.

Form Submit Triggers

You want to track the successful submissions of a form. What would be the right choice for a trigger here? A Form Submission trigger. Here is an example to track a form with id equal to formID on the page www.example.com/formPage/ :

  • Choose Event: Form Submission
  • Configure Trigger: Select Check Validation
  • Enable When: Page Path — matches RegEx (ignore case) — /formPage/$
  • Fire On: Form ID — matches RegEx — formID

Google Tag Manager Form Trigger Exmample

Custom Event Triggers

You need to track a YouTube video, to find out, for example, how many times it has been watched. What would be the best choice now? A Custom Event. Custom Events are used to capture the events that were pushed into the dataLayer. The dataLayer is a code “bucket” used to pass information about both page content and user interactions to GTM.

If you define a Custom Event trigger, GTM would then examine events that have been pushed into the dataLayer, looking for a match to fire that trigger. This one is a little more complicated. You’ll have to figure out how to push new types of interactions to the dataLayer, or you may find a resource that someone else has created to do this for you.

For instance, our YouTube Tracking recipe listens for interactions with a YouTube video and then pushes those events to the dataLayer with the name “youtubeTrack.” Check out the blog post to better understand how the trigger and the tag are set up.

Google Tag Manager Custom Event Example - Youtube tracking


While this was just a quick overview of all the triggers in GTM, there is a lot more going into each single item we discussed. You can read more on our blog or consider attending our in-person Google Tag Manager workshops to learn more.

More Resources

Zee is an Analytics Engineer with a passion for user experience design. He is an advocate of simplicity, and he appreciates data-driven designs. He received a degree in Electrical Engineering from Georgia Tech where he challenged himself to solve complex engineering problems and competed at numerous coding hackathons. Zee enjoys reading, learning new languages, and helping local tech startups.

  • sarah

    This post arrived in my inbox right after I figured out how to set up a trigger on a button without a link, and right as I’m about to set up a form submission tag. Good timing! I always appreciate LM’s expertise and frequently find myself on your site as I set up new tags/triggers in GTM.

    • http://www.lunametrics.com/blog/author/zee/ Zee D

      That’s awesome! Glad you found it useful 🙂

  • Oren Verdn

    Hey Zee, great guide! (even read it all the way through 🙂
    I have a Tag manager question that iv’e been looking for it’s answer for some time now,
    and i would really appreciate your help:

    i’m running a tag to track all clicks on outbound links from my website.
    This tag exclude clicks on internal links in the following way:

    element url Does not match RegEx .*www.sitename.*

    My question is this: does this tag currently exclude link clicks to sub-domains as well?
    If not, what do i do to exclude internal link clicks as well as link clicks to various sub domains?

    • http://www.lunametrics.com/blog/author/zee/ Zee D

      Hi Oren,

      Have you had the chance to look into our Outbound Tracking Recipe? http://www.lunametrics.com/labs/recipes/outbound-links/

      That pretty much covers what you need.

      And regarding your trigger set up, it will work if you use something like this: {{click hostname}} — doesn’t match ignore case — sitename

      • Oren Verdn

        thank you!

Contact Us.

LunaMetrics

24 S. 18th Street, Suite 100,
Pittsburgh, PA 15203

Follow Us

1.877.220.LUNA

1.412.381.5500

getinfo@lunametrics.com

Questions?
We'll get back to you
in ONE business day.