Understanding Variables in Google Tag Manager (GTM)

Sep 15, 2024 | Google Analytics / Tracking

What do variables in Google Tag Manager even do? Learn the basics about variables in GTM, how they benefit you, and when to use the different kinds.

GTM variables

Variables in Google Tag Manager are at work in almost every tag in your container. You don't need them for basic configuration tags, but they're necessary for taking analytics reporting a step further and extracting engagement data directly from a website.

Introducing variables in tracking efforts, while intimidating, can truly enhance your user insight. So what do they all mean and when will you need to use them? Our Digital Marketing Analyst, Kaylie Pitts, offers a quick summary that will leave you with clarity!

What are GTM Variables?

Variables, in short, are bits of information recorded in a website's data layer. This feedback can be extracted each time a user takes any sort of action.

Once collected, that information can be used to configure triggers and send data to your 3rd party measurement tools (like Google Analytics, Facebook, LinkedIn, etc.).

For example, say you want Google Analytics to tell you each time a person clicks a Sign Up button for your newsletter. There is a variable called Click Text, which in most cases will record the text field of whatever element was clicked. You can set a GA4 event tag to fire when the click text equals "Sign Up."

Variables may also serve as placeholders for dynamic values that change depending on user behavior. If someone makes a purchase from an e-commerce website, a data layer variable can be configured to pull in the exact dollar amount that was paid for the order, which then funnels into your platform reporting. Configuring variables as placeholders makes it easy to reuse data and extract information that changes with each new session, rather than having to hardcode it. 

Now that we're a bit more familiar with why variables exist, the next step is understanding the difference between built-in variables and user-defined variables.

Built-In vs. User-Defined Variables

Built-in Variables

Of the two types, built-in variables require much less configuration. They are pre-configured by Google Tag Manager and designed for common tracking needs. Our previous Click Text example is a perfect use case. Other examples include Page URL, Scroll Depth, Form ID, and Page Path. You'll typically use these to start off with more elementary tracking—clicks, page views, and generic form submissions.

user-defined variables in GTM
built-in variables GTM

 

User-defined variables

User-defined variables are customizable and intended for more specific tracking needs, like our ecommerce transaction example above. These are more commonly applied for a single website, as they will be unique to what is recorded in the backend code of the site.

Common Types of User-Defined Variables

Data Layer Variables

As the most common type of user-defined variables, data layer variables involve pulling dynamic, pre-defined information that's pushed to the data layer of a website. If you have unique form submissions with certain text fields users need to fill out, you'll want to use data layer variables to pull that information into reporting. It's also used for ecommerce reporting—transaction values, tax dollars, order numbers, and product names included in the purchase.

JavaScript Variables

This variable is only viable if your website already contains global JavaScript variables on its webpages. Some websites have existing JavaScript variables that you can access through the GTM JavaScript Variable function. This is a good alternative if other user-defined variables aren't sufficient for any complex tracking needs you may have.

JavaScript variables essentially work the same as Data Layer variables, just with the added knowledge that you are needing to pull information from a JavaScript code or variable already existing on your website rather than something pushed straight through to the data layer.

Constant Variables

Constant variables are essentially a static value (a value you don't ever need changed, but need to repeatedly reference). A perfect example of this: a Google tag. You may want to make one for your GA4 Measurement ID, but that ID needs to be referenced as a variable every time you create GA4 events after the fact. 

Need Help?

When it comes to Google Tag Manager, variables are key to capturing those all-important user interactions and making your tracking as unique as your business. With both built-in and custom variables in your toolkit, you can unlock next-level insights and make data-driven decisions.

Need a hand? From basic button clicks to advanced e-commerce tracking, our analytics team can ensure you're gathering the data you need. Contact us!

Looking to implement variables into your tracking strategy?

Our Digital Marketing experts will set you up for success.

Get Started Today


Share This Article

Back to Blog

We want to be your partners in success.

One simple conversation can change your business forever.

Animated Loading Gif

Loading

Please wait while we set things up for you!