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 to 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 to 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.
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
Want to see whether purchase, revenue, or item-level tracking is drifting in your property?
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 to 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.
How to use this in a GA4 audit
Use this topic to support a ecommerce tracking audit and data-layer review. This article covers ecommerce measurement quality, with emphasis on validating transaction integrity before teams trust revenue or merchandising reports. Where possible, separate API-verified findings, browser-verified findings, and findings that depend on access to linked platforms.
What to verify
- Validate purchase, refund, and item-level payloads against the platform or backend order record.
- Check whether currency, value, quantity, and transaction identifiers are populated consistently.
- Confirm attribution and checkout continuity separately from order-system truth.
- Document whether the issue is browser-verified, platform-specific, or dependent on backend access.
Known limitations
- GA4 is useful for attribution and behavioral analysis, but storefront or finance systems may remain the source of order truth.
- Deduplication and refund handling should be tested against the implementation in use, not assumed from a generic pattern.
Before acting on the result
Use the visible evidence behind the finding before changing reporting, bidding, privacy controls, or executive dashboards. GA4 Audits findings should be reviewed by a qualified analyst before major business decisions are made.