Google Tag Manager

GTM Variables for Beginners: What They Are and How to Use Them

What variables are in Google Tag Manager, the built-in ones to enable on day one, and the user-defined types marketers actually use, with examples.

8 min read
Quick answer

A variable in Google Tag Manager is a named placeholder that gets filled with a value when the page runs, like the current page's URL, the text of a clicked button, or a value your website pushed into the data layer. Triggers use variables in their conditions (fire when Click Text equals Subscribe) and tags use them in their fields (send the clicked URL to GA4). GTM ships with built-in variables you enable with a checkbox, and lets you create user-defined variables for everything else, written as {{variable name}}.

Tags are what runs and triggers are when; variables are the third building block, the what exactly. They’re how a trigger knows which button was clicked and how a tag knows what value to send, and once they click, Google Tag Manager stops feeling like a form to fill in and starts feeling like a system you can actually steer.

This guide covers what variables are, the built-in ones to enable immediately, and the user-defined types that show up in real marketing containers. If GTM itself is new to you, start with the Tag Manager beginner’s guide.

What a variable is

A variable is a named placeholder that resolves to a value at runtime. When something happens on the page, GTM evaluates its variables in that moment:

  • Page Path might resolve to /pricing/
  • Click Text might resolve to Start free trial
  • A data layer variable named order_value might resolve to 89.00

Variables get used in two places:

  1. Trigger conditions. “Fire when Click Text contains Subscribe” is a trigger using a variable.
  2. Tag fields. A GA4 event tag can send {{Click URL}} as a parameter, so the event carries whichever link was actually clicked.

