Understanding GTM Variables: Types, Uses, and Best Practices

Google Tag Manager (GTM) variables help track user interactions and pass important data to analytics tools. This guide explains what GTM variables are, their types (built-in and user-defined), how to use them, and best practices for accurate tracking. Learn how to enable, debug, and optimize GTM variables to improve your website’s analytics and marketing performance. 🚀

3/13/20254 min read

Understanding GTM Variables: Types, Uses, and Best Practices

Introduction

Google Tag Manager (GTM) is a powerful tool for tracking user interactions on a website. One of its key features is variables, which help make your tracking more dynamic and accurate.

But what exactly are GTM variables, and how do they work?

In this guide, we will explain what GTM variables are, their types, how to use them, and best practices in simple terms—like explaining to a 10-year-old.

What Are GTM Variables?

A variable in Google Tag Manager is like a box that stores information. This information can be used in tags, triggers, and other GTM settings.

Example: Variables Are Like a School Notebook

Imagine you are in a classroom, and the teacher asks for your name and age. Instead of memorizing everything, you write it down in a notebook.

Similarly, GTM stores important data in variables and uses it when needed.

Why Are Variables Important in GTM?

Without variables, GTM would not know who clicked a button, what page a user visited, or what product was purchased.

Variables help:

✅ Make tracking dynamic (e.g., track any button click instead of just one specific button).
✅ Pass important data to Google Analytics, Facebook Pixel, or other tracking tools.
✅ Ensure accuracy in tracking events, conversions, and user behavior.

Types of GTM Variables

Google Tag Manager has two main types of variables:

  1. Built-in variables (predefined by GTM)

  2. User-defined variables (custom variables you create)

Let’s explore each type in detail.

1. Built-in Variables in GTM

Built-in variables are pre-made by Google and can be enabled in GTM. They help track common website actions.

How to Enable Built-in Variables

  1. Open Google Tag Manager.

  2. Click on "Variables" in the left menu.

  3. Scroll to "Built-in Variables" and click "Configure".

  4. Select the variables you want to use.

Common Built-in Variables

1.Page Variables

These variables collect information about the page the user is visiting.

  • Page URL – Stores the full website URL.

  • Page Path – Stores the part of the URL after the domain (e.g., "/about-us").

  • Page Hostname – Stores the website domain (e.g., "example.com").

Example: Tracking a Blog Page View

Imagine you want to track how many people read a blog post.

  • You can use the Page Path variable to check if the user is on a page like "/blog/gtm-guide".

This data can be sent to Google Analytics to measure blog performance.

2.Click Variables

These variables track user clicks on a website.

  • Click URL – Stores the URL of the clicked link.

  • Click Text – Stores the text of the clicked button or link.

  • Click Element – Stores the HTML element clicked by the user.

Example: Tracking Button Clicks

Imagine you have a "Sign Up" button on your website.

  • You can use Click Text to track if a user clicked the "Sign Up" button.

  • This data helps understand how many users interact with the button.

3.Form Variables

These variables help track form submissions.

  • Form ID – Stores the unique ID of the submitted form.

  • Form Classes – Stores the class names of the form.

  • Form Target – Stores the form’s action URL.

Example: Tracking Contact Form Submissions

If you have a contact form, you can track how many users submit it using the Form ID variable.

4. User-Defined Variables in GTM

User-defined variables are custom variables you create based on your website’s needs.

Common Types of User-Defined Variables

1. Constant Variable

A constant variable stores a fixed value.

Example: Setting a Google Analytics ID

If you use Google Analytics, you need to enter your Measurement ID in multiple tags. Instead of typing it every time, you can create a constant variable for it.

2. Lookup Table Variable

A lookup table works like a translator. It takes an input and returns an output.

Example: Setting Different Tracking IDs for Different Domains

Imagine you have two websites, and each has a different Google Analytics ID.

  • If Page Hostname = site1.com, return GA-ID-1234.

  • If Page Hostname = site2.com, return GA-ID-5678.

This ensures the correct Google Analytics ID is used for each website.

3. JavaScript Variable

This variable pulls data from JavaScript on your website.

Example: Tracking Logged-in Users

If your website has a login system, a JavaScript variable can check if the user is logged in or not.

4. Data Layer Variable

A Data Layer Variable pulls information from the GTM Data Layer.

Example: Tracking E-commerce Purchases

If a user buys a product, the Data Layer may store:

{ "transactionTotal": 50.99, "productName": "Wireless Headphones" }

You can create a Data Layer Variable to store the transaction total and send it to Google Analytics.

Best Practices for Using GTM Variables

  1. Enable only the needed built-in variables to avoid clutter.

  2. Use clear names for user-defined variables (e.g., "GA Measurement ID" instead of "Variable1").

  3. Use constant variables for values that don’t change (e.g., Google Analytics ID).

  4. Use lookup tables to manage different tracking settings for multiple sites.

  5. Test variables in GTM Preview Mode before publishing.

How to Debug GTM Variables

To check if a variable is working correctly, use Preview Mode:

  1. Open Google Tag Manager.

  2. Click "Preview".

  3. Perform an action on your website (e.g., click a button).

  4. Check the Variables tab in the Debug Panel.

If a variable is empty or incorrect, you may need to adjust your GTM setup.

Final Thoughts

Variables in Google Tag Manager help collect and pass data for tracking user behavior.

  • Built-in variables handle common actions like page views and clicks.

  • User-defined variables give more flexibility for custom tracking.

  • Best practices ensure your setup remains organized and efficient.

By understanding and using GTM variables correctly, you can improve your website tracking, optimize marketing campaigns, and gain valuable insights.

Would you like a guide on setting up specific GTM variables for your business?

Get in touch with us:

Email: connect@ecommidea.com

WhatsApp: wa.me/919839618999