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
mailto:firstname.lastname@example.org 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.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.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 *