Skip to content

Guide 104 · Container · GA4 + Tag Manager

Create a data layer variable: read a value the site pushed to the data layer

Checked 11 November 2026 · Verification: container fragment validated structurally (15 checks, all passed) · Steps traced to Tag Manager Help, opened 11 November 2026 · 5-minute read

Most values worth measuring never appear in the page text: the order total, the plan name, the transaction ID. The site pushes them into the data layer, and a data layer variable is the way Tag Manager reads one back out. Google's variable page says the value is set when data is pushed to the data layer with a dataLayer.push() call, and that you name the key the variable should read. The worked example reads an order total from an ecommerce push: two items, 19.99 × 2 and 7.50 × 4, recomputed below.

Expected signal

After step 4, Preview mode shows the variable in the Variables tab of the debug view with the pushed value — 69.98 for the worked order — instead of undefined. A tag that references {{DLV - ecommerce.value}} sends that number.

Download the container fragment: the data layer variable fragment (JSON) (export format version 2, 1766 bytes, MD5 42c34c8fd651d0ae72d8afa29b7324e5). It holds the DLV - ecommerce.value variable and a GA4 purchase event tag that reads it, so the reference resolves inside the file. The file is a hand-built import template, validated structurally — it was not exported from a live container.

What you need

  • A data layer push on the site. The site must push the key before the variable can read it — dataLayer.push({"ecommerce": {"value": 69.98}}) for the worked example. No push, no value.
  • The exact key name. The variable reads the key letter for letter. A key called ecommerce.value is not the same as ecommerce_value.
  • Edit access to the container. Creating a variable is a container edit.

The trace

  1. Confirm the push exists on the page. Open the site, open the browser console, and type dataLayer. The push for the worked order lists two items: 19.99 × 2 = 39.98 and 7.50 × 4 = 30.00. The order value is 39.98 + 30.00 = 69.98. If the console shows no data layer, the site is not pushing and the variable has nothing to read.
  2. Go to Variables and click New under User-Defined Variables. The Variables page has two sections; user-defined variables are the lower one. Click New there, not under Built-In Variables.
  3. Click Variable Configuration and choose Data Layer Variable. Tag Manager lists the user-defined types; Data Layer Variable is under Page variables. Pick it and the configuration shows two fields: the key name and the data layer version.
  4. Enter the key as ecommerce.value and leave Data Layer Version at 2. Version 2 is the default and the right one here: it reads dots as nested values, so ecommerce.value means the value key inside the ecommerce object. Version 1 would treat the whole dotted string as one flat key name and find nothing.
  5. Name the variable after its function and click Save. Call it DLV - ecommerce.value, following Google's own naming example of Data Layer Variable - Product Name. The name is what tags and triggers reference as {{DLV - ecommerce.value}}.

Dead ends

DEAD END — VERSION 1 DOTS DO NOT NEST. With Data Layer Version 1, dots in a key name are literal: the variable looks for a single key called ecommerce.value. The site pushed a nested object, so the variable returns undefined. Version 2 is the default for a reason — it reads the dots as nesting.

DEAD END — NAMING THE VARIABLE AFTER THE TAG THAT USES IT. A variable called Purchase tag value is useless the day a second tag needs the same number. Name it after the data it reads — DLV - ecommerce.value — and every tag that needs the order total can reference the same variable.

DEAD END — PUSHING AFTER THE TAG FIRES. A data layer variable reads the value at the moment the tag fires. If the site pushes the order total after the purchase tag has already fired, the tag sends undefined. The push has to happen before the event that fires the tag.

End state

One data layer variable, DLV - ecommerce.value, returning 69.98 for the worked order. Any tag that needs the order total references it instead of hard-coding a number, and if the site changes how it pushes the value, one variable edit fixes every tag.

Sources

Checked 11 November 2026. The click paths above are the ones in Google's help pages, opened 11 November 2026. No step in this guide was run inside a live Analytics property or a live Tag Manager container, because both need a Google sign-in and this site does not sign in as anyone. The container file was validated structurally instead: export format version 2, every tag's firing trigger resolves, every variable the tags reference exists in the file, and the tag types are the documented ones. Google moves menu items without warning; if a path on this page no longer matches, the linked help page is the current map. The container fragment for this guide is 1766 bytes (1.72 KB, 0.86% of the reported 200 KB container size limit), MD5 42c34c8fd651d0ae72d8afa29b7324e5, and passed 15 structural checks.