Creating and Managing Variables

Complete guide to creating and managing variables in the Ours Privacy Tag Manager for dynamic and reusable tag configurations.

Creating and Managing Variables

Variables capture dynamic data from your website, making your tags and triggers more flexible and reusable. Instead of hardcoding values, variables adapt to the context—whether that's the current URL, a button's text, or data from your application.

Variables fall into two categories: pre-built variables that are always available, and customizable variables that you configure for specific needs.

Pre-built Variables

Pre-built variables are built-in and automatically available in every workspace. They capture common static values without any configuration:

  • Current URL: The full URL of the current page
  • Page Title: The title of the current page
  • Referrer: The URL of the page that linked to the current page
  • Timestamp: The current time when the variable is evaluated

These variables are ready to use immediately—just reference them in your tags or triggers.

Customizable Variables

Customizable variables let you create variables for specific data you need to capture. Configure how and where to get the data, then reuse the variable across multiple tags and triggers.

The following types are available (this is a non-exhaustive list):

Click Variables

Variables that capture data from user clicks:

  • Click Data Attribute: Retrieves data attributes (e.g., data-product-id) from the element that was clicked.
  • Click HTML Attribute: Retrieves HTML attributes (e.g., href, class, id) from the element that was clicked.

Page Variables

Variables that capture information about the current page:

  • URL Component: Retrieves specific parts of the current URL, such as the hostname, pathname, or full URL.
  • URL Parameter: Retrieves values from URL query parameters (e.g., utm_source, campaign_id).
  • Referrer URL: Retrieves parts of the referrer URL to understand where users came from.
  • Meta Tag Content: Retrieves content from meta tags in the page's <head> section.

Data Variables

Variables that capture data from various sources:

  • Constant: Returns a predefined constant value that you set during configuration.
  • Cookie: Retrieves the value of a specific cookie from the browser.
  • Data Layer: Retrieves values from the dataLayer object, enabling integration with your application's data.
  • DOM Element: Retrieves values from DOM elements, such as input field values or element text content.

Advanced Variables

Specialized variables for advanced use cases:

  • Custom JavaScript: Executes custom JavaScript code and returns the result, giving you full flexibility.
  • Time Since Page Load: Returns the time elapsed (in milliseconds) since the page finished loading.
  • eTracker Configuration: A configuration variable specifically for eTracker integration.

Using Variables

Variables make your tracking dynamic and context-aware. Use them in three main ways:

  1. In trigger conditions: Fire triggers based on variable values (e.g., "fire when URL contains /checkout")
  2. In tag configurations: Pass variable values to tags (e.g., send the button text as an event property)
  3. In event properties: Capture contextual data with events (e.g., track which page the user came from)

Variables eliminate the need for hardcoding values and make your tag management setup adaptable to different contexts.

Common Use Cases

Here are some practical examples of how variables enhance your tracking:

  • Track which button was clicked: Use a Click HTML Attribute variable to capture the button's id or class attribute
  • Send UTM parameters as event properties: Use a URL Parameter variable to capture campaign tracking parameters
  • Conditionally fire tags based on URL: Use a URL Component variable in trigger conditions to fire tags only on specific pages
  • Capture form field values: Use a DOM Element variable to retrieve input values when forms are submitted
  • Track time on page: Use a Time Since Page Load variable to measure how long users spend before taking action

Next Steps

Now that you understand variables, explore how to use them in practice:

How is this guide?

On this page

Creating and Managing Variables - Ours Privacy