Articles on: Troubleshooting

Variables

Variables are used in Google Tag Manager to store and reuse information. They help make tracking easier by automatically filling in values instead of entering them manually every time.

This document will explain what variables are and how to use them easily.

Let’s get started 🚀

What are Variables?



Variables in Google Tag Manager are like containers that store information. When the code runs on your website, these variables are filled with values. For example, the "Page URL" variable gives the URL of the page the user is currently on.

Variables are used in both triggers and tags:

In triggers, variables help set conditions for when a tag should run. For example, you might use a variable to check if a specific page is viewed before firing the tag.

In tags, variables are used to capture changing values, like the total transaction amount or product ID, and pass them to tracking tools like Google Analytics.

Google Tag Manager provides built-in variables for common tasks, such as getting the page URL or click information. These built-in variables can be used right away for most setups. If you need something more specific, you can create your own user-defined variables to track custom information that isn’t covered by the built-in ones.

How to Create a Variable



By creating a variable in Google Tag Manager, you can store and reuse data like event details or user information. This makes managing tags and triggers easier and more efficient.

In this demonstration, we will show you how to create a variable.



Event Data from data layer



With a Data Layer Checker plugin, you can see the data stored on your site and find the keys to access it. For example, to get the client_id of a session, locate the key in a tool like the Data Layer Checker plugin, as shown in the screenshot, and use it as the Key Path.

The data layer stores important event data that can be used for tracking user actions on a website. It helps collect and pass information.This helps track data correctly and keep it organized.

For more information on how to retrieve key value from data layer you can refer is document for Retrieving DataLayer Values.



If you want to learn about user-defined variables and what they can measure, you can read more in this article from Google.

Updated on: 04/02/2025

Was this article helpful?

Share your feedback

Cancel

Thank you!