How to use built-in variables in Google Tag Manager

Author:

Google Tag Manager (GTM) offers several built-in variables that allow you to track various elements on your website. These built-in variables can help you easily capture specific data without needing to configure custom variables. Here’s a guide on using GTM’s built-in variables and making the most of them:

1. Understanding Built-In Variables in GTM

Built-in variables in Google Tag Manager are pre-defined variables that simplify data capture, allowing you to focus on setup and analysis without coding custom solutions. These variables provide insights into user interactions, such as page views, clicks, and other engagement metrics.

Some common built-in variable categories include:

  • Page Variables: Capture details about the web page, like Page URL, Page Path, and Page Hostname.
  • Event Variables: Capture information about events, such as Click Element, Click URL, and Click Text.
  • Utility Variables: Offer utility details, including Container ID and Debug Mode.
  • Form and Video Variables: For tracking form submissions and video interactions.

2. Enabling Built-In Variables

To use any built-in variable, you need to enable it in your GTM workspace:

  1. Go to Google Tag Manager and select your container.
  2. In the left-hand menu, go to Variables.
  3. Under Built-In Variables, click Configure.
  4. A list of built-in variables appears. Check the boxes next to the variables you want to enable. You’ll see categories like Clicks, Forms, Pages, Utilities, and more.

By default, some variables like Page URL and Page Path may already be enabled, while others, such as Click Variables, need to be manually selected.

3. Commonly Used Built-In Variables

Here are some frequently used built-in variables and how they can be used:

  • Page URL: Captures the full URL of the page. Useful for tracking which URLs users are visiting.
  • Page Path: Shows the path component of the URL (e.g., /about-us). Often used in triggers to target specific pages.
  • Page Hostname: Indicates the domain of the page (e.g., example.com). Useful for multi-domain tracking.
  • Click Element: Returns the HTML element a user clicked. Great for detailed click tracking.
  • Click Classes: Shows the CSS classes of the clicked element. You can use this to trigger tags based on specific CSS class names.
  • Click ID: Captures the id attribute of the clicked element. This can be used to track clicks on elements with specific IDs.
  • Click URL: Tracks the URL of a clicked link. Useful for monitoring outbound link clicks or downloads.

4. Using Built-In Variables in Triggers

You can use built-in variables to create specific triggers that activate only under certain conditions. For instance, if you want to trigger a tag only when a user clicks a specific button:

  1. In GTM, go to Triggers and click New.
  2. Choose a trigger type, such as Click – All Elements or Click – Just Links.
  3. Under Trigger Configuration, select Some Clicks to narrow down the conditions.
  4. Choose a built-in variable like Click ID, Click Classes, or Click Text and set it to match the value you’re targeting (e.g., Click ID equals “submit-button”).
  5. Save the trigger and attach it to a tag.

This setup ensures that the tag fires only when the defined button is clicked.

5. Examples of Using Built-In Variables in Tags

Let’s say you want to set up a Google Analytics tag that fires when a specific link is clicked:

  1. Create a Tag: In the Tags section, click New and select a Google Analytics tag type.
  2. Add Event Tracking Parameters: In the tag configuration, use GTM variables to populate the event tracking parameters. For example:
    • Category: {{Click Text}}
    • Action: Click
    • Label: {{Click URL}}
  3. Set the Trigger: Attach a click trigger that utilizes built-in variables such as Click URL or Click Classes.
  4. Save the tag and preview it to ensure it functions as expected.

6. Advanced Uses of Built-In Variables

  • Using Page Referrer: Helps track where users came from before landing on the current page, useful for setting up referral-based triggers.
  • Form Tracking with Form ID or Form Classes: Track form submissions based on form-specific IDs or classes.
  • Video Tracking with YouTube Variables: GTM offers specific variables for tracking interactions with YouTube videos, such as Video Status and Video Percentage, allowing you to track events like play, pause, and percentage of video watched.

7. Testing Built-In Variables with Preview Mode

Always use Preview Mode to test your configurations before publishing changes:

  1. In GTM, click on Preview in the top-right corner to enter debug mode.
  2. Open your website in the debug window.
  3. Interact with the page elements you’re tracking (e.g., click buttons or links) and verify that the variables capture the expected values.
  4. In the debug panel, look at the Variables tab to see the data collected for each variable on different actions, such as page views or clicks.

8. Publishing and Monitoring Performance

Once tested, publish your container changes. Keep track of the data in your analytics tools to make sure that the variables are tracking correctly and that tags are firing as intended. You can review how well your tags and triggers perform in tools like Google Analytics or other integrated platforms.

Using built-in variables in Google Tag Manager can provide immediate access to important data without requiring complex setup. These variables help streamline tracking, enabling you to capture relevant user interactions efficiently. By strategically using built-in variables, you can set up effective triggers and tags, creating a powerful data collection framework for your site.