How to Add Tracking Scripts to Shopify (2026)

Last updated
•
Expert reviewed
•
5 min read

Key takeaways

  • The recommended method for checkout and purchase tracking is Settings → Customer events (Shopify’s pixel manager).
  • For app-specific scripts, use App Embeds in the Theme Editor rather than manually adding code to theme.liquid.
  • Theme scripts and additional scripts no longer run in checkout or on the thank-you page on any plan, including Plus.
  • Adding scripts directly to theme.liquid is the most powerful but least safe method — duplicate your theme first.

To add tracking scripts to Shopify, use Settings → Customer events for checkout and purchase tracking, App Embeds in the Theme Editor for app scripts, and theme.liquid for anything else that must run on every storefront page. Each method suits a different use case.

How do I add a tracking code to Shopify?

There are three main methods:

  1. Customer Events (pixel manager) - for purchase and checkout event tracking
  2. App Embeds - for app-specific scripts
  3. theme.liquid - for global scripts across all storefront pages (not checkout)

To check that your tags record sales once they are in, see How to Track Conversions in Shopify.


Shopify’s Customer Events system (formerly Shopify Pixels) is the proper place for purchase and checkout event tracking. It works across the entire checkout — including the order status page — on all Shopify plans.

Step 1 - Go to Settings → Customer events

Step 2 - Click Add custom pixel (for custom code) or browse the list of pre-built integrations (Google, Meta, TikTok, Klaviyo, etc.)

Step 3 - For a pre-built integration: click the integration, connect your account, and enable it. Shopify handles the rest.

Step 4 - For a custom pixel: paste your tracking code into the JavaScript editor. Your code runs in a sandboxed environment and has access to Shopify’s standard events (page_viewed, product_viewed, checkout_completed, etc.)

Why this is the recommended approach: Customer Events runs in a privacy-compliant sandbox, respects customer consent settings, and has full access to checkout events that theme.liquid scripts cannot reach.

For custom pixel code and event names, see How to Add Custom Events in Shopify.


Method 2 — App Embeds in the Theme Editor

When you install a Shopify app that includes a JavaScript snippet (like a review widget, live chat, or loyalty program), the correct way to enable it is through App Embeds:

Step 1 - Go to Online Store → Themes → Customize

Step 2 - Click the puzzle piece icon in the left sidebar (App Embeds)

Step 3 - Toggle on the app you want to enable

This method keeps app scripts organized, makes it easy to enable/disable without touching code, and avoids leftover script tags if you later uninstall the app.


Method 3 — theme.liquid (for global scripts)

For scripts that need to run on every page of your store (excluding checkout), you can add them directly to theme.liquid.

Step 1 - Go to Online Store → Themes, click the three-dot menu (…) next to your theme, then Edit code

Step 2 - Open theme.liquid

Step 3 - Add scripts in the <head> section (for scripts that must load early) or just before the closing </body> tag (for non-critical scripts)

Always duplicate your theme first. A syntax error in theme.liquid breaks your entire storefront.

Use defer or async on script tags where possible to avoid blocking page rendering:

<script src="https://example.com/script.js" defer></script>

How do I add a script in Shopify to the checkout page?

All plans, including Plus: theme scripts and additional scripts no longer run in checkout or on the thank-you page. checkout.liquid is switched off, and the Additional scripts field is view-only (Plus since August 2025, all plans since August 2026).

Use Customer Events (custom or app pixels) for tracking, and checkout UI extensions for anything shoppers see.

Moving off checkout.liquid? See checkout.liquid to checkout extensions.


Common tracking script mistakes

Installing a pixel twice. If you use Shopify’s native Meta integration AND paste the Meta Pixel code manually into theme.liquid, purchase events will fire twice. Use one method only.

Missing consent management. If you operate in the EU or California, you need a consent banner and your tracking scripts should only fire for consenting users. The Customer Events system handles this properly when configured correctly.

Scripts blocking page load. Render-blocking scripts in <head> delay your page from displaying. Add async or defer attributes to any non-critical tracking scripts.

For slow-loading tags, see How to Fix Render-Blocking Scripts in Shopify.

Build the page elements you're tracking by describing them to Fudge.
Start free trial

Using Google Tag Manager as a single source of truth

Rather than adding multiple tracking scripts directly to Shopify, many stores use Google Tag Manager (GTM) as a container. You add the GTM snippet once to theme.liquid, then manage all other tracking scripts inside GTM.

Benefits: no code changes needed when adding or modifying tracking, easier to add/remove scripts for non-developers, built-in debugging tools.

See our full guide: How to add Google Tag Manager to Shopify.


FAQ

Should I use Customer Events or theme.liquid for tracking?

Customer Events for any tracking that needs checkout coverage (purchase events, conversions, ad pixels). theme.liquid for scripts that only need to run on storefront pages and don't need checkout access. Most stores end up using both - Customer Events for conversion tracking, theme.liquid (or GTM) for storefront analytics and heatmaps.

Why does Shopify limit checkout script access?

Security and consistency. Allowing arbitrary third-party scripts on the checkout page creates risk of payment-flow tampering and PCI compliance issues. The Customer Events sandbox lets you run JavaScript in a safe environment with the same effective access for tracking purposes - just not direct DOM access.

Can I add tracking scripts via Shopify apps instead of theme.liquid?

Yes - many ad platforms and analytics tools have official Shopify apps that handle the script injection through App Embeds, which is the cleanest path. Pre-built Customer Events integrations also handle this. For custom tracking that doesn't have an official app (bespoke dataLayer events, scoped click handlers, custom conversion fires), describe what you want to Fudge, the AI operator for Shopify stores, and it writes the tracking code into your theme as a draft you review before it goes live.

Will adding tracking scripts hurt my Shopify Lighthouse score?

It can. Each tag adds JavaScript that takes time to parse and execute. Use defer or async on every external script reference, and prefer the Customer Events sandbox (which runs out-of-band from the main page render). Audits with WebPageTest or Lighthouse will show which specific scripts are the bottleneck.

How do I check which tracking scripts are actually firing on my store?

Open the page in Chrome DevTools → Network tab → filter by your tracking domain (e.g., google-analytics, facebook). You'll see each request the page makes to those services. For Customer Events specifically, the live event feed in Settings → Customer events shows which pixels are firing in real time.

Jacques's signature
Add conversion elements to your Shopify store by describing them.

You might also be interested in

Jacques Blom
Jacques Blom
CTO at Fudge.