Google Tag Manager

⌘K
  1. Home
  2. Google Tag Manager
  3. Set Up & Basics
  4. Overview of Built-in and User-Defined Variables in Google Tag Manager

Overview of Built-in and User-Defined Variables in Google Tag Manager

Part 1: Built-in Variables

What are Built-in Variables?

Built-in Variables are pre-configured variables provided by Google Tag Manager. You must enable them before using them in Tags or Triggers.

Built-in Variable Groups:

GroupCommon VariablesDescription / Use Case
Page VariablesPage URL, Page Hostname, Page Path, ReferrerTrack the current or previous page details
Click VariablesClick ID, Click Classes, Click Text, Click URL, Click ElementCapture what was clicked (buttons, links, etc.)
Form VariablesForm ID, Form Classes, Form Target, Form URL, Form ElementTrigger tags based on form submissions
Scroll VariablesScroll Depth Threshold, Scroll DirectionTrack how far users scroll down a page
Video VariablesVideo Provider, Video Status, Video URL, Video Title, Video Percent, Video Duration, Video Current TimeUsed when tracking YouTube video engagement
Error VariablesError Message, Error URL, Error Line, Error Stack TraceCapture JavaScript errors on your website
Visibility VariablesPercent Visible, Visible Element, Visible Classes, Visible IDTrigger tags when specific elements become visible
History VariablesNew History Fragment, Old History Fragment, New History State, Old History State, History SourceUsed in Single Page Applications (SPA) to track URL changes
UtilitiesEvent, Container ID, Container Version, Debug Mode, Random Number, Timestamp, Environment NameHelpful for debugging, environment tracking, or randomization

 How to Enable Built-in Variables:

  1. Go to Variables in GTM.
  2. Click “Configure” (top right).
  3. Check the boxes for the variables you want to use.

Part 2: User-Defined Variables

What are User-Defined Variables?

User-Defined Variables are variables that you manually create in GTM to extract or transform data for use in tags, triggers, and conditions.

User-Defined Variable Types:

TypeDescriptionExample Use Case
ConstantFixed value you can reuse across GTMGA4 Measurement ID, Site Name
Data Layer VariablePulls data from dataLayer pushed by your websiteOrder value, user ID, product name
Auto-Event VariableRetrieves properties of automatically tracked events (clicks, forms, etc.)Capture clicked element’s ID or class
URL VariableExtracts parts of the current page URL (hostname, path, query string)Pull UTM parameters or page path
First Party CookieReads a value stored in a browser cookieCapture a session ID or language preference
JavaScript VariableAccesses JavaScript values directly from the website’s global objectsGet window.location.pathname or other JS-based values
DOM ElementGets content from an HTML element using CSS selectorsCapture <h1> title text or product name on the page
Lookup TableMaps one value to another (simple value replacement)Translate plan IDs to human-readable names
Regex TableSimilar to Lookup Table but uses regular expressions for complex matchingMap multiple URL structures to one standard value
Custom JavaScriptLets you write your own JavaScript function that returns a valueCalculate values dynamically, combine logic, or return booleans

How to Create a User-Defined Variable:

  1. Go to Variables in GTM.
  2. Click “New” under User-Defined Variables.
  3. Choose the variable type.
  4. Configure it as needed.
  5. Name your variable clearly and click Save.

Note: 

  • Use Preview mode to see the actual value of variables when testing.
  • Label your variables clearly (e.g., DLV – Order Value or JS – Pathname) for easier management.
  • Combine Lookup Tables and Variables to organize complex tracking logic.

How can we help?