Skip to content
FunnelGuard

Fix guide by FunnelsGuard

GTM variables returning undefined after a dataLayer key rename

TRK-113High impactPartlyBy FunnelGuardPublished Updated
On this page

What this issue is

Google Tag Manager (GTM) reads values from the dataLayer, a JavaScript array on your page where the site pushes data such as transaction_id or value. A Data Layer Variable in GTM looks up one key by name. If the site now pushes order_total but the variable still looks for orderValue, GTM finds nothing and the variable returns undefined.

Before and after a key renamejavascript
// Old push, the GTM variable reads "orderValue"
dataLayer.push({ event: 'purchase', orderValue: 89.00 });

// After the rename, the variable still reads "orderValue" and gets undefined
dataLayer.push({ event: 'purchase', order_total: 89.00 });

Why it costs you leads or sales

Ad platforms learn from the values you send. If conversion value, transaction ID or product data goes missing, reports show conversions with zero revenue, duplicate orders or no match to the right campaign. Smart bidding then optimises on poor data. Because the tag still fires, nobody sees an error.

Where the value gets lost
  1. Site pushes dataKey renamed to order_total
  2. GTM variable lookupStill reads orderValue, returns undefined
  3. Tag sends hitValue field empty
  4. Ad platform reportingRevenue missing or zero

The site renames the key, so everything after the variable lookup carries an empty value.

Reported conversion value before and after the renameExample numbers
Reported conversion value before and after the rename (example)Before rename: 1,200 $ per day; After rename: 0 $ per day04609201,2000Before renameAfter rename$ per day

Example: the same real sales, but reported value drops to zero once the variable returns undefined.

How to check if your site has it

Find undefined variables
  1. Open GTM PreviewGoogle Tag Manager

    In your container click Preview, enter your site URL and complete the action, such as a test purchase or form submit.

  2. Select the event in the Tag Assistant timelineGoogle Tag Manager

    Click the event (for example purchase) in the left column, then open the Variables tab.

  3. Look for undefined valuesGoogle Tag Manager

    Any Data Layer Variable showing undefined is a candidate. Compare its name with the Data Layer tab for the same event.

  4. Check the page directlyCustom code

    In the browser console type dataLayer and expand the entries to see the keys the site really pushes.

List all keys pushed so far (browser console)javascript
dataLayer.forEach(function (e, i) { console.log(i, Object.keys(e)); });

How to fix it

Decide which side is right. Usually it is simpler to update the GTM variable to the new key. If many tools depend on the old name, ask the developer to push the old key as well.

Fix by platform
  1. Open the variable

    Go to Variables, open the Data Layer Variable that returns undefined.

  2. Update the name

    Set Data Layer Variable Name to the new key exactly, for example order_total or ecommerce.value.

  3. Optionally set a default

    Tick Set Default Value only for harmless fallbacks. Avoid defaults like 0 for revenue, as they hide breakage.

  4. Test and publish

    Check in Preview, then Submit and Publish the workspace.

Push both keys during a transitionjavascript
dataLayer.push({
  event: 'purchase',
  order_total: 89.00,
  orderValue: 89.00 // legacy key, remove once GTM is updated
});
Variable setup

Broken

  • Variable reads orderValue
  • Site pushes order_total
  • Variable shows undefined in Preview
  • Tag sends empty value

Fixed

  • Variable reads order_total
  • Site pushes order_total
  • Preview shows 89
  • Tag sends the real value

How to confirm it's fixed

Confirmation checks
  • In GTM Preview the variable shows a real value on the event, not undefined
  • The tag's fired details show the value, ID and currency populated
  • In GA4 DebugView the event parameters carry the value
  • The browser Network tab shows the hit with the value parameter filled
  • A real or test conversion appears in the ad platform with the right value after processing time

How to prevent it happening again

Prevention
  • Keep a written dataLayer spec listing keys, types and example values
  • Make developers check the spec before renaming keys
  • Review GTM Preview after every theme, plugin or checkout change
  • Use GTM version notes so changes are traceable
  • Avoid default values that hide missing data
  • Run a scheduled test of key journeys so a change is caught within a day

How FunnelGuard handles this

FunnelGuard detects this only partly. A robot visitor runs your real journeys on a schedule and checks the tracking hits sent to platforms such as GA4, Google Ads and Meta. Its params rules catch empty values, so if a variable returns undefined and a hit goes out with a blank value or ID parameter, that can be flagged, with a screenshot and a likely cause.

Questions people ask

Why is my GTM variable showing undefined?

The Data Layer Variable is looking for a key that is not in the dataLayer at that moment. Common causes are a renamed key, a typo or different case, a wrong nested path, or the variable being read before the push happens. Compare the variable name with the Data Layer tab in GTM Preview.

How do I fix a Data Layer Variable returning undefined?

Open the variable in GTM and set the Data Layer Variable Name to the exact key the site pushes now. Test in Preview, then publish. If the site should keep the old name, ask your developer to restore it.

Why is my GA4 purchase value empty or zero?

Often the variable feeding the value parameter returns undefined because the dataLayer key changed. Check the purchase event in GTM Preview and see whether the value variable has a real number.

Can a plugin or theme update rename dataLayer keys?

Yes. Plugins and themes that push data to the dataLayer can change key names in an update. After updates, compare the dataLayer in the browser console with what your GTM variables expect.

Should I set a default value for a Data Layer Variable?

Only for harmless cases. A default such as 0 for revenue hides the problem, because reports look populated but are wrong. Leaving it undefined makes breakage visible in Preview.

How do I see what is in my dataLayer?

Type dataLayer in the browser console and expand the entries, or open the Data Layer tab for an event in GTM Preview. Both show the real key names and values.

Can FunnelGuard detect undefined GTM variables?

Partly. Its params rules catch empty values in the tracking hits it checks, but it does not read your container or compare key names. Check Preview by hand after changes.

Does FunnelGuard catch this?

Partly

FunnelGuard checks part of this.

How: params rules catch empty values.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.