On this page
What this issue is
The dataLayer is a JavaScript array on your page. Your site pushes messages into it (for example a purchase or a form submit) and Google Tag Manager (GTM) reads them to decide which tags to fire.
When the GTM snippet loads, it wraps the dataLayer array and watches its push method. If another script later runs dataLayer = [] or window.dataLayer = [], the page variable now points to a brand new array. GTM keeps reading the old one, so anything pushed to the new array is never seen. Values already in the old array can also disappear from what your tags use.
// Runs AFTER the GTM snippet
window.dataLayer = [];
window.dataLayer.push({ event: 'form_submit' }); // GTM never sees thisThe usual sources are a theme or plugin, a copied tracking snippet, a cookie banner script, a single page app that resets state on route change, or a developer who wanted to "clear" the layer.
Why it costs you leads or sales
Your ad platforms learn from the conversions your tags report. If purchase or lead events go to a dead array, GA4, Google Ads and Meta see fewer conversions than really happened. Bidding then optimises on weak data, reports undercount, and you may cut campaigns that were working.
The failure is also quiet. The page looks fine, the form still submits and the customer still pays. Only the tracking breaks, and it can be intermittent because it depends on which script runs first.
- GTM loadsWatches the original dataLayer
- Script runs dataLayer = []Page now holds a new array
- Site pushes purchase eventGoes to the new array
- Tags fireGA4, Ads, Meta never triggered
The reset cuts GTM off from later pushes.
The event is pushed, but the tag stays silent.
How to check if your site has it
Search your code
Search theme files, plugins, header and footer scripts and tag templates for
dataLayer =anddataLayer=. Anything that is notwindow.dataLayer = window.dataLayer || [];is a suspect.Use the browser console
Open your page, then DevTools, then Console. Type
google_tag_managerand check your container ID exists. Then typedataLayerand look at the entries. If your early events (such asgtm.js) are missing, the array was replaced.Run a quick test
Before reloading, run
window.__dl = window.dataLayer;after the page loads. Trigger an action, then runwindow.__dl === window.dataLayer. If it returns false, something replaced the array.Use GTM Preview
Open Tag Assistant from GTM, connect to your page and walk through the journey. Compare the Data Layer tab with what you expected. Missing events or a Summary without
gtm.jsandgtm.domhints at a reset.
// Paste in the console after the page has loaded
window.__dl = window.dataLayer;
// ...click or submit something, then:
console.log(window.__dl === window.dataLayer ? 'Same array' : 'Array was replaced');How to fix it
The rule is simple: create the array once, then only push to it. Never assign a new array after the page starts.
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ event: 'form_submit', form_id: 'contact' });Locate the line
Use the search above to find every
dataLayer = []orwindow.dataLayer = []and note which file or tool adds it.Replace it
Change it to
window.dataLayer = window.dataLayer || [];. If it was meant to clear data, remove it, or reset specific keys by pushing them asnullorundefined.Declare before GTM
If you set up values before the GTM snippet, put the safe declaration above the snippet, and never below it.
Check third party code
If a plugin or app adds the reset, update it, change its setting, or contact its support. Do not edit files that updates will overwrite without a child theme or a custom code option.
Search theme and plugins
Search
wp-content/themesandwp-content/pluginsfordataLayer =. Also check header and footer injection plugins and Appearance, Theme File Editor.Edit safely
Change the line in a child theme or the plugin setting, not in a file that updates overwrite.
Check theme.liquid
In Online Store, Themes, Edit code, search all files for
dataLayer =. Check theme.liquid and any snippets.Check Customer events and apps
Review Settings, Customer events for custom pixels, and installed tracking apps that inject scripts.
Review Custom HTML tags
Search your container for
dataLayerin Custom HTML tags. Replace any reassignment with a push or the safe declaration.Publish
Use Preview to test the change, then Submit and publish the workspace.
Check custom code
Look in Site settings, Custom code (head and footer) and each page's custom code settings, plus embed elements.
Check tracking code areas
Look in the funnel or website Settings, Tracking code (header and footer) and custom code elements on each page.
Check Custom Code
Go to Settings, Custom Code, and review every snippet added to the head and body. Also check embed elements.
Check code injection
Open Settings, Advanced, Code Injection (header and footer) and any page-level code injection or Code Blocks.
Fix in source
Search your repository, including bundled JavaScript and single page app route handlers, then replace the assignment and deploy.
Broken
- dataLayer = [] runs after GTM loads
- New pushes go to an array GTM ignores
- Conversion tags stay silent
Fixed
- window.dataLayer = window.dataLayer || [];
- All pushes reach the array GTM watches
- Tags fire on the right events
How to confirm it's fixed
- Search shows no
dataLayer = []outside the safe declaration - The console test reports the same array after a page action
- GTM Preview shows
gtm.js,gtm.domandgtm.loadplus your custom events - Your conversion tags show as fired in Tag Assistant
- Hits appear in GA4 DebugView or your ad platform's test tool
- A real test lead or test order shows in reports
Reset present
Leads or data lost
Pushes go to a new array. GTM never sees them and conversion tags do not fire.
Switch the cause on to see how one line can silence tracking.
How to prevent it happening again
- Give developers and agencies the rule: declare with
window.dataLayer = window.dataLayer || [];, then only push - Review any new plugin, app or pasted snippet for
dataLayer =before it goes live - Test events in GTM Preview after every theme, plugin or consent tool change
- Keep a short list of the events your funnel must send
- Avoid copying old tracking code from other sites without reading it
How FunnelGuard handles this
FunnelGuard detects this issue only partly. It does not read your source code or look for a dataLayer = [] line. What it does is run your real journeys, such as a lead form or checkout, on a schedule and check the tracking hits sent to GA4, Google Ads, Meta, TikTok, LinkedIn, Bing, Pinterest, Snapchat, X and Reddit. If a reset wipes the events and a conversion hit does not arrive, the step fails, it is re-checked from a second region, and you get one alert with a screenshot and a likely cause.
What it does not do: it cannot tell you that a reset is the cause with certainty, it will not find resets that only affect events outside your monitored journeys, and it will not flag a reset that happens to cause no missing hit. To cover the rest by hand, search your code for dataLayer = as shown above, run the console check and review GTM Preview after changes. Plans start with a Free option (1 site, 2 journeys, daily checks, no card), and paid plans have a 3-day free trial.
Questions people ask
Why is my dataLayer.push not working in Google Tag Manager?
A common cause is that another script ran dataLayer = [] after the GTM snippet loaded. That replaces the array GTM watches, so later pushes go to an array GTM never reads. Search your code for the assignment and replace it with window.dataLayer = window.dataLayer || [];.
Is it OK to write dataLayer = [] before the GTM snippet?
It is safe only if nothing else has created the array earlier and no other script resets it later. The safer habit is to always use window.dataLayer = window.dataLayer || [];, which creates the array only if it does not exist.
How do I check if my dataLayer was overwritten?
Open the browser console and save window.__dl = window.dataLayer; after the page loads. After some activity, compare it with window.dataLayer using ===. If the result is false, the array was replaced. Missing gtm.js entries in the console are another sign.
How do I clear dataLayer values without resetting it?
Push the key with a null value, for example dataLayer.push({ ecommerce: null });. GTM merges pushes into its data model, so this clears the old value and keeps the same array.
Why do my GTM tags fire in Preview but conversions are missing in reports?
There are several possible causes, including consent settings, filters and wrong IDs. If events only go missing on some pages or after certain scripts run, check whether a script reassigns the dataLayer on those pages.
Can a single page app cause the dataLayer to reset?
Yes. Some single page app code or route change handlers set dataLayer = [] on every navigation. Replace that with pushes, and clear specific keys with null instead.
Can FunnelGuard detect a dataLayer reset?
Only partly. It does not scan your code, but it runs your journeys and checks whether the expected tracking hits arrive. A missing hit on a monitored journey raises an alert with a likely cause, and you then confirm the reset by hand.
Related issues
- TRK-113Variables returning undefined (dataLayer key renamed)Fix guide
- TRK-107Form submission trigger not firing for AJAX formsFix guide
- TRK-105GTM snippet placed in footer, firing lateFix guide
- TRK-101Two GTM containers fighting (old agency + new)Fix guide
- TRK-115Custom HTML tag throwing JavaScript errorFix guide
- TRK-106Trigger set to All Pages instead of thank-you pageFix guide