GTM Integration: Data Track Attribute

attribute variables for data-track google tag manager

In a previous post, I talked about the creation of a Google Tag Manager variable which can pull out any element attribute that you would like. Now by default, GTM tracks click urls, click text, click IDs and more. This previous article covers how to pull out the value of any attribute you can create.

That brings up a great area where your programming team and metrics or analytics team can work more seamlessly together for GTM integrations. If you need to pull on specific element attributes to get the data you need from the DOM, there are endless possibilities, and depending on the specific element, you could be creating many different macros to pull in the relevant data.

This is where many Google Tag Manager users say, you can take a lot away in regards to working with your programming or IT team, but working together can make GTM a more enjoyable experience.

In our organization, we came to the conclusion that we should create one known attribute that contains information to be tracked via Google Analytics or other analytics platforms. For this we landed on our now centralized element attribute, data-track. Anywhere we need to place data, static or dynamic, we place the data-track attribute within the element needed. For instance, let’s say we have a store locator and once the locator was used it gives us three possible stores to visit. From there we click on a link out to the store’s website.

Within the a tag element for the click out, we create the data-track element to show the store name and number (as seen below).

<a href=”” data-track=”Hardware Store 123″>

We then build out the data-track variable within GTM (see more about building variables on custom attributes here):

data-track variable creation in gtm
Creating the Data-Track variable with a Custom Javascript

And then can create an event tag for when this (and other links like it) are clicked on the locator page:

locator gtm tag implementation
Create a new Universal Analytics tag with these parameters

The best part of using one common element attribute across everything you need to track from clicks and other interactions, is you limit the number of variables you will need to create in GTM. The more variables you have lurking around, the easier it is to get distracted. This can create confusion during the implementation and cause oversite.

Chris Kujawski

Founder and instructor at Digital Metrics Guru.

A passionate and driven digital marketer, specializing in Google Analytics, Tag Manager and Data Studio. A qualified expert in Google Analytics and Adwords, with more than 10 years experience delivering sound solutions to clients worldwide.

View all posts


  • Great article. Your last paragraph made me rethink my implementation.

    One issue i saw in your article is that your return JS script is incorrect. It should read:

    return e.getAttribute(‘data-track’);


Popular Videos