What are triggers in Google Tag Manager?
Google Tag Manager triggers are components that define when and under what conditions tags should be fired. They determine the events or user interactions that activate specific tags.
Triggers essentially listen for certain actions or conditions to occur on a website or mobile app and initiate the firing of tags accordingly.
They can be set up to respond to various types of events, such as page views, form submissions, button clicks, link clicks, video plays, scroll depth, and more.
They can also utilize built-in variables or custom variables to add additional conditions to the firing logic.
Basically, triggers are responsible for detecting specific events on your web page or mobile app, such as form submissions, button clicks, or page views. They act as listeners, waiting for these events to occur.
When a trigger detects the specified event, it instructs the associated tag to fire.
When the code on the page or app is executed, triggers are evaluated. If the conditions set within the trigger are met, the associated tags are fired, allowing them to perform their intended actions.
Conversely, if the trigger conditions are not met, the tags will be blocked from firing. It is important to note that every tag in Google Tag Manager requires at least one trigger to be assigned in order for it to fire when the associated event occurs.
Why you should use triggers
By configuring triggers in Google Tag Manager, you can precisely control when tags are triggered, ensuring that they fire only when the desired events or conditions are met.
This flexibility allows you to implement various tracking and marketing solutions without directly modifying the underlying website or app’s code.
Example
Let’s say you have a website where you want to track the number of clicks on a specific button. You can use Google Tag Manager (GTM) to implement this tracking. Here’s a practical example that will help illustrate the differences between triggers, tags, and variables in GTM:
Triggers
Triggers in GTM determine when and where tags should be fired. They define the conditions that must be met for a tag to be activated. In this example, we’ll create a trigger that fires when the button with the ID “clickButton” is clicked.
The trigger could be named “Button Click Trigger” and configured with a specific event type like “Click” and a filter for the element ID equal to “clickButton”.
Tags
Tags are snippets of code that are fired or executed when a trigger’s conditions are met. In this case, we’ll create a tag called “Button Click Tag.” The tag could be configured to track the button click event by sending an event to Google Analytics, for example.
It might contain the necessary JavaScript code to send an event when the button is clicked.
Variables
Variables in GTM are used to capture and store dynamic values from the website. They can be used in triggers and tags to make them more flexible and reusable. In this example, we’ll create a variable called “Button ID Variable” that captures the ID of the clicked button.
This variable can be used in the trigger to check if the button ID matches the expected value and in the tag to pass the button ID as a parameter in the event tracking code.
To summarize
Triggers define the conditions that must be met for a tag to be fired. They specify when and where tags should be activated.
Tags are snippets of code that are executed when a trigger’s conditions are met. They perform specific actions like sending data to analytics platforms or other tracking systems.
Variables capture and store dynamic values from the website. They can be used in triggers and tags to make them more flexible and reusable.
In this example, the trigger ensures that the tag is only fired when the button with the specific ID is clicked. The tag, in turn, performs the desired action, such as sending an event to Google Analytics. And the variable allows us to capture the button’s ID dynamically and use it in the trigger and tag setup.
How to create a trigger
To create a new trigger in Google Tag Manager, follow these steps:
- Click on “Tags” and then select “New”.
- Click on “Trigger Configuration”.
- Choose the type of trigger you want to create.
- Complete the setup process for the selected trigger type.
How to create a trigger while configuring a tag
- Go to the tag configuration page.
- Click on “Triggering”.
- Click on “Add” to add a new trigger.
- Proceed to “Trigger Configuration”.
- Select the type of trigger you want to create.
- Complete the setup process for the selected trigger type.
How to edit a trigger
To edit an existing trigger in Google Tag Manager, use the following steps:
- Click on “Triggers”.
- Locate and click on the name of the trigger you want to edit.
- Click on “Trigger Configuration” to make changes to the trigger settings.
- Use the “More actions” option to perform additional actions such as copying, deleting, viewing changes, or adding notes for the selected trigger.
Trigger filters
By default, new triggers in Google Tag Manager are set to fire on all events associated with a specific event type. However, you can fine-tune the trigger’s firing behavior using trigger filters.
To apply a filter, simply locate the “This trigger fires on” section at the bottom of the trigger configuration page and choose “Some <event>”, where <event> represents the desired event type you wish to work with.
Trigger filters allow you to specify specific conditions under which the trigger should fire. By enabling a filter, you gain the ability to define precise criteria for when the trigger should be activated. This provides greater control and flexibility in determining the events that will trigger the associated tags.
Each filter consists of a Variable, an Operator, and a Value:
| Variable (menu) | Operator (menu) | Value (text field) |
|---|---|---|
| In the menu provided, you have the option to choose the most suitable Tag Manager variable that already exists, add a new built-in variable, or create a brand new variable. This menu allows you to select the appropriate variable based on your specific needs and requirements. | In the Operator menu, you can select from a range of operators to define the comparison or logical operation to be performed. These operators include options such as "equals," "contains," "less than," "matches RegEx" (regular expression), and more. By choosing an operator from this menu, you can specify how the value should be compared or matched in relation to the variable being evaluated. | In the provided text field for Value, you can enter the appropriate value that will be compared to the value in the variable during runtime. This value serves as the reference point for the comparison or matching process. By entering a suitable text value, you can precisely define the criteria for the comparison and determine when the filter or trigger should be activated based on the value provided. |
Example
Let’s consider a tag that has a trigger based on a pageview event. To ensure that this tag fires on specific product pages of a website where “/products/” is a consistent part of the URL, you can utilize the following filter:
Page URL contains “/products/”
By setting this filter, the tag will be triggered only when the page URL contains the specified text “/products/”. This enables precise targeting, ensuring that the tag fires exclusively on the relevant product pages where this URL pattern is present.
Firing triggers and blocking triggers
Firing triggers determine when tags should be activated. A tag will fire when the conditions of any of its triggers are met. For example, if a tag has two triggers—one for all pages and another for a specific page—the tag will always fire on all pages.
Triggers are configured at the bottom of a tag’s configuration page. When creating a tag, you will be prompted to add a trigger to the configuration before saving the tag.
On the other hand, a trigger exception, also known as a “blocking trigger,” can prevent another trigger from firing under specific conditions.
For instance, if a tag has a trigger to fire on all pages and a trigger exception is set with the condition “Page URL equals thankyou.html,” the tag will never fire on the page “thankyou.html”.
When using advanced Tag Sequencing settings, a tag disregards its own triggers and instead fires as part of the specified sequence.
How to add or remove a trigger from a tag configuration, or to create an exception
- Click on “Tags” in the left navigation menu.
- Select the name of the tag you wish to edit.
- Click on “Triggering”.
- To add a trigger, click on “Add” in the Firing Triggers section.
- To remove a trigger, click on “Remove” next to the trigger you want to remove from the Firing Triggers section.
- To add a trigger exception, click on “Add” in the Exceptions section.
- To remove a trigger exception, click on “Remove” next to the entry you want to remove from the Exceptions section.
Trigger types
To learn about all trigger types available, read this post.