5 Must Have Google Tag Manager Variables

must have google tag manager variables

Creating variables within Google Tag Manager is one of the many features that make tag management so powerful.

While this is the case across the board, a lot of us stick to the built-in variables because we know they work. There is a lower chance that errors flow into your data since these have been created and vetted by Google.

Don’t let this distract from the powerful variables you can create. There are a few main custom variables you can create in GTM to better help your implementation. Check out the top Google Tag Manager variables to create below.

Don’t want to wait, download an importable container now!

1. GA Base Code – Constant

Most GTM implementation specialists know this one, but I can’t stress the importance and ease of use. Creating a constant variable to house your Google Analytics UA number will save time every day you work with GTM.

Create a new constant variable and insert your Google Analytics UA number (i.e. UA-12345678-9) into the value area. Then, you can recall the variable each and every time that you need to insert the number (i.e. all Google Analytics tags).

google tag manager constant variable
Insert your UA number in the constant area

2. Element Title – Auto Event Variables

Many times when trying to track the click of a particular element on your site, you pull from different attributes within the element. Sometimes that may be alt text, sometimes the visible text itself or a slew of other attributes.

One attribute that is used often is “title”. If you want to capture that, GTM makes that easy to accomplish through auto event variables.

By creating a new auto event variable you can select a variable type of element attribute. In the attribute name area, enter the name of the attribute (i.e. title) that you want to pull the value of from the element selected.

element title google tag manager variable
This will pull the value of the title attribute

You can repeat this process for any other element attribute you would like to pull. For a more in-depth look at this, check out element attributes for GTM

3. Document Title – JavaScript Variables

Similarly to the Element Title many times we want to pull data that is inserted directly into the page information. One of the most used cases for this is pulling in the page, or document, title.

In order to do that we have to create a new JavaScript variable inside of Google Tag Manager. Once you have selected to create a new JS variable, fill in the value as shown below.

document title javascript variable gtm
Pull in the title of the page document

4. Download Name – Custom JavaScript

One request I get from clients more often than not, is how can I accurately pull in the names of PDF downloads on my site for tracking. This used to be a tough answer.

You could either pull on the click text of the download, or the entire file name, but nothing was too consistent. Thankfully, through GTM, you can create a simple custom JavaScript call to grab the extension of any download. If you file structure is: /downloads/files/pdfs/whitepapers/2017/march/gtm-top-variables.pdf, this script will just pull in gtm-top-variables.pdf and send that to your event label (or whichever you choose).

Since we all aren’t JavaScript experts (including myself), I have outlined exactly how to create this variable below.

google tag manager custom javascript variable
This will display name after the last “/” in your file

5. URL Host Name – URL Variables

There are a lot of ways that we try to figure out what is and what is not on our own domain. The main reason in tracking analytics is to identify outbound links.

I’ve seen multiple configurations of triggers for tracking outbound links through Google Tag Manager, but the best is by using a custom variable.

Select to create a new GTM variable and this time select URL. There are a few options for Component Type under the URL variable type. For this we will want to select Host Name. After selecting that make sure to check the box to strip the www.

url variable for hostname google tag manager
Make sure to check the strip the www box

That is all you need to do to enable this powerful variable. From there, if you want to track outbound links, use it in a trigger to fire an outbound link track when that URL Host Name variable does not contain your domain.

outbound link trigger for gtm setup
Make sure to utilize the Host Name variable for outbound links

Summary

There are many different opinions when it comes to the top variables to create in Google Tag Manager. If you are just getting started, or looking for ways to improve your implementation, I hope these help you along.

Make sure to download the free container which includes all of these variables. You can then import this into your current container and utilize all of these great variables for your site.

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

Add comment