4 min readTracking

How to Set Up GA4 and Google Tag Manager on Shopify (2026)

The two GA4 setups that actually work on Shopify in 2026, when to use each, and how to make sure you are not counting every purchase twice.

How to Set Up GA4 and Google Tag Manager on Shopify (2026)

Some links in this article are affiliate links. If you buy through them I may earn a commission, at no extra cost to you. I only recommend tools I use on real client stores.

Most Shopify stores I take over have Google Analytics 4 installed two or three times: once through the Google & YouTube app, once in old theme code, and sometimes again through Google Tag Manager. The result is doubled purchases, broken attribution and reports nobody trusts. This guide shows the two setups that actually work in 2026, how to choose between them, and how to test that the numbers are right.

In this article
  1. The two correct ways to install GA4 on Shopify
  2. Option 1: GA4 with the Google & YouTube app
  3. Option 2: GA4 through Google Tag Manager as a custom pixel
  4. How to test that GA4 is right
  5. The duplicate-tracking checklist
  6. FAQ

The two correct ways to install GA4 on Shopify

Google & YouTube app Google Tag Manager (custom pixel)
Setup time 10 minutes 1–3 hours
Code needed None Some JavaScript
Ecommerce events Sent automatically You map them yourself
Other tags (TikTok, Pinterest, Clarity…) No Yes, all from one container
Best for Most stores Stores with several ad platforms or custom events

My rule: start with the Google & YouTube app. Move to GTM only when you need tags the app can’t handle. Never run both for the same GA4 property.

Option 1: GA4 with the Google & YouTube app

  1. In Shopify admin, install the Google & YouTube app from the Shopify App Store.
  2. Connect the Google account that owns your GA4 property.
  3. Select the GA4 property (check the measurement ID matches the one in Google Analytics).
  4. Remove any old gtag.js snippet from theme.liquid and any GA code left in old checkout settings.

Shopify then tracks the standard ecommerce events for you: product views, add to cart, checkout steps and purchases.

Option 2: GA4 through Google Tag Manager as a custom pixel

Shopify no longer wants tracking code pasted into the theme or checkout. The supported way to run GTM is as a custom pixel, which runs in Shopify’s sandbox.

  1. In Google Tag Manager, open Admin → Install Google Tag Manager and copy the code meant for the <head>.
  2. Remove the outer <script></script> tags.
  3. In Shopify admin, go to Settings → Customer events → Add custom pixel, name it “GTM” and paste the code.
  4. Below the GTM code, subscribe to Shopify’s customer events and push them to the dataLayer, for example:
analytics.subscribe("product_added_to_cart", (event) => {
  const line = event.data.cartLine;
  window.dataLayer.push({
    event: "add_to_cart",
    ecommerce: {
      currency: line.cost.totalAmount.currencyCode,
      value: line.cost.totalAmount.amount,
      items: [{ item_id: line.merchandise.product.id, item_name: line.merchandise.product.title, quantity: line.quantity }]
    }
  });
});
  1. Repeat for product_viewed, checkout_started and checkout_completed (purchase).
  2. In GTM, create a GA4 Configuration tag plus GA4 event tags triggered by those custom events, with data layer variables for the ecommerce fields.
  3. Click Connect on the pixel in Shopify and publish the GTM container.

Know the sandbox limits

Because custom pixels run in a sandbox, some things behave differently: Tag Assistant often can’t see the tags, and enhanced measurement or cross-domain tracking may not work as you expect. Test with GA4’s own reports instead of Tag Assistant.

How to test that GA4 is right

  1. Open your store in a normal browser window and do a full journey: view a product, add to cart, start checkout.
  2. In GA4, open Reports → Realtime and confirm each event arrives once, not twice.
  3. Place a real low-value test order (or use a 100% discount code) and confirm one purchase with the right value.
  4. After 48 hours, compare GA4 purchases with Shopify orders. A gap of 10–20% is normal (consent, blockers); 2× means duplicate tracking.

The duplicate-tracking checklist

  • Search the theme code for gtag(, googletagmanager.com and G- measurement IDs. Remove them.
  • Check Settings → Customer events for old custom pixels you forgot about.
  • If GTM sends GA4 events, the Google & YouTube app should not be connected to the same GA4 property.
  • Check third-party apps that “add Google Analytics” for you. Uninstall the ones you don’t need.

Tracking Meta ads too? Set up the Conversions API the right way with my Meta CAPI on Shopify guide. Starting a new store? Shopify’s trial is $1/month for the first 3 months.

FAQ

Can I use GTM and the Google & YouTube app together?

Yes, but not for the same GA4 property. A common split is the app for Google Ads and GA4, and GTM for everything else (TikTok, Pinterest, heatmaps).

Why doesn’t Tag Assistant show my GTM tags on Shopify?

Custom pixels run in a sandboxed iframe, so browser debugging tools often can’t see them. Use GA4 Realtime and DebugView to confirm events instead.

Do I still put tracking code on the thank-you page?

No. On stores using Shopify’s current checkout, old “additional scripts” don’t run. Purchase tracking should come from the app or the checkout_completed event in a custom pixel.

admin

Lead web developer building Shopify, Hydrogen and WooCommerce stores for brands in the US and the Gulf.