In short: Shopify GA4 tracking no longer works through the old “Additional scripts” box, which stopped running on all plans in August 2026. The supported replacement is a custom pixel under Settings > Customer events: it subscribes to Shopify’s standard events such as checkout_completed and sends them to GA4 as page_view, view_item, add_to_cart, begin_checkout and purchase.
If your GA4 property stopped recording purchases from your Shopify store, you are not alone. For years the standard recipe was to paste a tracking snippet into the “Additional scripts” field of the order status page. Shopify retired that field for Shopify Plus stores in August 2025 and for every other plan in late August 2026. Scripts that lived there simply no longer fire.
This guide shows how to rebuild Shopify GA4 tracking the supported way, with a custom pixel. You get the complete code, an explanation of each part, and a testing routine, so you can have purchases back in GA4 in about half an hour.
Why Shopify GA4 Tracking Broke
The old checkout let you run any JavaScript on the thank-you page. The script could read Liquid variables such as the order total and send them wherever you wanted. The new checkout, built on Checkout Extensibility, does not allow that. Tracking code now has to run inside Shopify’s Web Pixels system, which is managed in one place: Settings > Customer events.
Two things change for you as a result:
- No DOM and no Liquid. A custom pixel runs in a sandbox. It cannot read the page, scrape the order total from the HTML, or use Liquid variables. Everything comes from event payloads that Shopify hands to your code.
- Events instead of page loads. You no longer run code “on the thank-you page”. You subscribe to an event called checkout_completed, and Shopify calls your function when it happens.
Your Three Options
- The Google & YouTube app. Shopify’s own integration. It is the fastest route and needs no code, but you get little control over which events and parameters are sent.
- A custom pixel that talks to GA4 directly. A few dozen lines of JavaScript. You control every event and parameter, and there is nothing else to maintain. This is what the rest of this guide builds.
- A custom pixel that loads Google Tag Manager. Useful if you already manage many tags in GTM. It works, with limitations that are covered near the end.
Pick one. Running the Google & YouTube app and a custom GA4 pixel against the same property counts every purchase twice.
The Shopify Events You Will Use
Shopify publishes a fixed list of standard events. These are the ones that map to GA4 ecommerce events:
- page_viewed → GA4 page_view
- product_viewed → view_item
- product_added_to_cart → add_to_cart
- checkout_started → begin_checkout
- payment_info_submitted → add_payment_info
- checkout_completed → purchase
Others exist too, among them collection_viewed, search_submitted, cart_viewed and product_removed_from_cart. Add them later with the same pattern if you need them.
Step 1: Create the Custom Pixel
- In the Shopify admin, open Settings > Customer events.
- Add a custom pixel and give it a clear name, for example “GA4 direct”.
- Under the customer privacy settings, leave permission as Required with Marketing and Analytics selected. This is the default for new custom pixels. In regions that require consent, the pixel then runs only for visitors who agreed.
- Paste the code from the next step into the code window.
- Click Save, then Connect. A saved pixel that is not connected does nothing.
Step 2: The Pixel Code
Replace the measurement ID on the first line with your own. You find it in GA4 under Admin > Data streams.
const GA4_ID = 'G-XXXXXXXXXX';
// 1. Load gtag.js inside the pixel sandbox
const s = document.createElement('script');
s.async = true;
s.src = 'https://www.googletagmanager.com/gtag/js?id=' + GA4_ID;
document.head.appendChild(s);
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
// 2. Pass Shopify's consent state to Google Consent Mode
function consentFrom(p) {
const analytics = p && p.analyticsProcessingAllowed ? 'granted' : 'denied';
const marketing = p && p.marketingAllowed ? 'granted' : 'denied';
return {
analytics_storage: analytics,
ad_storage: marketing,
ad_user_data: marketing,
ad_personalization: marketing
};
}
gtag('consent', 'default', consentFrom(init.customerPrivacy));
api.customerPrivacy.subscribe('visitorConsentCollected', (event) => {
gtag('consent', 'update', consentFrom(event.customerPrivacy));
});
// 3. Configure GA4. Page views are sent manually below.
gtag('js', new Date());
gtag('config', GA4_ID, { send_page_view: false });
// 4. Helpers
const num = (money) => (money && money.amount != null ? Number(money.amount) : 0);
function itemFromVariant(variant, quantity) {
return {
item_id: variant.sku || variant.id,
item_name: variant.product.title,
item_variant: variant.title,
item_brand: variant.product.vendor,
item_category: variant.product.type,
price: num(variant.price),
quantity: quantity || 1
};
}
function checkoutPayload(checkout) {
return {
currency: checkout.currencyCode,
value: num(checkout.totalPrice),
items: checkout.lineItems.map((line) => itemFromVariant(line.variant, line.quantity))
};
}
// 5. Events
analytics.subscribe('page_viewed', (event) => {
gtag('event', 'page_view', {
page_location: event.context.document.location.href,
page_title: event.context.document.title
});
});
analytics.subscribe('product_viewed', (event) => {
const variant = event.data.productVariant;
gtag('event', 'view_item', {
currency: variant.price.currencyCode,
value: num(variant.price),
items: [itemFromVariant(variant, 1)]
});
});
analytics.subscribe('product_added_to_cart', (event) => {
const line = event.data.cartLine;
gtag('event', 'add_to_cart', {
currency: line.cost.totalAmount.currencyCode,
value: num(line.cost.totalAmount),
items: [itemFromVariant(line.merchandise, line.quantity)]
});
});
analytics.subscribe('checkout_started', (event) => {
gtag('event', 'begin_checkout', checkoutPayload(event.data.checkout));
});
analytics.subscribe('payment_info_submitted', (event) => {
gtag('event', 'add_payment_info', checkoutPayload(event.data.checkout));
});
analytics.subscribe('checkout_completed', (event) => {
const checkout = event.data.checkout;
const coupons = (checkout.discountApplications || [])
.filter((d) => d.type === 'DISCOUNT_CODE')
.map((d) => d.title);
gtag('event', 'purchase', Object.assign(checkoutPayload(checkout), {
transaction_id: checkout.order.id,
tax: num(checkout.totalTax),
shipping: num(checkout.shippingLine && checkout.shippingLine.price),
coupon: coupons.join(',')
}));
});
What the Code Does
Loading GA4
The first block adds Google’s script to the sandbox, exactly as the usual GA4 snippet does on a normal page. Automatic page views are switched off because the sandbox has its own internal URL. If GA4 measured that URL you would see sandbox paths in your reports instead of real pages.
Consent
Shopify knows what each visitor agreed to in your cookie banner. The consentFrom function translates that into the four Google Consent Mode signals. The first call sets the state when the pixel starts, and the subscription updates it if the visitor changes their choice.
Shopify’s own Google Tag Manager example sets all four signals to “granted” unconditionally. Do not copy that part if you sell to the EU or the UK, because it overrides what your visitors actually chose.
Page views
The real page address and title come from the event itself, under event.context.document. That is the only reliable source inside the sandbox.
Products and cart
Every ecommerce event in GA4 wants an items array. The itemFromVariant helper builds one item from a Shopify product variant, so the same shape is used from product view through purchase. It uses the SKU as the item ID and falls back to the variant ID when a product has no SKU.
Purchase
The purchase event reads everything from event.data.checkout: the order ID, total, tax, shipping and discount codes. The order ID is only present on checkout_completed. On earlier checkout events it is empty, which is why the transaction ID is added only here.
Step 3: Test It
Google Tag Assistant’s “Troubleshoot tag” feature does not detect tags that run inside a custom pixel, so do not rely on it. Use GA4 itself:
- Temporarily change the config line to turn on debug mode:
gtag('config', GA4_ID, { send_page_view: false, debug_mode: true }); - Save the pixel, then open your store in a private window and accept the cookie banner.
- In GA4, open Admin > DebugView. Browse a product, add it to the cart and start checkout. Each step should appear within a few seconds.
- Place a test order, using Shopify’s test payment gateway or a 100% discount code. Check that the purchase event shows the right value, currency, transaction ID and items.
- Remove debug_mode and save again.
If nothing arrives, open the browser console on the storefront. An error in the pixel code is reported there, usually a property that does not exist on the event. Adding a temporary console.log(event) inside a subscription shows you the exact payload Shopify sends.
Common Problems
- Purchases counted twice. The Google & YouTube app is still connected to the same GA4 property. Disconnect one of the two.
- No events at all. The pixel was saved but not connected, or you are testing from a region that requires consent and did not accept the banner.
- Missing purchases with upsell apps. checkout_completed fires once per checkout. With a post-purchase upsell it fires on the first upsell page, not on the thank-you page, so the value does not include what was added afterwards. If the page fails to load, the event does not fire at all.
- Strange page paths in GA4. Automatic page views are still on. Keep send_page_view: false and send page views from the page_viewed event.
- Revenue lower than in Shopify. Expected to some degree. Visitors who decline analytics cookies are not tracked, and ad blockers stop some requests. Compare trends, not exact totals.
- Old code still present. Remove GA4 snippets from theme.liquid. Leaving them there double counts page views on the storefront.
What About Google Tag Manager?
You can load a GTM container inside a custom pixel instead of gtag.js, then push each Shopify event into the data layer and build the GA4 tags in GTM. The principle is the same as our WooCommerce data layer guide, with Shopify’s events as the source.
Know the limits before you choose it:
- Only Custom Event triggers work, and the trigger name must match the event name you push. Page view, click, scroll and form triggers have nothing to listen to in the sandbox.
- Tags that need the real page, such as heatmaps, chat widgets or anything that changes what the visitor sees, cannot run from a pixel.
- Outbound link clicks and scroll depth are not detected automatically.
For a store that only needs GA4, the direct pixel above is simpler and has fewer moving parts.
Conclusion
Shopify GA4 tracking now lives in one place, the Customer events screen, and one custom pixel covers the full funnel from page view to purchase. Create the pixel, paste the code with your measurement ID, connect it, and confirm a test order in DebugView. Once purchases are flowing again, our guides to GA4 traffic sources and GA4 attribution models help you make sense of where those orders came from.
Frequently Asked Questions
Why did GA4 stop tracking purchases on my Shopify store?
Most often because the tracking code was in the Additional scripts field of the order status page. Shopify stopped running that field for Shopify Plus stores in August 2025 and for all other plans in late August 2026. The code has to be moved to a pixel under Settings > Customer events.
What replaces Additional scripts in Shopify?
Web pixels, managed under Settings > Customer events. You can use an app pixel such as the Google & YouTube app, or write a custom pixel that subscribes to Shopify’s standard events.
Which Shopify event should trigger the GA4 purchase event?
checkout_completed. It fires once per checkout, normally on the thank-you page, and its payload contains the order ID, total, tax, shipping, discount codes and line items.
Can I use Google Tag Manager in a Shopify custom pixel?
Yes. You can load a GTM container inside a custom pixel and push Shopify events to the data layer. Only Custom Event triggers work, and tags that need access to the real page cannot run because the pixel is sandboxed.
Do I need to handle cookie consent in a custom pixel?
Shopify only runs the pixel for visitors who gave the permissions you selected in the pixel’s customer privacy settings. For Google Consent Mode you should also pass the visitor’s choice to gtag, using init.customerPrivacy and the visitorConsentCollected event.
Why are my Shopify purchases counted twice in GA4?
Usually because two integrations send the purchase to the same property, for example the Google & YouTube app and a custom pixel. Keep one and disconnect the other.
Sources: Shopify Web Pixels API: standard events, checkout_completed reference, Shopify Help: custom pixel code, Shopify Help: Google Tag Manager in a custom pixel.
