Make Your GTM Auto-Event Tracking More Resilient

Mitch Daniels, Former Senior Digital Analyst

Article Categories: #Strategy, #Data & Analytics

Posted on

Several months ago, Google announced a brand new ‘auto-event tracking’ feature within Google Tag Manager (GTM). This feature allows GTM users to fire snippets of tracking code (or any code, for that matter) without making any modifications to a page’s markup. Instead, GTM can ‘listen’ for specific interactions, such as clicks, link clicks, and form submissions, which then trigger individual GTM tags.

Auto-event tracking has helped us streamline our tracking implementation process and allowed us to take some tedious tagging work off the shoulders of our Front-End Developers. In addition, GTM’s linkClick and formSubmit listeners offer hitCallback functionality, which improves the performance and accuracy of our tracking.

However, auto-event tracking carries an important caveat: GTM rules that are dependent on specific page markup are fragile. For instance, a rule that is set to fire on click of element.className==‘upper-nav button’ might work on site launch, but will break without warning if that className is ever modified in the future.

To minimize this fragility while maintaining the flexibility associated with tag management, we implemented a ‘middle-ground’ approach on sites such as Dick’s Sporting Goods’ new 2014 Baseball Digital Lookbook. We’re using a ‘data-track-gtm’ attribute with our ‘Category’, ‘Action’, and ‘Label’ values on each tracked element on the site. We then fire an event tracking request with those corresponding values whenever the following two rules are satisfied:

  • {{event}} contains
  • {{has data-track-attribute}}* equals true

* Custom JS macro:

 function() {
 var tracking = {{element}}.getAttribute('data-track-gtm');
 if (tracking) {
 return true;
 } else {
 return false;

The presence of the data-track-gtm attribute alerts our developers to the fact that the element is tracked, while still granting our analytics team the flexibility and improved accuracy that GTM provides.

We’re head-over-heels for the many benefits that GTM offers our analytics team. It allows us to streamline our tagging process and grants us a level of flexibility never before available. Auto-event tracking adds yet another level of flexibility and, with the appropriate customizations, makes our tracking even more accurate and efficient.

Related Articles