Identify and solve GTM trigger issues

Business Benefits

Collect consistent and correct data.

Use Enable conditions to specify on which pages triggers should actively listen for trigger events and the Fire condition to specify what in the event itself determines whether tags having specific trigger should fire.

Pay particular attention to Just Links and Form Submission triggers, as they have both Enable and Fire conditions.

In the image above, the Enable condition states that the trigger should actively listen for link clicks only on pages where the page path contains the string /contact/. The Fire condition states that any tag to which this trigger is added should only fire on links that include in their URL.

Fix broken Just Links and Form Submission triggers by allowing events to propagate all the way to the top of the document.

GTM’s triggers will not work if the event propagation has been stopped. They will work, however, if the default action is prevented.

  • Talk to your developers if you find that a Just Links trigger or a Form Submission trigger will not work even when you know there is no custom handler logic.
  • Find out whether just using event.preventDefault() instead of event.stopPropagation() would be sufficient.
  • Look into using custom events if the stopPropagation() call is essential.

Debug issues with these triggers by browsing through the site source code using the browser’s developer tools. Look for custom link and form handlers that interrupt the default browser event either by stopping its propagation or preventing its default action. A very common culprit is a return false; call within a jQuery event handler. This combines both event.stopPropagation() and event.preventDefault(), when only the latter is necessary in most cases.

Load the YouTube IFrame Player API with the page load, give each video its own iframe element, and do not reload or modify iframes after they’ve been loaded once to ensure dynamically inserted videos work seamlessly with YouTube video triggers.

The YouTube Video trigger detects iframe embeds with YouTube domains as they are inserted into the page, decorates them with listeners, and doesn’t touch them again. So GTM’s trigger will stop working if the site reloads or modifies the iframe after it’s decorated.

Use the Matches CSS Selector predicate when using the All Elements trigger to capture the actual element clicked.

The Matches CSS Selector predicate offers more comprehensive click tracking than any other attribute like Click ID or Click Classes. Always use the following syntax when using the All Elements trigger, since it captures the actual element that was clicked:

Click Element matches CSS selector , *

```For example, if you wanted to track clicks on an element with the ID ***#main***, your trigger condition would look like this :

Click Element matches CSS selector #main, #main *

## Use the *Page View* trigger type to fire a tag at the earliest possible moment.

This is useful in case you have scripts that need to be loaded as soon as the GTM container is ready to process tags. Typical examples include consent tags, analytics libraries, and A/B testing scripts.

## Use the *DOM Ready* trigger type to fire tags as soon as the page HTML document is read by the browser.

The ***DOM Ready*** trigger is your best friend when you need to fire a tag that references an element in the page HTML document. If you set this tag to fire on an earlier trigger, such as ***Page View***, it could cause a race condition, where the tag fires before the value is available in the browser.

## Use the *Window Loaded* trigger type to fire tags that need to reference an asynchronously loaded resource.

The ***Window Loaded*** trigger is usually the safest trigger to use for tags that reference an asynchronously loaded resource on page load, such as a JavaScript file or an API call. For example, if you have a tag that requires the jQuery library, and the library is loaded asynchronously when the page is loaded, using the ***Window Loaded*** trigger ensures that the tag that requires jQuery to be loaded is fired.