Shopify GA4 purchase tracking with GTM
Track Shopify purchases with Customer events and GTM, map GA4 order values and check transaction IDs, discounts and duplicate senders.
Shahzada Ali Hassan, founder of Crisperchecked against 14 sources
Tools
The short answer
Track Shopify purchases in GA4 with a Customer events custom pixel and a GTM GA4 Event tag named purchase. Google deduplicates web purchases by transaction_idsupport.google.com, so each order needs a stable, unique identifier. This guide is for store owners replacing legacy checkout scripts and checking order values.
- If Google & YouTube already sends purchases, check it before adding a second sender.
- Use
custom_purchasein GTM andpurchasein GA4. - Compare item value, tax and shipping separately.
- Steps and settings checked against Google and Shopify documentation on 25 October 2026.
FREE AUDIT
NO LOGINCheck what Meta and Google can count on your site
- Your site
Crisper- Meta and Google count it
Enter your website to see how good its tracking is, and whether Meta is likely restricting it.
On this page 14 sections
- Can I still use Additional Scripts for GA4 purchases?
- Should I use GTM or Google & YouTube for purchases?
- How do I connect the Google tag to Shopify?
- How do I send Shopify order data to GTM?
- How do I create the GA4 purchase trigger?
- Which parameters should the GA4 purchase tag send?
- How do I test a Shopify purchase event?
- What should I compare with the Shopify order?
- How do I inspect purchase parameters in DebugView?
- Why should I check more than the Realtime event count?
- Which mistakes make Shopify purchase revenue wrong?
- What else can affect checkout_completed?
- What should I save after the purchase test?
- What changed in this guide
01Can I still use Additional Scripts for GA4 purchases?
Use Customer events for the replacement. Shopify's checkout.liquid documentationshopify.dev marks checkout.liquid and Additional Scripts as sunset on Thank you and Order status pages.
The video shows the older Additional Scripts method; the written steps below use Customer events.
02Should I use GTM or Google & YouTube for purchases?
Use GTM when you need to maintain a custom mapping. If the Google & YouTube integration already records the right purchases, another sender is the wrong fix.
Have a development store, a test GTM container and the intended GA4 web stream ready. Shopify calls custom pixels an advanced, unsupported featurehelp.shopify.com; choose an app integration if you need a maintained setup.
03How do I connect the Google tag to Shopify?
Load the test container and subscription in the same Customer events pixel.
1. Create the test pixel
- On a development store, open Settings > Customer events and add a pixelhelp.shopify.com.
- Paste the GTM head snippet without its HTML script tags, as Shopify's GTM tutorialhelp.shopify.com says.
- Use the ID of a test container that only your development store loads.
- Put the subscription below in the same pixel.
- Review Customer privacy permissionshelp.shopify.com against the store's consent plan.
Done when the saved pixel contains your test container ID, the subscription and the intended privacy settings.
2. Confirm the GA4 destination
Google's setup guidesupport.google.com documents the Google Analytics destination and the alternate Google tag method.
- Reuse the store's Google tag and GA4 web stream.
- For Google's alternate methodsupport.google.com, enter the stream's Measurement ID as Tag ID.
- Give that Google tag an Initialization trigger.
Done when the saved ID matches the intended stream.
04How do I send Shopify order data to GTM?
Subscribe to checkout_completed and push its order data into the pixel's data layer, the object GTM reads for tag values.
3. Add the purchase subscription
The fields come from Shopify's checkout_completed payloadshopify.dev.
- Append the JavaScript below after the loader, once.
- Save the pixel.
- Test the callback locally with mixed valid and null-variant lines, a null variant ID, and all-null variants.
window.dataLayer = window.dataLayer || []; analytics.subscribe("checkout_completed", (event) => { const checkout = event.data.checkout; const currency = checkout.currencyCode; if (!currency || checkout.lineItems.length === 0) { throw new Error("Checkout mapping needs currency and source lines"); } // Validate and total every source line before filtering item identifiers.
44 more lines of JavaScript
- Copy and download
- Emailed to you
Unlock this snippet
Three details, and the full code is yours
No account needed. Unlock once and every snippet on the blog opens.
Done when the saved pixel contains one subscription and no Liquid checkout code, and in the local tests the event retains its full value and currency, every emitted item has its original variant ID, and all-null input produces an empty items array without suppressing the event.
Shopify's event referenceshopify.dev allows a null variant, variant ID or line title. This sample filters out lines without a variant ID before mapping items, and omits a missing title. Value still includes every validated source line, so item reporting is incomplete when a line is skipped.
Shopify's checkout payloadshopify.dev defines finalLinePrice as the line total after line-level discounts and makes it available with Checkout Extensibility. This sample totals all source lines for value, then divides each identified line total by quantity for its item price. Google's event referencedevelopers.google.com defines value as the sum of price times quantity, excluding shipping and tax.
The sample stops with an error if the full source-line total differs from Shopify's subtotal by more than 0.01. Filtering unidentified items does not change that comparison. Test your discounts and bundles before using the mapping. If the check fails, reconcile the order fields rather than removing it.
This replacement uses Shopify's order ID instead of the former order number, and variant IDs instead of product IDs for items. Check any joins to older reports. The sample maps only the ecommerce and page fields shown; customer contact data is not included.
05How do I create the GA4 purchase trigger?
Create a Custom Event trigger with event name custom_purchase.
4. Save the trigger
Google's data-layer guidedevelopers.google.com explains how the event key triggers tags.
- Leave regular-expression matching off.
- Attach only the completed-order event.
Done when the saved trigger name exactly matches the event in the snippet.
06Which parameters should the GA4 purchase tag send?
Map order identity, items and amounts from the ecommerce object.
5. Create the variables and event tag
- Create Data Layer Variablessupport.google.com, which read named values from the data layer.
- Choose Version 2 for nested fieldssupport.google.com.
- Enter the paths below.
- Create a Google Analytics: GA4 Eventsupport.google.com tag.
- Enter the intended Measurement ID.
- Set Event Name to
purchase. - Map each table row in Event Parameters.
- Attach the
custom_purchaseCustom Event trigger. A trigger is the condition that runs a tag. - Save the tag.
items
- Data Layer Variable path
- ecommerce.items
- Check
- Product objects, not a text string
currency
- Data Layer Variable path
- ecommerce.currency
- Check
- Checkout currency
value
- Data Layer Variable path
- ecommerce.value
- Check
- All source line totals, including unidentified lines
page_location
- Data Layer Variable path
- page_location
- Check
- The page URL from the event context
transaction_id
- Data Layer Variable path
- ecommerce.transaction_id
- Check
- Stable Shopify order ID
tax
- Data Layer Variable path
- ecommerce.tax
- Check
- Tax sent separately
shipping
- Data Layer Variable path
- ecommerce.shipping
- Check
- Shipping sent separately
coupon
- Data Layer Variable path
- ecommerce.coupon
- Check
- Discount codes, when present
Done when each saved variable has the correct path, and reopening the tag shows that event name, stream, parameters and trigger.
07How do I test a Shopify purchase event?
Place a test order and inspect both the Shopify subscription and GA4 receipt.
6. Enable debug mode and publish the test version
Changes saved in a workspace do not run yet. Google sayssupport.google.com you need to publish workspace changes to make them operational.
- Before publishing, open the GA4 Event tag in the development-only container.
- Add
debug_modewith valuetruein Event Parameters, following Google's DebugView instructionssupport.google.com. - Save the tag settings.
- Open the test container that only your development store loads.
- Select Submit, then choose Publish and Create Version.
- Name the version and publish.
Do not publish to a container your live store loads; move the tested setup there through your normal release process.
Done when reopening the tag shows debug_mode set to true in the published version, the test container's Versions list shows your version as published and the pixel code loads that container's ID.
7. Exercise fresh events and inspect receipt
- Connect the saved pixel on the development store.
- Choose Test. Shopify Pixel Helperhelp.shopify.com shows the subscribed
checkout_completedevent and any code errors. - Perform the matching store action with consent granted.
Done when that event has a green dot and its payload matches the action.
Use Shopify Pixel Helper for the subscription and GA4 DebugView for receipt. Shopify says Tag Assistant's Troubleshoot tag feature is incompatible with custom pixelshelp.shopify.com; a green Pixel Helper dot confirms local execution, not GA4 delivery.
08What should I compare with the Shopify order?
Compare the order ID, currency, item prices, quantities, tax and shipping. Keep a written copy of the order values beside the received event.
09How do I inspect purchase parameters in DebugView?
Select the fresh purchase sent by the published test version with debug mode enabled.
8. Compare GA4 with the test order
- With the debug_mode test version published, perform a fresh test action.
- Open GA4 Admin > Data display > DebugView.
- Select
purchaseand compare its parameters and items with your test action. - Revisit the completed order.
- Place a different order.
- Keep debug_mode out of the final non-test configuration.
Done when the event name, products, currency and amounts agree, any repeated event for the first order keeps its ID and the new order uses a different ID.
Google warns against empty or reused transaction IDssupport.google.com because they can cause purchases to be deduplicated.
10Why should I check more than the Realtime event count?
An event count does not show whether the amounts match your order. Use DebugView's event parameter inspectionsupport.google.com to keep the comparison tied to the test purchase.
11Which mistakes make Shopify purchase revenue wrong?
Check duplicate senders, order IDs and the value calculation first.
- Sending both app and GTM purchases complicates reconciliation. Shopify's custom pixel instructionshelp.shopify.com say to remove or modify overlapping installations so events are not counted twice.
- Using an empty transaction ID can combine unrelated purchases. Google's transaction-ID guidesupport.google.com requires a unique ID for each order.
- Replacing the item total with a tax-inclusive order total changes value's meaning. Google's purchase referencedevelopers.google.com excludes tax and shipping from value.
12What else can affect checkout_completed?
Does checkout_completed always wait for the Thank you page?
No. Shopify's event referenceshopify.dev says it can fire on the first upsell offer page instead and will not repeat on the Thank you page. Inspect that earlier event when testing an upsell.
What if the completion page never loads?
The event is not triggered if the page where it should fire fails to load, according to Shopify's referenceshopify.dev. Compare store orders with received events to find those gaps.
13What should I save after the purchase test?
Save the test order IDs, received amounts and the payment paths checked for review. Then verify Shopify checkout-start tracking against the same item-ID convention.
14What changed in this guide
- 25 October 2026: Replaced Additional Scripts and Liquid checkout code with Customer events; added purchase parameters, guarded item-value mapping, order-ID and variant-ID migration notes, and Shopify Pixel Helper plus GA4 checks. Added null-variant and null-ID filtering without reducing event value, local null-case checks, and debug mode before the full test-container publish and fresh-event checks.
Sources
14 sources
- 1Google deduplicates web purchases by transaction_idsupport.google.com↩
- 2Shopify's checkout.liquid documentationshopify.dev↩
- 3Shopify calls custom pixels an advanced, unsupported featurehelp.shopify.com↩
- 4Shopify's GTM tutorialhelp.shopify.com↩
- 5Google's setup guidesupport.google.com↩
- 6Shopify's checkout_completed payloadshopify.dev↩
- 7Google's event referencedevelopers.google.com↩
- 8Google's data-layer guidedevelopers.google.com↩
- 9Data Layer Variablessupport.google.com↩
- 10Google Analytics: GA4 Eventsupport.google.com↩
- 11Google sayssupport.google.com↩
- 12Google's DebugView instructionssupport.google.com↩
- 13Shopify Pixel Helperhelp.shopify.com↩
- 14Google's purchase referencedevelopers.google.com↩


