What Are GTM Variables? Understanding GTM Variables

In Google Tag Manager (GTM), variables are the third key pillar, after Tags and Triggers.

If Tags are the heart, and Triggers are the brain, then Variables are the memory.

They store and provide information to tags and triggers dynamically, allowing marketers to implement scalable and accurate tracking.

1. What Is a Variable in GTM?

A variable is a named container that stores a value.
 The value can be used by:

  • Tags → to send dynamic information

  • Triggers → to check conditions

  • DataLayer → to feed custom events

Examples of variables:

Variable NameDescription
Page URLURL of the page being viewed
Click TextText of the button or link clicked
Form IDIdentifier of the form submitted
Transaction ValueRevenue of a purchase
Product NameName of the product added to cart

2. Why Variables Are Important

Without variables:

  • Each tag must be hard-coded

  • Each trigger must be unique

  • Scaling campaigns becomes difficult

  • Tracking becomes static and error-prone

With variables:

  • One tag can track multiple pages, buttons, or forms

  • One trigger can work with multiple conditions

  • Tracking becomes flexible and reusable

  • Advanced conversion tracking and server-side tagging is possible

3. Types of GTM Variables

A. Built-In Variables

GTM provides many pre-configured variables:

  • Page Variables: Page URL, Page Path, Page Hostname

  • Click Variables: Click ID, Click Classes, Click Text

  • Form Variables: Form ID, Form Classes, Form Target

  • Event Variables: Event, Event Category, Event Action

Tip: Enable all built-in variables when starting; they cover most basic tracking needs.

B. User-Defined Variables

These are variables you create manually to store specific values.

Examples:

  • Google Analytics Event Value

  • Transaction ID for eCommerce

  • Customer type

  • Button ID

  • Product category

User-defined variables make your tags highly dynamic.

C. DataLayer Variables

DataLayer variables pull values from the website’s DataLayer.

Example:

dataLayer.push({

  event: “purchase_complete”,

  transaction_id: “TX12345”,

  value: 199

});

  • Variable: transaction_id → pulls TX12345

  • Variable: value → pulls 199

Use Case: Essential for server-side tagging, enhanced conversions, and accurate eCommerce tracking.

4. How Variables Work With Tags & Triggers

  • Triggers use variables to check conditions:
     Example: Only fire form submission tag if Form ID = contact_form

  • Tags use variables to send dynamic data:
     Example: GA4 purchase event → uses Transaction ID & Value variables

Variables act as the link between triggers and tags, ensuring your tracking works dynamically across pages, forms, buttons, and user actions.

5. Real-World Examples

Example 1 — Lead Form Tracking

  • Tag: Google Ads Lead Conversion

  • Trigger: Form Submission

  • Variable: Form ID → ensures only the specific form fires the tag

Example 2 — Purchase Tracking

  • Tag: GA4 Purchase Event

  • Trigger: Custom DataLayer Event: purchase_complete

  • Variables: Transaction ID, Purchase Value, Product Name

Example 3 — Button Click

  • Tag: Meta Pixel Button Click

  • Trigger: Click

  • Variable: Click Text → allows multiple buttons to use one tag

6. Best Practices for Variables

  1. Start with all built-in variables enabled

  2. Create user-defined variables for all dynamic data

  3. Always use DataLayer variables for advanced tracking

  4. Name variables logically for easy management

  • Test variables in Preview Mode before publishing

7. Summary

  • Variables store dynamic values

  • They connect triggers and tags

  • Enable flexible, scalable, and accurate tracking

  • Types: Built-in, User-defined, DataLayer

  • Essential for modern marketing analytics

Next lesson, you will build your first complete tag with trigger and variable in GTM, combining everything from Modules 1–8.

Get A Free Audit :

Request a Quote

Book Your Free Tracking Audit!

Request a Quote