# Map data-layer values with GTM variables Create Data Layer Variables for the exact event keys GTM receives, then prove each value resolves in Preview before a tag uses it. - Canonical: https://satracking.net/guides/gtm-data-layer-variables/ - Language: en - Category: platforms - Level: intermediate - Published: 2026-11-10 - Updated: 2026-11-10 --- ## Audience and prerequisites Create Data Layer Variables for the exact event keys GTM receives, then prove each value resolves in Preview before a tag uses it. You need the actual data-layer key names, a web container, and a test page that can emit one known event. Skill level: intermediate. Reading time: seven minutes. ## 1. Inspect the event payload before creating variables Connect GTM Preview and trigger the application action. In Tag Assistant, select the event and inspect the data layer values. Record the exact key names, nesting, types, and when they become available. A variable path must reflect the payload that is really pushed; guessing from a developer's field label often creates an empty value. ## 2. Create a Data Layer Variable for each needed field In the GTM container, create a **Data Layer Variable** and enter the key path from the observed payload, such as `form_id`. For nested objects, use the path supported by the data-layer structure and the selected variable version. Give the GTM variable a clear name, then test its value on the event that should use it. Do not create variables for every field by default. ### Generic data-layer example The application may emit a controlled value after successful submission: ```js window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: 'generate_lead', form_id: 'contact_sales' }); ``` This is a generic message to the shared queue. It is not a GA4 API call or another vendor's event. Keep the existing `dataLayer`; don't overwrite it after GTM loads. ## 3. Use the variable in a configured tag For GA4, add the intended event parameter to a GA4 Event tag and select the Data Layer Variable as its value. For a different destination, map only fields supported by that tag and provider. Variables read values; they do not send events. A tag and matching trigger are still required. ## 4. Check expected and failing cases in Preview Repeat the action and confirm the variable resolves to the expected value on the correct event. Also test a failure, a page where the key is absent, and a repeat action. If the value is undefined, check exact spelling/case, nesting, push timing, and whether code recreated a separate data layer. If it is stale, inspect whether a later event updated the key and whether the tag fired on the intended message. Publish only after the positive and negative cases pass. A Preview value proves the variable resolved in that test session; it does not prove a destination received or processed it. ## Privacy and data minimization Only expose fields that have an approved measurement purpose. Never map emails, names, phone numbers, credentials, or free-text form content into tags. Keep consent requirements on each destination tag and check the relevant state during Preview. ## Related work For a matching Custom Event trigger, see [Connect a data-layer event to a GTM trigger](/guides/send-data-layer-event-to-ga4-via-gtm/). For the GA4 tag that uses mapped values, continue with [Send a data-layer event to GA4 through GTM](/guides/send-data-layer-event-to-ga4-via-gtm/). ## Official references - The data layer — https://developers.google.com/tag-platform/tag-manager/datalayer (verified 2026-11-10) - Set up event parameters — https://developers.google.com/analytics/devguides/collection/ga4/event-parameters (verified 2026-11-10) - Preview and debug containers — https://support.google.com/tagmanager/answer/6107056?hl=en (verified 2026-11-10)