GTM Variables: Reading Data from the Data Layer | Adslytics | Adslytics

GTM Data Layer How-To Guide

GTM Variables: Reading Data from the Data Layer

By Muhammad Farooq · March 20, 2026 · 5 min read
GTM Variables: Reading Data from the Data Layer

What GTM Data Layer Variables Are

In GTM, a Data Layer Variable is a variable type that reads a specific key from the data layer. When a tag needs to include a value that came from a dataLayer.push (like an order ID or transaction value), you configure a Data Layer Variable pointing to that key, then reference the variable in the tag.

Creating a Data Layer Variable

  1. GTM → Variables → User-Defined Variables → New
  2. Variable Type: Data Layer Variable
  3. Data Layer Variable Name: the key path you want to read
  4. Data Layer Version: Version 2 (almost always)
  5. Name it descriptively: DL - Transaction ID, DL - Ecommerce Value

Reading Top-Level Keys

For a push like:

dataLayer.push({
  'event': 'purchase',
  'transactionId': 'T12345',
  'transactionValue': 59.99
});

Data Layer Variable Name: transactionId → reads 'T12345'

Data Layer Variable Name: transactionValue → reads 59.99

Reading Nested Keys (Dot Notation)

For nested objects:

dataLayer.push({
  'event': 'purchase',
  'ecommerce': {
    'transaction_id': 'T12345',
    'value': 59.99,
    'items': [{'item_id': 'SKU-001'}]
  }
});

Data Layer Variable Name: ecommerce.transaction_id → reads 'T12345'

Data Layer Variable Name: ecommerce.value → reads 59.99

Data Layer Variable Name: ecommerce.items.0.item_id → reads the first item's ID

Default Values

Set a Default Value for the variable to return when the key is not present in the data layer — useful when the variable is used in trigger conditions (prevents undefined from causing errors):

  • For string variables: default '' (empty string)
  • For numeric variables: default 0
  • For boolean variables: default false

Using Variables in Tags

In GA4 Event tags, reference data layer variables using double curly-brace syntax:

  • Event Parameters → Add Parameter → Name: transaction_id, Value: {{DL - Transaction ID}}
  • Event Parameters → Add Parameter → Name: value, Value: {{DL - Ecommerce Value}}

Variables in Trigger Conditions

Data Layer Variables can also be used in trigger conditions to restrict when a trigger fires. Example: only fire a purchase tag when the transaction value is above £50:

  • Trigger: Custom Event "purchase"
  • Fire this trigger when: DL - Ecommerce Value greater than 50

Summary

Data Layer Variables in GTM read specific keys from the data layer using the key name (top-level) or dot notation (nested). Configure them with descriptive names (prefix DL -) and set default values. Reference them in tag parameters with double curly braces. Data Layer Version 2 is the standard — Version 1 behaves differently and should not be used in new implementations.

See our GTM Data Layer Implementation service for variable configuration.

Need GTM data layer variables set up? Contact Adslytics.

Need expert tracking setup?

Our Google Tag Manager experts have delivered 500+ tracking setups with a 98% success rate.

Get a Free Consultation →
← Back to Blog
Muhammad Farooq

Author

Muhammad Farooq GTM & Analytics Expert · Adslytics Founder

Tracking specialist with 10+ years of experience in Google Tag Manager, GA4, Server-Side Tracking, and Google Ads. Founder of Adslytics — a dedicated analytics agency with a 98% success rate across 232+ projects on Upwork.

Top Rated Plus LinkedIn Visit the author's profile →