Shopify8 min read6 views

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.

Watch on YouTube

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_purchase in GTM and purchase in GA4.
  • Compare item value, tax and shipping separately.
  • Steps and settings checked against Google and Shopify documentation on 25 October 2026.

Ask an assistant

ChatGPTClaudePerplexity

FREE AUDIT

NO LOGIN

Check what Meta and Google can count on your site

  1. Your site
  2. Crisper
  3. Meta and Google count it

Enter your website to see how good its tracking is, and whether Meta is likely restricting it.

Run a free audit

Can 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.

Should 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.

How 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

  1. On a development store, open Settings > Customer events and add a pixelhelp.shopify.com.
  2. Paste the GTM head snippet without its HTML script tags, as Shopify's GTM tutorialhelp.shopify.com says.
  3. Use the ID of a test container that only your development store loads.
  4. Put the subscription below in the same pixel.
  5. 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.

  1. Reuse the store's Google tag and GA4 web stream.
  2. For Google's alternate methodsupport.google.com, enter the stream's Measurement ID as Tag ID.
  3. Give that Google tag an Initialization trigger.

Done when the saved ID matches the intended stream.

How 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.

  1. Append the JavaScript below after the loader, once.
  2. Save the pixel.
  3. Test the callback locally with mixed valid and null-variant lines, a null variant ID, and all-null variants.
javascript53 lines
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.

We email you a copy. We may follow up on WhatsApp.

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.

How 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.

  1. Leave regular-expression matching off.
  2. Attach only the completed-order event.

Done when the saved trigger name exactly matches the event in the snippet.

Which parameters should the GA4 purchase tag send?

Map order identity, items and amounts from the ecommerce object.

5. Create the variables and event tag

  1. Create Data Layer Variablessupport.google.com, which read named values from the data layer.
  2. Choose Version 2 for nested fieldssupport.google.com.
  3. Enter the paths below.
  4. Create a Google Analytics: GA4 Eventsupport.google.com tag.
  5. Enter the intended Measurement ID.
  6. Set Event Name to purchase.
  7. Map each table row in Event Parameters.
  8. Attach the custom_purchase Custom Event trigger. A trigger is the condition that runs a tag.
  9. 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
These paths must match the event payload.

Done when each saved variable has the correct path, and reopening the tag shows that event name, stream, parameters and trigger.

How 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.

  1. Before publishing, open the GA4 Event tag in the development-only container.
  2. Add debug_mode with value true in Event Parameters, following Google's DebugView instructionssupport.google.com.
  3. Save the tag settings.
  4. Open the test container that only your development store loads.
  5. Select Submit, then choose Publish and Create Version.
  6. 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

  1. Connect the saved pixel on the development store.
  2. Choose Test. Shopify Pixel Helperhelp.shopify.com shows the subscribed checkout_completed event and any code errors.
  3. 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.

What 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.

How 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

  1. With the debug_mode test version published, perform a fresh test action.
  2. Open GA4 Admin > Data display > DebugView.
  3. Select purchase and compare its parameters and items with your test action.
  4. Revisit the completed order.
  5. Place a different order.
  6. 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.

Why 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.

Which mistakes make Shopify purchase revenue wrong?

Check duplicate senders, order IDs and the value calculation first.

What 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.

What 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.

What 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
  1. 1Google deduplicates web purchases by transaction_id↩
  2. 2Shopify's checkout.liquid documentation↩
  3. 3Shopify calls custom pixels an advanced, unsupported feature↩
  4. 4Shopify's GTM tutorial↩
  5. 5Google's setup guide↩
  6. 6Shopify's checkout_completed payload↩
  7. 7Google's event reference↩
  8. 8Google's data-layer guide↩
  9. 9Data Layer Variables↩
  10. 10Google Analytics: GA4 Event↩
  11. 11Google says↩
  12. 12Google's DebugView instructions↩
  13. 13Shopify Pixel Helper↩
  14. 14Google's purchase reference↩