Articles in this section

Google Tag Manager – Triggers and Variables

Triggers: for events

Using the Tracklution Template in Google Tag Manager, each event has its own tag, and each tag need at least one trigger.

A trigger in Google Tag Manager is what defines the conditions that fire the tag, which sends the event to your server (Tracklution).

The triggers are often set up using dataLayer events. These are events that your website push to the dataLayer when for example, an item is added to a shopping cart, or when a contact form is submitted. These pushes to the dataLayer are usually prebuilt and included or activated if you use a website builder, or managed by your website's web-developers for custom sites. When we browse the website through Google Tag Manager Preview, we are able to see these dataLayer events, these are the ones that appear on the left side of your screen when inside Preview, for example Container loaded, DOM Ready, or Window Loaded. If dataLayer events with specific names like, form_submit, or add_to_cart happen on the website, this list is where you will see these events. In Google Tag Manager we can configure triggers that listen for these dataLayer events. You can use other conditions to trigger your tags, but using the dataLayer is the most common method.

To make a dataLayer trigger in GTM, you'll select Custom Event and input the event name from your dataLayer that you want to use. This is case-sensitive, make sure to write the event name to match exactly. 

Custom Event triggers also allow you to use RegEx matching should you need to. One example where to use RegEx is when you have a dataLayer with inconsistent naming or casing. This is slightly more advanced, and the proper solution is often to go back and fix the dataLayer, but sometimes that's just not an option, and then RegEx can be a handy tool. There are many opportunities when using RegEx, this was just an example.

DL_trigger


As mentioned, triggers can listen for many more conditions than just a dataLayer event. Triggers can for example listen for a specific web-page's URL (a thank-you page), website elements, or a specific link on a click. The important thing is to find a unique condition for a website-action that you want to tag as an event and send to your server. This can be very simple, or very complex, depending on how your website is built and what it is you define as an important action that you want to be tagged.

 → subscribe to Tracklution Academy's upcoming GTM series on YouTube.


Variables: for parameters

When you send an event, you often want to include additional information. These are your event parameters, and they are populated in Google Tag Manager by using variables.

A Google Tag Manager variable isn't much different than a trigger. When a trigger listen for a condition to fire a tag, a variable listen for a key (or condition) to return a value, which then populates your event's parameter.

If you use Data Layer Variable in GTM to listen for keys in the dataLayer, you should be aware that they follow hierarchies. Top level keys are found by just writing the name of the key in the variable. Keys that are nested within another key are found by writing both the top level key and the nested key in the variable separated by a dot.

Examples
  • Top level key for a form submit event is often the form ID (often written as form_id), this would be written in the variable as: form_id
  • Parameter keys for a purchase event, like currency, are often nested under the ecommerce top level key, this would be written in the variable as: ecommerce.currency

These keys from the dataLayer are also case-sensitive, make sure to write the name of the key to match exactly. You can easily edit the name of your key by opening the Variables tab in Google Tag Manager, select the variable you need to edit and update the name of the key. 

DL_variable


GTM variables are powerful and can be used for many things, the GTM Data Layer Variable is just the most common. You can for example have a JavaScript in a variable listen for a specific condition and return 'true' or store a specific value. That can then be used to further define the condition of a trigger. For example, you can trigger a Subscribe event tag on a page's URL path that contains 'success', but further define the condition to: only if my javascript variable returns 'true'.

Comments (0)
Access denied
Access denied