How should I install GA4 on Shopify?
The 2026 best practice for Shopify GA4 is Web Pixel via Customer Events API — Shopify's sandboxed pixel system that runs GA4 in isolation, supports the Customer Privacy API for consent, fires standard e-commerce events automatically, and works on all Shopify plans (including Basic).
The legacy approach — pasting GA4 code into theme.liquid and additional_scripts (Shopify Plus only) — is deprecated for new implementations because it creates duplicate transactions when run alongside Web Pixel and lacks the consent integration. Use Web Pixel for new stores; migrate from theme.liquid for existing stores.
Shopify Plus removed the checkout.liquid restriction in August 2024, making Web Pixel viable across the full purchase flow.
The two implementation paths
Path A — Web Pixel (modern, recommended)
Shopify's Web Pixel sandbox (introduced 2023, expanded through 2024–25) runs third-party tracking scripts in a sandboxed iframe. Benefits:
- Sandboxed execution — pixel can't access cart, customer data, or other apps without explicit permission
- Customer Privacy API integration — automatically respects the visitor's consent state
- Standard events fired automatically — page_viewed, product_viewed, product_added_to_cart, checkout_started, checkout_completed, search_submitted, etc.
- Works on all Shopify plans including Basic
- Survives theme changes — pixel is independent of theme code
- Customer Events API — emit custom events for granular tracking
Setup time: 30–60 minutes for a competent developer.
Path B — theme.liquid + additional_scripts (legacy, avoid for new)
The pre-2023 approach: paste GA4 gtag.js into theme.liquid for storefront pages, and additional_scripts (Shopify Plus only) for the checkout. Or add the same code to checkout.liquid directly (Shopify Plus, deprecated August 2024).
Why avoid:
- Duplicate transactions when run alongside Web Pixel (most stores have both)
- No native consent integration — must wire Customer Privacy API manually
- Theme upgrades break tracking — code lives inside the theme
- No checkout coverage on non-Plus — Shopify Basic/Standard plans can't edit checkout
- Deprecated `checkout.liquid` — Shopify Plus removed direct checkout.liquid editing in August 2024 (existing implementations got migration deadlines)
For existing stores running theme.liquid, the migration path matters — covered below.
Setting up Web Pixel correctly
Step 1 — Configure Customer Privacy API
In Shopify Admin → Settings → Customer privacy:
- Enable Cookie banner if not already running
- Configure regions where consent is required
- Set up consent categories that align with your CMP
The Web Pixel reads the visitor's consent state from this configuration automatically.
Step 2 — Add a Web Pixel through Settings
Two paths:
- Custom Pixel: Settings → Customer events → Add Custom Pixel. Write the pixel code yourself with full control.
- App Pixel: install a Shopify app that provides a managed pixel (e.g., GTM by Stape, GA4 + Google Ads by various vendors).
For most stores, a Custom Pixel with GA4-specific code is cleanest. The minimal setup:
The pixel subscribes to checkout_completed (and other events). Each subscription fires when the corresponding event happens. Shopify handles the timing and consent gating.
Step 3 — Subscribe to all relevant events
Beyond checkout_completed, subscribe to:
page_viewed— every page navigationproduct_viewed— product detail pageproduct_added_to_cart/product_removed_from_cartcart_viewedcheckout_startedcheckout_address_info_submittedcheckout_shipping_info_submittedcheckout_contact_info_submittedpayment_info_submittedsearch_submitted
Each event maps to a standard GA4 e-commerce event. The Web Pixel API handles the timing — you don't need to wait for DOM events or worry about race conditions.
Want to see whether purchase, revenue, or item-level tracking is drifting in your property?
Step 4 — Verify with sandbox console
In Shopify Admin → Customer events → click your pixel → there's a sandbox console showing events firing in real time. Use this to verify the events you subscribed to are firing with the data you expect.
For end-to-end verification, also check GA4 Realtime → confirm purchase events appear with correct transaction_id, value, and items array.
The Shopify Plus checkout.liquid timeline
Shopify Plus historically allowed direct editing of checkout.liquid for custom checkout tracking. The timeline:
- August 2024: Shopify announced
checkout.liquiddeprecation; new Plus stores cannot edit it - 2024–2025: Existing Plus stores given migration window
- 2026: Direct checkout.liquid editing fully removed; all Plus stores must use Web Pixel or Checkout Extensibility
If your Plus store still has GA4 code in checkout.liquid, plan migration before Shopify forces it. The replacement is exactly the Web Pixel approach above — same code, different hosting location.
Migration path from theme.liquid to Web Pixel
For stores running the legacy theme.liquid setup, the migration sequence:
Step 1 — Audit the existing implementation
Identify every place GA4 code currently lives:
theme.liquid(storefront pages)checkout.liquid(Plus only, pre-deprecation)additional_scripts(Plus checkout)- Apps that inject GA4 code (some "Google Analytics for Shopify" apps)
- Manual GTM containers triggering on URL patterns
Document the transaction_id, value, and items array data each location currently sends.
Step 2 — Implement Web Pixel in parallel (don't replace yet)
Add the Web Pixel with all event subscriptions. Verify events fire correctly in the sandbox console. Do not yet remove the theme.liquid code — you want to confirm Web Pixel works first.
Step 3 — Make a test purchase, expect duplicates
With both running, a test purchase will fire two GA4 events for the same transaction_id. This is expected and confirms both are working. Run the BigQuery duplicates query (see *Duplicate Transactions in GA4*) — your test transaction should appear exactly twice.
Step 4 — Remove theme.liquid GA4 code
Once Web Pixel is confirmed working:
- Remove GA4 snippets from theme.liquid
- Remove GA4 code from additional_scripts (Plus)
- Remove any apps duplicating Web Pixel functionality
- Test another purchase — should now fire exactly once
Step 5 — 7-day validation
Wait 7 days post-removal. Run the BigQuery duplicates query for that period — should show no duplicate transaction_ids. Cross-check GA4 revenue against Shopify Admin's sales reports — should match within 1–2%.
What Web Pixel can't do
A few honest limitations:
- No access to cart contents from outside checkout events. If you need to track abandoned cart custom logic, you may need an app or backend integration.
- No access to customer-specific data without permissions. Email and address are available only on relevant events with explicit Customer Privacy permissions.
- Subscribed events only. You can only fire on the events Shopify exposes — can't hook into arbitrary theme JavaScript.
- No DOM access. The pixel runs in a sandbox; no direct manipulation of theme elements.
For most analytics use cases these limits don't matter. For unusual requirements (e.g., custom DOM-event tracking on theme components), you may still need a hybrid approach with theme.liquid for non-checkout tracking + Web Pixel for checkout.
FAQ: Shopify GA4 Setup: Web Pixel vs theme.liquid in
How close should shopify ga4 setup: web pixel vs theme.liquid in numbers be before I worry?
What should I validate first when shopify ga4 setup: web pixel vs theme.liquid in numbers disagree?
When is a discrepancy a tracking bug instead of a reporting difference?
Related guides for Shopify GA4 Setup: Web Pixel vs theme.liquid in
Item Array Integrity: What Stops Items Reporting in GA4 (2026)
Items fail to appear in GA4 e-commerce reports when the items array is missing, malformed, or inconsistent across the funnel. Eight common bugs: (1) missing item_id (the only required field — items without it are dropped), (2) item_id mismatched between view_item and purchase (same product reports as different items)…
Refund Tracking in GA4: The Three Patterns That Work (2026)
GA4 supports refund tracking via the refund event with the same transaction_id as the original purchase. Three implementation patterns: (1) Measurement Protocol from your backend — your order-management system fires a server-to-server refund event when refunds are processed (most reliable, works with any platform)…
Audit Shopify GA4 Setup: Web Pixel vs theme.liquid in before revenue reporting drifts further
Run a free GA4 audit to catch purchase, refund, item-array, and attribution issues before they distort ecommerce decision-making.