The double-curly-brace syntax {{like this}} is how you reference a variable anywhere in GTM. Type {{ in a tag field and a picker appears.

Built-in variables: enable these first

GTM ships with predefined variables, but most are switched off until you enable them. This is the number one “GTM is broken” moment for beginners: you build a click trigger, nothing fires, and the real problem is that the Click variables were never turned on.

Go to Variables > Configure in your workspace and enable the groups you’ll use:

GroupVariablesYou’ll need them for
PagesPage URL, Page Path, Page Hostname, ReferrerURL-based trigger conditions
ClicksClick Element, Click Classes, Click ID, Click Target, Click Text, Click URLAny click tracking
FormsForm Element, Form Classes, Form ID, Form Target, Form Text, Form URLForm submission triggers
ScrollScroll Depth Threshold and friendsScroll depth tracking
VideosVideo status, percent, title, and friendsYouTube video triggers
UtilitiesEvent, Container ID, Random Number, and friendsCustom event conditions, debugging

Enabling a built-in variable costs nothing when it’s unused, so switching on the whole group you’re working with beats trickling them in one at a time.

The workhorses, in practice: Page Path for “which page am I on” conditions, Click Text and Click URL for click triggers, and Event (the name of the current data layer event) for custom event work.

User-defined variables: the types that matter

Under Variables > New, GTM offers a long list of variable types. A handful cover nearly everything marketers do:

Data Layer Variable. Reads a named value from the data layer, the structured information your website announces to GTM (the data layer is the “shared noticeboard” between your site and your tags). If your site pushes dataLayer.push({event: 'purchase', order_value: 89.00}), a Data Layer Variable named order_value hands that number to any tag. This is the single most useful user-defined type, because it doesn’t care what the page looks like, only what the site says happened.

Constant. A fixed value you name once and reuse, classically an account or destination ID you’d otherwise paste into a dozen tags. When the ID changes, you edit one constant instead of hunting through every tag.

Lookup Table. Maps one variable’s values to outputs: if Page Hostname is shop.example.com, output ID A; if it’s blog.example.com, output ID B. RegEx Table is the same idea with patterns. These keep containers with multiple sites or environments sane.

URL. Pulls apart the current URL and hands you a piece: a specific query parameter (like a promo code or a utm_content value), the fragment, the path. Handy when the information you need is already sitting in the address bar.

DOM Element. Reads a value from the page itself by element ID or CSS selector, like a product name printed in an <h1>. It works, with the caveat that it breaks when the design changes; prefer a data layer value whenever you can get one.

Custom JavaScript. A small function that computes a value when nothing else can, like lowercasing a value or combining two others. Powerful, and also the type most likely to quietly break, so treat it as the option of last resort and keep the functions tiny.

A worked example: one variable, used twice

Say you want a GA4 event when someone clicks any pricing link, and you want the event to say which link it was.

  1. Enable the Click variables under Variables > Configure.
  2. Trigger: a Just Links trigger with the condition Click URL contains /pricing.
  3. Tag: a GA4 event tag named pricing_link_click, with an event parameter link_url set to {{Click URL}}.

The same variable is doing both jobs: deciding when (in the trigger) and enriching what (in the tag). That pattern, one variable feeding both a condition and a parameter, is most of day-to-day GTM work; the button click tutorial builds a complete version of it.

Debugging variables in Preview mode

Preview mode is where variables stop being abstract. Connect it to your site, do the thing you’re trying to track, click the event in the left-hand timeline, and open the Variables tab: every variable and its exact value at that moment, side by side.

Two habits worth forming:

  • When a trigger doesn’t fire, check the variable’s actual value first. Nine times out of ten, Click Text has extra whitespace, different capitalization, or belongs to a child element you didn’t expect.
  • When a tag fires but the data looks wrong in GA4, check what the variable held when the tag fired, not what it holds now. Values change as the page runs; the Variables tab shows the snapshot per event.

The full Preview workflow has its own guide: how to use GTM Preview mode.

Keep them named and few

Variables multiply quietly. Two rules keep a container readable:

  1. Prefix user-defined variables by type, like DLV - order_value for a Data Layer Variable or LT - ga4 id by hostname for a lookup table, so anyone can tell what a reference does without opening it. Our naming conventions guide has the full system.
  2. Don’t create a variable you can’t point to a tag or trigger using. Orphan variables accumulate like browser tabs, and each one is something the next person has to reverse-engineer.

Variables, triggers, and tags are the whole GTM model: what to send, when to send it, and the live details that make it worth sending. With all three in hand, the tracking recipes become assembly rather than mystery.

Frequently asked questions

What is a variable in Google Tag Manager?
A named value that GTM resolves while the page runs. Instead of hard-coding 'fire on /pricing', you write a condition against the Page Path variable, and instead of typing a button's label into a tag, you pass the Click Text variable. Variables are what make triggers and tags reusable and precise.
Why are my Click variables empty in GTM?
Built-in variables are off by default. Go to Variables > Configure in your workspace and tick the Clicks group (Click Element, Click Classes, Click ID, Click Target, Click Text, Click URL). Until they're enabled, click triggers have nothing to match against, and the variables don't even appear in Preview mode's Variables tab.
What's the difference between built-in and user-defined variables?
Built-in variables are predefined by GTM; you just switch them on: page URL parts, click details, form details, scroll depth, video status. User-defined variables you create yourself for anything beyond that: reading a data layer value, storing a constant, mapping values with a lookup table, or grabbing something from the page.
What is a data layer variable?
A user-defined variable that reads a named value your website pushes into the data layer, like an order total, a form type, or a page category. It's the cleanest way to get information from your site into GTM, because it doesn't depend on how the page looks, only on what the site announces.
How do I use a variable inside a tag?
Type {{ in almost any tag field and GTM shows a picker of available variables. The reference looks like {{Click URL}} or {{DLV - order_value}}, and it resolves to the live value when the tag fires. The same {{name}} syntax works in trigger conditions and even inside other variables.
How can I see what value a variable has?
Preview mode. Connect Tag Assistant to your site, perform the action, click the event in the left-hand timeline, and open the Variables tab. It lists every variable and the exact value it held at that moment, which is where most 'why didn't my trigger fire' mysteries get solved.

Keep learning