On this page
What this issue is
The dataLayer is a JavaScript array on your page. Your site pushes messages into it, such as generate_lead or purchase, and Google Tag Manager (GTM) reads them to decide which tags to fire.
GTM does read events that were pushed before it loaded. But problems still happen. The usual causes: the code calls dataLayer.push before dataLayer exists, so it throws an error. Or a script replaces the array with dataLayer = [] after GTM started. Or the event fires before the page has its other data, and the trigger or variable that needs that data comes up empty. In each case the event is never processed by a tag.
- Page starts loadingTheme or app script runs early
- dataLayer.push(event)Runs before the array exists or is later overwritten
- GTM container loadsFinds no matching event
- Conversion tagNever fires
The push runs before the dataLayer is ready, so nothing downstream sees it.
Why it costs you leads or sales
The lead or sale still happens, but GA4, Google Ads, Meta and other platforms never hear about it. Reports undercount conversions, and ad platforms learn from less data. Smart bidding can then spend on the wrong audiences. It often hits only some visits, such as slow connections or cached pages, so it is easy to miss.
Example: 100 real form leads in a week, but the early push is missed on some page loads.
How to check if your site has it
Open GTM PreviewGoogle Tag Manager
In Tag Manager, click Preview, enter your page URL and run the journey that should send the event.
Look at the event list
In Tag Assistant, check the left column. Your custom event should appear after Container Loaded, or be shown in the Data Layer tab of an earlier message.
Check the browser console
Open DevTools, then Console. An error such as 'Cannot read properties of undefined (reading push)' means the push ran before the dataLayer existed.
Inspect the array
Type
dataLayerin the console after the action. If your event is missing, it was overwritten or never pushed.Compare trigger and tagGoogle Tag Manager
If the event is present but the tag shows as Not Fired, check the Custom Event trigger name. It is case sensitive.
How to fix it
The goal is that the array always exists first, is never replaced, and that events carry their data when pushed.
<script>
window.dataLayer = window.dataLayer || [];
</script>
<!-- Google Tag Manager snippet goes here, right after -->window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'generate_lead',
form_id: 'contact'
});Find where the push comes from
Check your theme's header.php, a code snippets plugin, or the form plugin's custom JavaScript.
Declare the array first
Add the one-line declaration before the GTM snippet, or use
window.dataLayer = window.dataLayer || []in every push.
Edit theme.liquid
In Online Store, Themes, Edit code, open theme.liquid and put the declaration above the GTM snippet in the head.
Check custom pixels
Pushes from Customer events (custom pixels) run in a sandbox. Test them separately in GTM Preview.
Use a Custom Event trigger
Set the event name to match exactly, for example generate_lead.
Avoid timing-sensitive triggers
If a tag needs data pushed with the event, read it from the same push, not from an earlier message.
Use Project settings
In Custom code, Head code, put the declaration above the GTM snippet. Put form event code in the Footer code, or on the page.
Remove overwrites
Search your code for
dataLayer = [and change it todataLayer = dataLayer || [].Push after the action
Push the event in the success callback of the form or checkout, not on page load.
How to confirm it's fixed
- No console errors about dataLayer or push
- The custom event appears in Tag Assistant after the action
- The tag shows under Tags Fired for that event
- The hit appears in GA4 DebugView or the platform's own test tool
- Test on a hard refresh and with the cache cleared
How to prevent it happening again
- Keep one agreed snippet that declares the dataLayer above GTM
- Ask developers to document event names, and match them in triggers
- Re-run GTM Preview after theme, plugin or form changes
- Publish a GTM version note describing each new event
- Test the full journey on a schedule, not only at launch
How FunnelGuard handles this
FunnelGuard detects this only partly. Its robot visitor runs your real journey, such as a lead form, and checks that the tracking hits for GA4, Google Ads, Meta and the other platforms actually go out. If an early or missed push means a conversion hit never fires, a failed hit check can reveal the symptom, and you get one alert with a screenshot and a likely cause after a second-region re-check.
Questions people ask
Does GTM process dataLayer events pushed before it loads?
Yes, if the dataLayer array exists. GTM reads messages already in the array when the container loads. The problem starts when the array is missing, overwritten, or the event lacks data the trigger needs.
Why is my dataLayer push not triggering a tag in GTM?
Common causes are a mismatch in the event name (it is case sensitive), a push that ran before the array existed, or a trigger with extra conditions that are not met. Check Tag Assistant to see whether the event appears at all.
How do I make sure the dataLayer exists before GTM loads?
Add window.dataLayer = window.dataLayer || []; in the head, above the GTM snippet. Use the same form in any script that pushes events.
Why do I get 'Cannot read properties of undefined (reading push)'?
Your code calls dataLayer.push before the array has been created. Declare it first with window.dataLayer = window.dataLayer || [].
How can I see events that GTM missed?
Type dataLayer in the browser console to view the array, and use GTM Preview to see which events it processed. If the event is in the array but not in Preview, check the container loading order and the trigger.
Can overwriting dataLayer break tracking?
Yes. Setting dataLayer = [] after GTM has started replaces the array and cuts the link GTM uses. Always use dataLayer = dataLayer || [].
Can FunnelGuard detect a dataLayer push that ran too early?
Only partly. It checks that the tracking hits go out on your real journeys, so a missing conversion hit can be flagged. It does not inspect your dataLayer code or timing, so confirm that by hand in GTM Preview.
Related issues
- TRK-099GTM container snippet missingFix guide
- TRK-105GTM snippet placed in footer, firing lateFix guide
- TRK-107Form submission trigger not firing for AJAX formsFix guide
- TRK-113Variables returning undefined (dataLayer key renamed)Fix guide
- TRK-115Custom HTML tag throwing JavaScript errorFix guide
- TRK-103Workspace changes never published (tag in preview only)Fix guide