Chapter 12 of 12:

So…I feel like I need to start this last post with an apology! If you recall in the 8th of 12 posts journaling my digital analytics quest with CXL Institute, I covered the first two components of a Tag Management System (TMS) (e.g., the Tag and Trigger), and at the end of the post I promised to cover the last main TMS component…the Variable!

“Mercer” of Measurement Marketing did a phenomenal job in my CXL beginner and intermediate Google Tag Manager courses explaining that variables are easily the most versatile component of any tag management system. A variable is a vessel or placeholder for a value. Take a second and think back to your Jr. High Pre-Algebra days where your math started using letters…those letters were your first introduction to the concept of a variable. Take this simple equation, for example:

(Ex. 10 + 2x = 22)

In this equation, “x” is the variable or placeholder for the product of the equation which, in this case, the value of “x” is 6. Granted this is an arguably over-simplified explanation of the concept that is a variable, but it adequately illustrates the point I am trying to make. Let’s take this nostalgic review and apply it to TMS variables. Within Google Tag Manager, you have two categories of variables:

  1. Built-in Variables
  2. User-Defined Variables

The Built-in Variables are there for your use right “out of the box”, all that is required to use them is to simply configure and enable them. Not to worry, it’s far more simple and straightforward than it sounds. All you have to do is:

  • Navigate to the Variable section of GTM and in the “Built-in Variables” section click on the “Configure” button (See Image Below for Reference)
  • Next, you will see a sidebar menu pop out which will present you with all of the Built-in Variable options you have to work with:
  • You can enable any that meet your tracking objectives, but as a rule of thumb, I recommend enabling the following variables to start out:

Pages Variables (Basically the primary components of a URL)

  • Page URL — returns the page Hostname and Path (also known as the URI) as the variable’s value (i.e., www.hostname.com/page/path).
  • Page Hostname — returns the page Hostname component of the URL (also known as the domain) as the variable’s value (i.e., hostname.com)
  • Page Path — returns the page Path as the variable’s value (i.e., /product/product-name/trial).
  • Referrer — returns the page previous to the currently loaded page as the variable’s value (i.e. if a user enters your website homepage from a Facebook advertisement, the Referrer variable would return “facebook.com” as the value.

Utility Variables:

  • Event — returns the value of whatever event is being listened for within the DOM of the HTML document (i.eThe GTM event pushed to the data layer when a click on an element is made returns “gtm.click” as the value.)

Errors Variables:

  • Debug Mode — when GTM debug mode is enabled in Preview mode, this variable will attach a URL query to the page path that returns the value of an “x” (i.e., domain.com/page/path?gtm_debug=x). This is helpful when filtering out internal and Q/A traffic.

Click Variables: NOTE — enable the All Element Clicks trigger along with these variables.

  • Click Element — accesses the gtm.element key in the data layer that is set by click triggers, which references and returns the value of the DOM element clicked.
  • Click Classes — similarly accesses the gtm.elementClasses key in the data layer that is set by click triggers, which references and returns the “string” value of the DOM element class that was clicked.
  • Click ID — accesses the gtm.elementId key in the data layer that is set by click triggers, which references and returns the “string” value of the DOM element ID that was clicked.
  • Click Target — accesses the gtm.elementTarget key in the data layer that is set by click triggers, which references and returns the “string” value of the DOM element Target that was clicked.
  • Click URL — accesses the gtm.elementUrl key in the data layer that is set by click triggers, which references and returns the “string” value of the DOM elementUrl that was clicked.
  • Click Text — accesses the gtm.elementText key in the data layer that is set by click triggers, which references and returns the “string” value of the DOM elementText that was clicked.

Form Variables: NOTE — enable the All Forms trigger along with these variables.

  • Form variables — access the same gtm.element components within the data layer as the Click Variables since they are tracking identical DOM elements, the key difference is that these variables are set with Form triggers as opposed to Click triggers.

This handful of Built-in variables will typically be more than enough in helping you fulfill the majority of most simple tracking objectives. BUT! Because I am presuming you are here for more than just simple tracking configuration, I will show you a few others to have in your back pocket when leveling up your data tracking game. The most important of which is the Google Analytics Settings variable…lemme tell ya, it’s a gas! If you don’t get that now…just wait for it, it will make sense soon. Anyhow, let’s take a minute and unpack this powerful variable.

Another uber cool aspect of variables is the inception-like ability to use variables within variables within variables ad infinitum.

The Google Analytics Settings variable is a perfect example of just that fact. Any input field of that variable that contains a little “lego” looking block icon can use another variable as an input. Truth be told, I could probably write an entire blog post on this variable alone…and who knows? Perhaps I will at some point.

Back to the point, this variable allows you to customize your Google Analytics interface similar to how you can in the admin section, but in a cooler, much more visual, agile format. Do you see those drop-down menus indicated in that green square? Do they look familiar? They should, you will find similar settings within the Google Analytics interface. Custom Dimensions, metrics, content groupings, eCommerce settings, cross-domain tracking, etc.

I have a couple of others that I have mentioned in previous articles (e.g., the Lookup Table and RegEx Table variables are wildly helpful in using existing variables as inputs and producing cleanly formatted outputs of the data that you’ve collected in a more understandable format.)

And we mustn’t forget the data layer and custom event variables that are essential for pushing information into the data layer.

Familiarize yourself with and practice, practice, practice using these User Defined GTM variables and I promise that you will soon become a data tracking force to be reckoned with.

Just a nomadic digital analyst finding his way to great light and knowledge through sharing it with you!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store