When a shopper views a product, adds to cart or completes checkout, the site pushes a message into the data layer with details such as product ID, name, variant, price, quantity, currency and order value. Google Tag Manager and other tools listen for these messages and pass the data to GA4, Meta, Google Ads, Klaviyo or a server-side container.
In code it is usually an array called window.dataLayer, and events are added with dataLayer.push(). On Shopify, checkout and purchase events run through Customer Events (web pixels), so the storefront and the checkout often need separate setups. WooCommerce and Magento stores typically rely on a plugin, an extension or custom theme code.
Why it matters for eCommerce
Every ROAS, conversion rate and LTV number depends on tracking data. A clean data layer means ad platforms receive accurate purchase values, so their bidding algorithms optimize toward real revenue instead of duplicates or missing orders.
How it works in practice
- Write a spec: which events, which parameters, which naming convention. GA4’s recommended ecommerce events are a good base.
- Developers push events at the right moments in the theme or app.
- Google Tag Manager reads the data layer and fires tags to each platform.
- QA every event in preview mode before and after each theme or app change.
Common mistakes
- Scraping prices from page text with CSS selectors that break on the next redesign.
- Including tax and shipping in revenue for some platforms but not others, so numbers never match.
- Firing the purchase event again every time the thank-you page reloads.