#GTMTip Track GTM Version and ID as a Custom Dimension

Have you ever had the nightmare of opening your Google Analytics (GA) account to find that the data you were interested in stopped tracking?

Maybe it was an event for the shiny new CTA on your site and you had the event tracking setup and working, but it suddenly stopped at some point.  One culprit of this nightmare, are changes made in Google Tag Manager (GTM). Maybe you’re the only person who edits GTM and you didn’t realize the implications of a change, or maybe there are a lot of people editing your GTM Account and a change was made that you weren’t aware of.

Either way, because you’re a smart marketer you’ve implemented all tags, including Event tracking, via GTM. But there’s been countless updates and versions since then, so what’s the easiest way to fix this? You could use GTM’s built in change log but this usually proves to be unwieldy and confusing at best. This post provides a better solution.


There’s two very useful, and often overlooked, built-in Variables within GTM: Container ID and Container Version. We’ll combine these two Variables to create a powerful utility Custom Dimension used for debugging and diagnosis.

The Setup

These two Variables are exactly what you’d expect; the Container ID is the common “GTM-XXXXXX” that we’re accustomed to seeing in the GTM interface, source code, and Tag Assistant. The Container Version is the version of that Container, most commonly found in the interface. Each GTM Container has a version number, which starts at 1, and increments every time you publish the Container or create a new version.  


Before we dive in to GTM, let’s make a quick stop in Google Analytics to set up the Custom Dimension we’ll need. This can be found in the Admin section of GA, in the Property column, under Custom Definitions:image2

Create a new Hit scope dimension (we want this to be hit scope because we’ll be sending this dimension with each individual hit being sent to GA from GTM). You can name it whatever you’d like, but I’d suggest something descriptive (Hint: in the screenshot below the name is descriptive and shows how it flows into GA from GTM):image3

Now let’s head back to GTM. To get started using this #GTMTip, first make sure Container ID and Container Version are “on”:


Now, let’s combine these two built-in Variables to create a single user-defined Variable – this is to make our life easier and to reduce the risk of error. Combine them by creating a new constant Variable.

For naming consistency purposes, I recommend naming the Variable the same name we gave the Custom Dimension we created earlier in GA. Define the variable using the Container ID and Container Version Variables, separated by a character. The character you use is arbitrary, but I would recommend not using a space or Regex special characters to avoid making mistakes when trying to use the Custom Dimension later. Here’s what it could look if you use the “_” as a connector:


We’re almost there – the last step is to add this to all current and new GA tags in the future, including Pageview and Event tags. This can be done in any Universal GA template Tag under step 3, Configure Tag, within the More Settings dropdown select Custom Dimensions (Classic GA template Tags use the Custom Variables selection). Populate the Index field with the number we noted earlier when we created the Custom Dimension in GA, and the Dimension Value with the Variable we just created. This is what this will look like if your Index value is 1 for a Pageview tag:

configuretagThe Outcome

And, that’s it. You’re all set! Now as your Tags send data to GA this Custom Dimension will be populated with the GTM Container and Version Number that it was sent from – awesome! You’ll be able to use this in GA reports as a Secondary Dimension, Custom Reports, and via the API directly.

Use Cases

Going back to the nightmare I started this post with, one use case of this Custom Dimension is to see your GA data alongside the GTM Container and Version to easily see what version correlates to a change in your GA data. Using a custom report, here’s a screenshot showcasing this:


Since GTM Preview mode fires live hits to GA, another use case is to view the hits you’ve sent from preview mode. If you’re not comfortable using tools like Charles or deciphering the network traffic in the console this is a great way to view information about your hits that can’t be seen via GA Real-Time reports, like event labels.

What other uses have you found for this Custom Dimension? Have a better way to do this? Want to nerd about other Custom Dimensions? I’d love to get your feedback, thoughts, cash donations (just kidding), in the comments section below or via twitter @Jaycohh!