About Variables in Google Tag Manager - by Aman Singh - CollectLo

About Variables in Google Tag Manager

Aman Singh - CollectLo

Aman Singh

Content Writer . Hire Me

1 min read . Feb 02

Clap
Save

Understanding Variables in Google Tag Manager

Variables in Google Tag Manager act as placeholders that store values when your website or app runs. For example, the "Page URL" variable holds the current web page’s URL.

 - by Aman Singh - CollectLo

How Variables Are Used:

  1. In Triggers:Variables help decide when a tag should fire.Example: A trigger can fire when the URL contains "example.com/index.html".
  2. In Tags:Variables capture and send dynamic data.Example: A tag can use a variable to pass a transaction value and product ID for conversion tracking.

Google Tag Manager includes many built-in variables to cover common needs. If these don’t meet your requirements, you can create custom variables for more flexibility.

 - by Aman Singh - CollectLo

Built-in Variables in Google Tag Manager (Web Containers)

Google Tag Manager provides built-in variables to automatically track user actions on your website. These help with tracking clicks, errors, page details, scrolling, videos, and more.

1. Click Tracking Variables (Tracks what users click)

  • Click Element – The specific item a user clicked.
  • Click Classes – The class name of the clicked item (helps identify groups of elements).
  • Click ID – The unique ID of the clicked item.
  • Click Target – The destination of the clicked item (e.g., where a link leads).
  • Click URL – The full web address of the clicked link.
  • Click Text – The visible text of the clicked item (e.g., button text like "Buy Now").
 - by Aman Singh - CollectLo

2. Error Tracking Variables (Tracks website errors)

  • Error Message – The description of an error when something goes wrong.
  • Error URL – The web page where the error happened.
  • Error Line – The specific line of code where the error occurred.
  • Debug Mode – Tells if the site is in testing mode (Preview Mode).
 - by Aman Singh - CollectLo

3. Form Tracking Variables (Tracks form submissions)

  • Form Element – The exact form a user interacted with.
  • Form Classes – The class name of the form (helps track specific forms).
  • Form ID – The unique ID of the form.
  • Form Target – The destination URL where the form submits data.
  • Form Text – The visible text inside the form (e.g., button text like "Submit").
  • Form URL – The web address linked to the form.
 - by Aman Singh - CollectLo

4. Page Tracking Variables (Tracks page details)

  • Page Hostname – The website’s main address (e.g., "example.com").
  • Page Path – The part of the URL after the domain (e.g., "/contact").
  • Page URL – The full web address of the page.
  • Referrer – The previous page the user came from.
 - by Aman Singh - CollectLo

5. Scroll Tracking Variables (Tracks how far users scroll)

  • Scroll Depth Threshold – How much the user scrolled (e.g., 50% or 100%).
  • Scroll Depth Units – Whether the scroll was measured in pixels or percentage.
  • Scroll Direction – Whether the user scrolled up/down or left/right.
 - by Aman Singh - CollectLo

6. Video Tracking Variables (Tracks user interactions with videos)

  • Video Current Time – The time (in seconds) where the user is in the video.
  • Video Duration – The total length of the video in seconds.
  • Video Percent – How much of the video was watched (e.g., 50%, 75%).
  • Video Provider – The platform where the video is hosted (e.g., YouTube).
  • Video Status – The action taken on the video (e.g., play, pause).
  • Video Title – The name of the video.
  • Video URL – The full link to the video.
  • Video Visible – Whether the video is on the user’s screen or hidden.
 - by Aman Singh - CollectLo

7. Visibility Tracking Variables (Tracks if elements are visible on screen)

  • Percent Visible – How much of an element is visible on the screen (e.g., 50%, 100%).
  • On-Screen Duration – How long (in milliseconds) an element has been visible.
 - by Aman Singh - CollectLo

8. History Tracking Variables (Tracks page navigation history)

  • New History Fragment – The new URL fragment (hash) after a user navigates.
  • Old History Fragment – The previous URL fragment before navigation.
  • New History State – The latest page state after navigation.
  • Old History State – The previous page state before navigation.
 - by Aman Singh - CollectLo

9. Utility Variables (General useful data)

  • Container ID – The unique ID of your Google Tag Manager setup.
  • Container Version – The version number of your current Tag Manager setup.
  • Environment Name – Shows if the website is live or in testing mode.
  • Event – The current event happening on the website (e.g., page load, form submission).
  • Random Number – A randomly generated number (useful for tracking unique events).
 - by Aman Singh - CollectLo

These built-in variables help track user actions and improve website analytics. Let me know if you’d like me to simplify anything further! 😊

Custom User-Defined Variables in Google Tag Manager

If built-in variables don’t meet your needs, you can create custom user-defined variables in Google Tag Manager.

 - by Aman Singh - CollectLo

Tag Manager supports these user-defined variable types for web

 - by Aman Singh - CollectLo

Learn more about Trigger in Google Tag Manager here