Guide 40 · Ecommerce · GA4 + Tag Manager
Shape the ecommerce data layer: the ecommerce object, the clear, and the seven variables Tag Manager reads
Tag Manager never sees the order unless the site pushes it in Google's shape. The data layer is one ecommerce object per event, cleared before each push, with the same keys every time.
After step 4, Tag Assistant Preview shows the GA4 Event tag firing on every ecommerce event the site pushes, with the event name taken from the push itself. DebugView shows the same events with the full ecommerce object attached.
Download the container fragment: the ecommerce-data-layer container fragment (JSON) (export format version 2, 6732 bytes, MD5 6f7024c67130db4c2f02cade558ad8c9). It holds the GA4 Event tag, the custom event trigger, and the seven ecommerce data layer variables, with the Measurement ID left as G-XXXXXXXXXX for you to replace. The file is a hand-built import template, validated structurally — it was not exported from a live container. Import it from Admin, then Import Container, choosing Merge if the container already has tags.
What you need
- A Tag Manager web container with the Google tag installed. The install guide covers the container and the Google tag.
- Access to the website source code. The site pushes the ecommerce object; Tag Manager reads it but cannot invent it.
- One worked order in Google's shape. The worked order is Google's two-item order: transaction_id
T_12345, value 72.05, tax 3.60, shipping 5.99, currency USD.
The trace
- Push the event name and the ecommerce object together. Each ecommerce action is one push with two keys:
event, the name Analytics will record, andecommerce, the object with the order data. For a purchase:dataLayer.push({ event: "purchase", ecommerce: { transaction_id: "T_12345", value: 72.05, tax: 3.60, shipping: 5.99, currency: "USD", coupon: "SUMMER_FUN", items: [...] } }). The value is the items total: 30.03 + 42.02 = 72.05. The amount charged is 72.05 + 3.60 + 5.99 = 81.64. - Clear the ecommerce object before each push. Run
dataLayer.push({ ecommerce: null })before every ecommerce push. Without the clear, the new object merges with the previous one, and a purchase can carry the last view_item's items. The clear is one line and it prevents the most common data layer error. - Use the same keys on every event. The ecommerce object always uses the same field names:
transaction_id,value,currency,tax,shipping,coupon, anditems. The items array always usesitem_id,item_name,price, andquantity. A key spelled differently on one event —transactionIdinstead oftransaction_id— is a different key, and the variable that reads it stays empty. - Create one GA4 Event tag for all ecommerce events. Add a tag of type Google Analytics: GA4 Event, set the Measurement ID, and set the Event Name to the built-in
{{Event}}variable, so the tag sends whatever event name the data layer pushed. Map the seven event parameters to the seven data layer variables:itemsto{{DLV - ecommerce.items}},transaction_idto{{DLV - ecommerce.transaction_id}},valueto{{DLV - ecommerce.value}},currencyto{{DLV - ecommerce.currency}},taxto{{DLV - ecommerce.tax}},shippingto{{DLV - ecommerce.shipping}}, andcouponto{{DLV - ecommerce.coupon}}. - Fire it on every ecommerce event with one trigger. Add a trigger of type Custom Event that fires when
{{_event}}matches the regular expressionview_item|view_item_list|select_item|add_to_cart|remove_from_cart|begin_checkout|add_shipping_info|add_payment_info|purchase|refund. One tag and one trigger then carry every ecommerce event the site pushes. - Check it in Preview and DebugView. Click Preview, connect the site in Tag Assistant, and walk the shop: view a product, add to cart, begin checkout, purchase. The tag must fire once per push. Then check DebugView in Analytics (Admin, then Data display, then DebugView) for the same events with their ecommerce objects.
Dead ends
DEAD END — THE MERGED OBJECT. Two pushes without a clear between them merge into one object, and the second event inherits the first event's items. The clear push is the fix, and it costs one line per push.
DEAD END — THE KEY THAT DIFFERS BY ONE CHARACTER. ecommerce.value and ecommerce.Value are different keys. Data layer variable names are case-sensitive, and a variable that points at the wrong case reads nothing. Copy the keys from the push into the variable, do not retype them.
DEAD END — ONE TAG PER EVENT WHEN ONE TAG WOULD DO. Ten GA4 Event tags, one per ecommerce event, all mapping the same seven parameters, drift apart the first time one of them is edited. One tag with {{Event}} as the event name carries every ecommerce event and can only disagree with itself in one place.
End state
The site pushes one ecommerce object per action, cleared before each push, with the same keys every time. One GA4 Event tag with {{Event}} as the event name and one custom event trigger carry every ecommerce event in the list. The worked order pushes value 72.05 (30.03 + 42.02), tax 3.60, shipping 5.99, currency USD, for a charged total of 81.64. The downloadable container fragment holds this tag, trigger, and variable set, with the Measurement ID left as G-XXXXXXXXXX for you to replace.
Sources
- Google Analytics developer docs — Measure ecommerce — the GA4 Event tag configuration, the seven data layer variables, and the ecommerce object shape
- Google Analytics developer docs — Set up a purchase event — the worked order values the push carries
Checked 11 November 2026. The data layer shape above is the one in Google's ecommerce developer guide, opened 11 November 2026. No step was run inside a live Tag Manager container or Analytics property, because both need a Google sign-in and this site does not sign in as anyone. The container fragment was validated structurally: export format version 2, unique IDs, the tag's firing trigger resolves, every variable the tag references exists in the file, and the figures were recomputed in Python: 10.01 × 3 = 30.03, 21.01 × 2 = 42.02, 30.03 + 42.02 = 72.05, and 72.05 + 3.60 + 5.99 = 81.64.