On this page
What this issue is
The dataLayer is a list of messages your site sends to Google Tag Manager (GTM). GTM merges every message into one running picture of the page, called the data model. When you push an ecommerce event such as view_item_list or add_to_cart, the ecommerce object stays in that model until something replaces it.
Why it costs you leads or sales
- view_item_listPushes 12 items
- add_to_cartPushes 1 item, old object not cleared
- GA4 receives eventItems or fields from the list are merged in
- ReportsWrong products and counts
The ecommerce object from the product list is never cleared, so it is merged into the add_to_cart event.
How to check if your site has it
Open GTM Preview modeGoogle Tag Manager
In Tag Manager click Preview, enter your site URL and connect Tag Assistant to the site.
Walk through two ecommerce events in a row
Open a category page, then a product page, then add the product to the cart. Each step should send a different ecommerce event.
Inspect the dataLayer for each event
In Tag Assistant, select each ecommerce event and open the Data Layer tab. Look for a push of { ecommerce: null } just before each ecommerce push. If it is missing, you have the issue.
Compare the payload GA4 receives
Open the GA4 tag fired by the later event and check its fields. If it lists items from the earlier event, or a coupon or value that was not in the new push, the old object leaked.
Test in the browser console
On the page, run google_tag_manager['GTM-XXXX'].dataLayer.get('ecommerce') after the later event. Replace GTM-XXXX with your container ID. If it returns old fields, the object was not reset.
How to fix it
window.dataLayer = window.dataLayer || [];
// 1. Clear the previous ecommerce object
dataLayer.push({ ecommerce: null });
// 2. Push the new event
dataLayer.push({
event: 'add_to_cart',
ecommerce: {
currency: 'USD',
value: 29.99,
items: [{
item_id: 'SKU_123',
item_name: 'Blue T-shirt',
price: 29.99,
quantity: 1
}]
}
});Find every ecommerce push
Search your code for dataLayer.push calls that contain an ecommerce key.
Add the clear before each one
Put dataLayer.push({ ecommerce: null }); directly above each push, or wrap both in one helper function and call that everywhere.
Check where the pushes come from
If a Custom HTML tag pushes ecommerce events, add the clear line before the push inside that tag.
Do not rely on a trigger to clear it
GTM cannot clear the data model after the fact. The null push must go into the dataLayer in the code that creates the event.
Identify the source of the events
Open Plugins and see which one pushes ecommerce data to the dataLayer, for example a GA4 or WooCommerce tracking plugin.
Update the plugin and check its settings
Many plugins already clear the object. If yours does not, update it, or ask the vendor. If you added your own snippets in a theme file or code-snippet plugin, add the clear line there.
Find where events are pushed
Check Settings > Customer events for custom pixels, and the theme code in Online Store > Themes > Edit code for dataLayer.push calls.
Add the clear line before each push
If a theme, app or custom snippet pushes to the dataLayer, put dataLayer.push({ ecommerce: null }); before each ecommerce push. If an app generates them, contact its support.
Find your custom code
Check Project settings > Custom code and page-level custom code for dataLayer.push calls with ecommerce data.
Add the clear line
Put dataLayer.push({ ecommerce: null }); before each ecommerce push, then republish the site.
How to confirm it's fixed
Repeat the walkthrough in GTM PreviewGoogle Tag Manager
Go through the list, product and cart events again. Each ecommerce push should now be preceded by an { ecommerce: null } push.
Check the GA4 tag payload
Each event should list only its own items, with no leftover coupon, value or items from the previous event.
Check GA4 DebugView
In GA4 go to Admin > DebugView and confirm each event shows the right items and parameters.
Compare reports after a few days
Check Reports > Monetization > Ecommerce purchases. Item counts per event should look realistic compared with your orders.
Not cleared
- add_to_cart carries items from the earlier list
- Item counts and values look inflated
- Product reports show products nobody added
Cleared first
- add_to_cart contains only the added product
- Each event has its own items and value
- Product and funnel reports match real behaviour
How to prevent it happening again
- Use one shared function that clears and pushes every ecommerce event
- Add the clear step to your tracking spec so new events include it
- Re-test in GTM Preview after theme, plugin or checkout changes
- Test two ecommerce events in a row, not only one in isolation
- Review GA4 DebugView after any release that touches tracking
How FunnelGuard handles this
Questions people ask
Why are items from a previous event showing in my GA4 add_to_cart?
GTM merges each new push into its data model, so an ecommerce object that was not cleared can carry old items or fields into the next event. Push dataLayer.push({ ecommerce: null }) immediately before every ecommerce push to stop it.
How do I clear the ecommerce object in the dataLayer?
Run dataLayer.push({ ecommerce: null }); right before each ecommerce event push. This resets the object so the new event starts clean. It should sit in the code that creates the event, not in a GTM trigger.
Do I need to clear ecommerce before every GA4 event?
Yes, before every push that contains an ecommerce object. Google's GA4 ecommerce documentation recommends this because the object otherwise persists in the GTM data model. Events without an ecommerce key do not need it.
Can I fix a dataLayer leak inside Google Tag Manager only?
Not reliably. GTM reads the dataLayer but cannot reset it after the fact. The clear push has to be added in the code or plugin that creates the events. A Custom HTML tag that you control is the one exception, because you can edit its code.
How can I tell if my ecommerce object is leaking?
Open GTM Preview, trigger two ecommerce events in a row and inspect the Data Layer tab for each. If there is no { ecommerce: null } push before the second event, or the GA4 tag shows old items, the object is leaking.
Does a leaking ecommerce object affect purchase revenue?
It can. Purchase value may still be correct, but extra items, a leftover coupon or wrong item data can distort product reports and item revenue. Check the purchase event payload against a real test order.
Can FunnelGuard detect an ecommerce object that is not cleared?
No. FunnelGuard does not check for this yet. It captures the dataLayer but has no clear check, so use GTM Preview and GA4 DebugView for now.
Related issues
- TRK-083items array missing from ecommerce eventsFix guide
- TRK-084items missing item_id or item_nameFix guide
- TRK-088add_to_cart missing or fires on page loadFix guide
- TRK-092Old UA enhanced ecommerce schema pushed instead of GA4 schemaFix guide
- TRK-095Currency on items differs from event currencyFix guide
- TRK-082purchase value differs from order totalFix guide