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_valuemight resolve to89.00
Variables get used in two places:
- Trigger conditions. “Fire when Click Text contains Subscribe” is a trigger using a variable.
- 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:
| Group | Variables | You’ll need them for |
|---|---|---|
| Pages | Page URL, Page Path, Page Hostname, Referrer | URL-based trigger conditions |
| Clicks | Click Element, Click Classes, Click ID, Click Target, Click Text, Click URL | Any click tracking |
| Forms | Form Element, Form Classes, Form ID, Form Target, Form Text, Form URL | Form submission triggers |
| Scroll | Scroll Depth Threshold and friends | Scroll depth tracking |
| Videos | Video status, percent, title, and friends | YouTube video triggers |
| Utilities | Event, Container ID, Random Number, and friends | Custom 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.
- Enable the Click variables under Variables > Configure.
- Trigger: a Just Links trigger with the condition Click URL contains
/pricing. - Tag: a GA4 event tag named
pricing_link_click, with an event parameterlink_urlset 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:
- Prefix user-defined variables by type, like
DLV - order_valuefor a Data Layer Variable orLT - ga4 id by hostnamefor a lookup table, so anyone can tell what a reference does without opening it. Our naming conventions guide has the full system. - 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.