Summary
This article covers the Google Analytics 4 purchase event that your storefront writes on the order completed page for Google Tag Manager to pass on to Google Analytics 4: where to switch it on in the admin area, how to check what a test order sends, what each field contains, and why figures in Google Analytics 4 can differ from your admin area. Revenue in Google Analytics 4 leaves out tax and delivery, which are sent separately, and each product is identified by its product variant ID, the same in every order, rather than by its SKU.
Problem
You want to know what order data reaches Google Analytics 4 from your storefront, or why its revenue and item reports don't match the order totals and product codes you see in your admin area.
Environment
Any storefront using Google Tag Manager with Google Analytics 4. Admin area > Configuration > Settings > General Settings > Google Tag Manager Settings tab. The purchase event is written on the storefront's order completed page. You need your own Google Tag Manager container and Google Analytics 4 property.
Before you start
- A Google Tag Manager container (its ID starts with GTM-) that you can edit and publish, and a Google Analytics 4 property.
- Your storefront on its own domain or subdomain: Google Analytics tracking does not work on a path-based address.
- Access to Configuration > Settings > General Settings in the admin area.
- For the check: a way to place a test order without taking a payment, and to cancel it afterwards (a test order is a real order).
Video
Configuration
Step 1: Open General Settings
In the admin area's left-hand menu, click the items below in turn.
- Configuration
- Settings
- General Settings
The page opens on its Store information tab. The Storefront Name shown there is the name sent to Google Analytics as the store (the affiliation field).
Step 2: Open the Google Tag Manager Settings tab
Click the Google Tag Manager Settings tab along the top of the page. It holds the three settings used in steps 3 and 4. At first only Enable Google Tag Manager shows; Google Tag Manager Id and Enable Google Analytics appear once it is ticked. The screenshot shows the tab after steps 3 and 4.
Step 3: Turn on Google Tag Manager and enter your container ID
- Tick Enable Google Tag Manager.
- In Google Tag Manager Id, enter your container ID from your Google Tag Manager account. It starts with GTM- (the screenshot shows a placeholder, GTM-XXXXXXX).
With this ticked, your storefront loads your Google Tag Manager container, and the order completed page writes the order into the data layer.
Step 4: Tick Enable Google Analytics
Tick Enable Google Analytics. A Google Analytics Configuration Info button appears below it (used in step 6). This adds the Google Analytics 4 purchase event to the data layer on the order completed page. If it is unticked, the data layer only holds the older order variables described in the Google Tag Manager article on this page, and no purchase event.
Step 5: Save the settings
Click Save at the top of the page, under the General Settings heading. A green message confirms the settings were updated, and the page reloads on its Store information tab. The settings apply to this storefront's orders from then on.
Step 6: Follow the Google Tag Manager steps in Google Analytics Configuration Info
You can do this step now or after steps 7 to 9: checking a test order only needs steps 1 to 5. Click the Google Tag Manager Settings tab again, then click Google Analytics Configuration Info (not Google Tag Manager Configuration Info below it). The box that opens, Setup Google Analytics, lists what to set up so the purchase event reaches Google Analytics 4:
- Create a Google Analytics account to get your Measurement Id.
- In Google Tag Manager, create a trigger for the purchase event.
- Add a tag that loads Google Analytics with your Measurement Id. The box calls it a Google Analytics: GA4 Configuration tag; in Google Tag Manager this tag type is called the Google tag. If your container already has a Google tag for this Measurement Id, use that one rather than adding a second.
- Add a Google Analytics: GA4 Event tag with your Measurement Id (where the box mentions a Configuration Tag dropdown, enter your Measurement Id instead), set the event name to purchase, turn on sending the ecommerce data from the data layer, and fire it with the purchase trigger.
- Click Submit in Google Tag Manager so your changes go live.
Google renames options in Tag Manager from time to time, so if a name differs, look for the closest match. Read the box's NOTE too: Google Analytics tracking needs your storefront on its own domain or subdomain, not a path-based address such as www.yourstore.com/mystore. The data layer check in steps 7 to 9 works on any address.
Step 7: Place a test order
To see what is sent, place a test order on your storefront. A test order is a real order: it goes through your normal order process (payment, approval, production and emails), so use a payment method that does not take a payment, and cancel the order in the admin area afterwards. If your Google Tag Manager container is already published, Google Analytics 4 counts the test order too. To avoid that, check the order before you publish your container. Orders placed in Google Tag Manager's Preview mode are also sent to Google Analytics 4; they only stay out of your reports if the Developer traffic data filter in Google Analytics 4 is set to Active.
- If you want to watch the order in Preview mode, start it first: in your Google Tag Manager account click Preview and place the order in the window it opens.
- If you want to test a coupon, make sure Show discount box is ticked in Configuration > Settings > Basket Settings; otherwise the basket has no Discount Code box.
- Add a product in a published category to the basket (find one through your storefront's menu or search box), so the category fields are filled in.
- Optional: type a coupon code in Discount Code and click Apply coupon. The basket says the coupon code was applied and the total drops.
- Check out as normal and confirm the order.
Step 8: Note the order reference number
After you confirm the order, the order completed page opens. Note the order reference number: the purchase event sends it as transaction_id, so you can match the event to the order. Stay on this page for step 9: the purchase event is only written on this page.
Step 9: Find the purchase event
On the order completed page, look at what was written into the data layer. Use whichever of these you prefer:
- Page source: in the same browser window you ordered in, right-click the page and choose View page source, then search the source (Ctrl+F) for "event":"purchase". It is on the line starting dataLayer = [{, which holds the event. (Searching for dataLayer finds an earlier line first.)
- Browser console: press F12, open the Console tab, type dataLayer and press Enter, then expand the entry with event: "purchase".
- Google Tag Manager Preview: if you started Preview before the order (step 7), select the purchase event and open the Data Layer tab.
Check that transaction_id matches the order reference number from step 8, and that value matches the basket total after discounts, without tax and delivery. In the page source the amounts can show extra trailing zeros (for example 7.6500000000), and the same line goes on with the order variables described in the Google Tag Manager article on this page; both are normal. Reloading or reopening the order completed page shows the latest order of whoever is signed in, so if you see a different order number, check you are signed in as the customer who placed the test order. Then cancel the test order in the admin area. The fields are explained in What the purchase event contains below.
What the purchase event contains
The purchase event follows Google's recommended format for Google Analytics 4 ecommerce. A field with nothing to send (no brand, no category, no coupon or discount) is left out.
| Field | What it contains |
|---|
| transaction_id | The order reference number. |
| value | The total of the products after all discounts, without tax and without delivery, rounded to two decimal places. A discount on the whole order is taken off here only, so value can be lower than the products' prices added up. |
| tax | The order's tax, on its own. |
| shipping | The delivery charge without tax, on its own. |
| currency | The currency of the order, for example GBP. |
| affiliation | Your Storefront Name (General Settings > Store information). Sent for the order and for each product. |
| coupon (order) | The coupon code of a discount on the whole order (for example a discount assigned to the order total or subtotal), when the customer entered one. |
| item_id | The ID of the product variant. It is the same in every order of that product, so Google Analytics 4 can add up its sales across orders. It is not the SKU: to recognise a product in your reports, use item_name or item_variant (the SKU), which are sent with it. |
| item_name | The product's full name. |
| item_variant | The product's SKU on that order line. |
| item_brand | The product's manufacturer, when the product has one. You add it on the product's Manufacturer mappings tab, which shows when Show manufacturer items in admin is ticked in Configuration > Settings > Catalogue Settings. If you don't see the Manufacturers menu to create one, ask Infigo Customer Support. |
| item_category to item_category5 | The product's category path, broadest first, for example Branded Merchandise, then Office Stationery, then Notebooks. It follows the product's first category, up to five levels; a deeper path sends its five broadest levels. Left out if the product is in no published category. |
| price | The price of one unit after the discounts on that product, without tax. |
| discount | The discount on one unit from discounts on that product (for example by product, SKU or category), without tax. Sent only when the product line was discounted. |
| coupon (product) | The coupon code of the discount that applied to this product (a discount assigned to products, SKUs, categories or product groups). Only coupon codes are sent, never discount names. |
| quantity, index | How many were ordered, and the product's position in the order, starting at 0. |
Example purchase event
This is the purchase event from a test order for one A5 notebook at ÂŁ8.50, with a 10% coupon (NOTEBOOK10) on its category, no tax and no delivery charge. It is the event and ecommerce part of the data layer entry; the same entry also holds the older order variables described in the Google Tag Manager article on this page (their StorefrontName is your storefront's account name, which can differ from the Storefront Name sent as affiliation). It is laid out here for reading; in the page source it is one long line, and amounts can show extra trailing zeros (for example 0.0000 or 7.6500000000) with the same value.
{
"event": "purchase",
"ecommerce": {
"transaction_id": "16737",
"affiliation": "Example Store",
"value": 7.65,
"tax": 0,
"shipping": 0,
"currency": "GBP",
"items": [
{
"item_id": "4105",
"item_name": "A5 Branded Notebook",
"affiliation": "Example Store",
"coupon": "NOTEBOOK10",
"discount": 0.85,
"item_category": "Branded Merchandise",
"item_category2": "Office Stationery",
"item_category3": "Notebooks",
"price": 7.65,
"quantity": 1,
"index": 0,
"item_variant": "NB-A5-HARDBACK"
}
]
}
}
Why Google Analytics 4 figures differ from your order totals
- Tax and delivery are reported separately. value and each product's price leave out tax and delivery, as Google asks; tax and delivery go in tax and shipping (shown in Google Analytics 4 as Tax amount and Shipping amount). Revenue figures in Google Analytics 4 can therefore be lower than the order totals in your admin area, which include tax and delivery.
- Discounts are already taken off. value is after all discounts. Each product's price and discount only reflect discounts on that product; a discount on the whole order comes off value only.
- Products are identified by product variant. item_id is the product variant's ID, the same in every order, so reports group a product's sales together. Item IDs recorded under a different setup, for example one ID per order line, will not match these.
- Orders are sent when the order completed page opens. That includes orders that still need approval. Orders cancelled, rejected or refunded later are not taken back out of Google Analytics 4, and orders that never reach the order completed page are not sent. If the page is reloaded, the same purchase event (same transaction_id) is written again; Google Analytics 4 uses transaction_id to avoid counting a purchase twice.
- Nothing to change. If both settings are ticked and your Google Tag Manager tags are working, you don't need to do anything.
If the purchase event is missing or incomplete
- No purchase event at all: check that Enable Google Tag Manager and Enable Google Analytics are both ticked and saved (steps 3 to 5), and that you are looking at the order completed page straight after an order.
- The event is in the page but not in Google Analytics 4: check the trigger and tag in your Google Tag Manager container (step 6), that the container is published, and that your storefront has its own domain or subdomain.
- The data layer holds order variables but no "event":"purchase", although both settings are ticked: your storefront uses an older data layer format. Ask Infigo Customer Support.
- No item_brand: the product has no manufacturer. See item_brand in the table above for where to add one.
- No category fields: the product is not in a published category.
- No coupon: the discount has no coupon code, or the customer did not enter one. Discounts that apply without a code still change value, price and discount.
- A different order appears: the page shows the latest order of whoever is signed in. Check the page source in the same browser window you ordered in, or place a new test order.
Search Terms
GA4, Google Analytics 4, purchase event, dataLayer, data layer, Google Tag Manager, GTM, ecommerce tracking, GA4 revenue does not match, GA4 revenue lower than order total, tax and shipping in GA4, item_id, item_brand, item_category, item coupon, order coupon, affiliation, transaction_id, Enable Google Analytics, Google Analytics Configuration Info, order completed page tracking