If you look after a Shopify store that was customised a few years ago, there is a good chance its purchase tracking lived in one of two places: a <script> block in checkout.liquid (Plus stores) or the "additional scripts" box on the Thank you page. Both are gone. checkout.liquid stopped working on the information, shipping and payment steps on 13 August 2024, and the additional scripts box became view-only on 28 August 2025.
The replacement is pixels: app pixels from analytics and ad platforms, and custom pixels for anything else. This post walks through moving one hand-written purchase tag to a custom pixel, testing it, and avoiding the two mistakes I see most often (double counting and silent breakage).
Where pixels live
In the Shopify admin go to Settings → Customer events. App pixels (Google, Meta, TikTok and so on) appear there when you install the matching sales channel or app. Custom pixels are created with Add custom pixel, which gives you a code editor and privacy settings.
Two things are different from the old world:
-
A custom pixel runs in a sandbox. It cannot read or change the checkout page's DOM. You get events and their data, not
document.querySelector. -
It reacts to events. Instead of running once when the page loads, you subscribe to standard events such as
page_viewed,product_added_to_cart,checkout_startedandcheckout_completed.
Step 1: write down what the old tag sent
Before deleting anything, open the old snippet and list the fields it sent. A typical one sent an order ID, the total, the currency and maybe a list of SKUs. Keep this list, because it is your test plan.
Step 2: the custom pixel
Here is a minimal pixel that sends a purchase to your own collector endpoint:
analytics.subscribe("checkout_completed", (event) => {
const checkout = event.data.checkout;
const payload = {
order_id: checkout.order && checkout.order.id,
value: checkout.totalPrice && checkout.totalPrice.amount,
currency: checkout.currencyCode,
items: (checkout.lineItems || []).map((li) => ({
sku: li.variant && li.variant.sku,
quantity: li.quantity,
price: li.variant && li.variant.price && li.variant.price.amount,
})),
sent_at: event.timestamp,
};
fetch("https://collect.example.com/purchase", {
method: "POST",
keepalive: true,
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
});
A few notes:
- Defensive access. Not every checkout has every field (digital products have no shipping lines, a free order may have a zero total). Guard each property instead of assuming it exists.
-
keepalive: truelets the request finish if the customer closes the tab straight after the Thank you page appears. - No secrets in the pixel. The code is delivered to the browser. If your collector needs authentication, check requests server-side (origin, rate limits, a shared non-secret site key) rather than shipping an API key.
If the tool you are replacing is Google Ads, Meta or another major platform, check for an official app pixel first. Use a custom pixel only for what no app covers.
Step 3: privacy settings
Each custom pixel has a permission setting that controls whether it runs before a visitor gives consent. Match it to your cookie banner and the laws where you sell: GDPR and UK GDPR for European and UK visitors, provincial and federal rules in Canada, state laws in the US. If you are unsure, the stricter setting is the safer default, and your marketing team should know that consent affects how many purchases are reported.
Step 4: de-duplicate on the server
checkout_completed is the event to use for purchases, but don't assume every request you receive is a new sale. Customers reload pages, browsers retry, and you may still have an app pixel reporting the same order. Make your collector idempotent:
# collector (Flask-style sketch)
seen = set() # use a database table with a unique index in production
@app.post("/purchase")
def purchase():
data = request.get_json(force=True)
oid = str(data.get("order_id") or "")
if not oid:
return ("missing order id", 400)
if oid in seen:
return ("duplicate", 200)
seen.add(oid)
save_purchase(data)
return ("ok", 201)
A unique index on order_id does the same job in SQL and survives restarts.
Step 5: test like a customer
- Turn on a test payment method (Shopify's test gateway or your provider's test mode).
- Open the store in a private window, accept or decline cookies as a real visitor would, and place an order.
- In DevTools, filter the Network tab by your collector's domain. The pixel runs inside a sandboxed frame, so filtering by URL is easier than hunting through frames.
- Check the payload against the list from step 1: order ID, total, currency, items.
- Reload the Thank you page and confirm your collector reports a duplicate rather than a second sale.
- Repeat with a discount code, a second currency if you use Shopify Markets, and a mobile browser.
Only when the numbers match should you remove the old snippet's references from your documentation and tag manager.
Common mistakes
- Copying the old script line by line. Anything that touched the DOM (reading the order total from a heading, injecting a survey) needs a different approach: a checkout UI extension or an app block on the Thank you page.
- Forgetting the other markets. Prices and currency codes change per market. Test at least one non-default currency.
- No owner. A pixel nobody watches breaks quietly. Add a daily check that compares collector purchases with Shopify's own order count.
Where this fits in a bigger checkout project
Tracking is usually one item on a longer list: discount logic that moved from Shopify Scripts to Functions, fields that need a checkout UI extension (a Plus feature on the information, shipping and payment steps), and branding in the checkout editor. If your team would like help planning that list, our Shopify development team works with stores in the USA, UK, Canada and Australia.
FAQ
Can a custom pixel change what the customer sees in checkout?
No. Pixels only observe events. Visible changes need the checkout editor, app blocks or checkout UI extensions.
Do I need Shopify Plus for custom pixels?
No. Custom pixels are available under Customer events on standard plans as well as Plus.
Should I keep the old tracking code "just in case"?
It no longer runs in checkout, so it only causes confusion. Archive a copy in your repository, then remove it.
What about server-side conversion APIs?
They complement pixels well, especially for ad platforms. Send the same order ID from both so the platform can de-duplicate.
Originally published on the Dzimark blog.
Top comments (0)