How to Design a dataLayer Correctly for E-commerce Tracking in GA4, Google Ads and Meta Ads
A good dataLayer is not a list of random variables in GTM. It is an agreement between the website, analytics, ad platforms and development.
Short Answer
A good dataLayer is not a list of random variables in GTM. It is an agreement between the website, analytics, ad platforms and development. For e-commerce, it should carry stable business data: product ID, price, quantity, currency, value, order ID, items and a unique event identifier. Only then should events be mapped from this layer into GA4, Google Ads and Meta Ads.
Why Treat the dataLayer as a Contract, Not Improvisation
The biggest mistake in e-commerce tracking is relying on GTM to somehow pull the price from HTML, the product name from a heading and the order ID from text on the thank-you page. That kind of tracking works until the first redesign, template change or A/B test. A proper dataLayer should be independent of the page's appearance. The website sends structured data into it, and GTM only reads, validates and forwards it.
In practice, this means the developer should not implement "GA4 code". They should implement a data layer with clear events. Marketing can then decide in GTM which platforms receive a signal from a given event. As a result, one purchase can be sent to GA4 as purchase, to Google Ads as a purchase conversion and to Meta as Purchase, without each platform having its own unmaintainable snippet in the template.
Minimum Event Design
For a typical online store, it makes sense to start with these events: view_item, add_to_cart, view_cart, begin_checkout, add_shipping_info, add_payment_info and purchase. Each event should include an items array. For purchases, add transaction_id or order_id, value, currency and ideally event_id for deduplicating server and browser events.
Not every store needs every intermediate step immediately. If the budget is small and tracking is being built for the first time, it is more important to have a bulletproof purchase and add_to_cart than ten half-working events. On larger accounts, however, the intermediate steps help analyze the funnel, build remarketing audiences and tune the product feed.
Recommended Payload Structure
The dataLayer should send business reality, not marketing labels. The product ID should match the identifier in the feed and internal system. The price should be a number, not text such as "1 290 Kc". The currency should be an ISO code, for example CZK or EUR. The order value should be defined consistently: ideally the value of items excluding shipping and tax, while shipping and tax are sent separately where the platform supports them.
Be careful with categories. item_category through item_category5 in GA4 only make sense when the category is consistent. If you sometimes send "Shoes > Women" and other times "womens-shoes", reports will look technically correct but analytically broken.
Example dataLayer Event
This example is not a universal template for every online store, but it is a good direction for a developer brief:
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'ecommerce_purchase',
event_id: 'ord_12345_purchase',
ecommerce: {
transaction_id: '12345',
currency: 'CZK',
value: 2580.00,
shipping: 99.00,
tax: 447.00,
coupon: 'JARO10',
items: [
{
item_id: 'SKU-001',
item_name: 'B\u011b\u017eeck\u00e9 boty Alpha',
item_brand: 'Alpha',
item_category: 'Obuv',
item_category2: 'B\u011bh',
price: 1290.00,
quantity: 2
}
]
}
});What to Map Into Each Platform
GA4 should receive the recommended event names: ecommerce_purchase in the dataLayer is forwarded in GTM as purchase. Google Ads usually does not receive the full item list unless it is a specific implementation with cart data, but value, currency and transaction_id are essential. Meta should receive Purchase, value, currency, content_ids, contents and event_id. If you use both the Pixel and Conversions API, event_id must be identical for the browser and server version of the same event.
The dataLayer should not contain email, phone number or other personal data in readable form. If you are implementing enhanced conversions or advanced matching, handle it deliberately, through supported mechanisms, hashing and with respect for consent and legal basis.
Pre-publication Checklist
Trigger each event in GTM Preview and verify that the variables exist at the moment the tag fires. Verify that purchase does not fire twice after refreshing the thank-you page. Verify that transaction_id is unique. Verify that item_id matches the feed. Verify that value and currency are not empty. Verify that the same order has the same numbers in the store, GA4 and ad systems, with expected attribution differences.
When the store template changes, the dataLayer must be part of regression testing. Otherwise, ads may keep running while the algorithm suddenly learns from empty values or duplicate purchases.
FAQ
Frequently Asked Questions
Next Article
GCLID FBCLID li_fat_id UTM parameters
GCLID, FBCLID, li_fat_id and UTM Parameters: Why They Are Not the Same and How Not to Lose Them
UTM parameters and click IDs have completely different jobs. UTM is a human-readable campaign description for analytics, reporting and source governance.
Looking for someone who can take this off your plate?
Want to verify whether your online store is sending the right data to ad platforms? We will audit your dataLayer, GTM and conversion setup.