How to track Shopify checkout conversions in A/B tests
Track purchases on Shopify's checkout and thank-you pages with a Customer Events pixel, so revenue flows into your A/B test results.
By the Testa teamUpdated 3 min readView as Markdown
If you A/B test a Shopify store, the conversion you care about most, the completed order, happens on the one page your test script can't reach. Shopify's checkout and thank-you (order status) pages run in a locked-down environment. Theme code and normal site scripts don't run there, and that includes your A/B testing snippet.
The fix is Shopify's Customer Events: a custom pixel that runs in a sandbox during checkout and can send events to Testa. This guide sets one up for purchases, adds funnel steps such as add-to-cart and checkout started, and shows how to test it before you trust the numbers.
Why checkout tracking needs a separate pixel
Shopify has moved all stores to Checkout Extensibility. Custom code in
checkout.liquid and the old "additional scripts" box on the order status page
have been retired. Scripts that touch checkout now have to run as web
pixels, in a sandbox that:
- can't read or change the checkout page itself,
- can subscribe to standard events such as
checkout_completed, - can read cookies through
browser.cookie.get, and - can make network requests with
fetch.
That is everything you need: the pixel reads the visitor's Testa ID from the
_testa_uuid cookie, which the Testa script set on the storefront, and sends
the conversion to Testa with it. Testa then attributes the purchase to the
variation that visitor saw.
Step 1: create the goals in Testa
Each event you send must match a custom event goal on your experiment. In the experiment's goals, add a Custom Event goal for each step you want to measure, for example:
| Goal name | Custom event name |
|---|---|
| Purchase | purchase |
| Checkout started | initiate_checkout |
| Added to cart | add_to_cart |
The event name in the pixel code must be identical to the name in the dashboard. See goals for details on custom events.
Step 2: add the custom pixel in Shopify
In your Shopify admin, go to Settings → Customer events → Add custom pixel,
name it "Testa" and paste the code below. Replace <your-project-uuid> with
your Testa project ID, which is the id in your script URL
(/projects/<uuid>.js).
// Your Testa project UUID
var TESTA_PROJECT = "<your-project-uuid>";
// Send one event to Testa for the current visitor.
function sendToTesta(eventName, data) {
browser.cookie.get("_testa_uuid").then(function (uuid) {
if (!uuid) return; // visitor never saw the storefront script: skip
var url =
"https://new.testa-soft.tech/api/pixel" +
"?uuid=" + encodeURIComponent(uuid) +
"&event=" + encodeURIComponent(eventName) + // must match your goal
"&project=" + encodeURIComponent(TESTA_PROJECT) +
"&data=" + encodeURIComponent(JSON.stringify(data || {})) +
"&_t=" + Date.now();
fetch(url, { method: "GET", keepalive: true });
});
}
// Completed order (thank-you / order status page)
analytics.subscribe("checkout_completed", function (event) {
var checkout = event.data.checkout;
sendToTesta("purchase", {
order_id: checkout.order && checkout.order.id,
amount: checkout.totalPrice && checkout.totalPrice.amount,
currency: checkout.currencyCode,
});
});
// Funnel steps (optional)
analytics.subscribe("checkout_started", function () {
sendToTesta("initiate_checkout");
});
analytics.subscribe("product_added_to_cart", function (event) {
var line = event.data.cartLine;
sendToTesta("add_to_cart", {
product: line && line.merchandise && line.merchandise.product.title,
quantity: line && line.quantity,
});
});Save the pixel, then click Connect to activate it.
Customer privacy settings
When you create the pixel, Shopify asks which customer permission it requires. Choose the one that matches how your store handles analytics consent. If the pixel requires consent the visitor hasn't given, Shopify won't run it and those conversions won't be recorded.
Step 3: test it before you trust it
Never launch a revenue test on an untested pixel. To check it:
- Visit the storefront in a private window and make sure you're in the
experiment, so the Testa script sets the
_testa_uuidcookie. You can log your assignment with the browser events. - Place a test order. Use Shopify's Bogus Gateway or your payment provider's test mode.
- On the thank-you page, open DevTools → Network and filter for
pixel. You should see a request withevent=purchaseand your order data. - Check the experiment's results in Testa and confirm the purchase is attributed to your variation.
If no request appears, check that the pixel is connected, that customer
consent isn't blocking it, and that the storefront actually set the
_testa_uuid cookie.
Other Shopify events you can track
The pixel can subscribe to any of Shopify's standard customer events. The ones most useful for A/B tests:
| Shopify event | What it measures |
|---|---|
page_viewed | Any storefront or checkout page view |
product_viewed | Product detail page views |
product_added_to_cart | Add-to-cart actions |
checkout_started | The visitor reached checkout |
payment_info_submitted | The visitor entered payment details |
checkout_completed | The order was placed |
For each one, subscribe with analytics.subscribe(...) and call
sendToTesta("<goal name>", {...}), then create a matching custom event goal in
Testa.
What to test on a Shopify store
With purchases tracked, you can run the tests that matter most for ecommerce revenue:
- Free-shipping threshold banners. Measure both conversion rate and average order value.
- Product page layout. Image gallery, reviews placement, sticky add-to-cart.
- Cart drawer versus cart page. Measure both checkout started and purchase.
- Pricing and bundles. Charm pricing, bundle discounts, "subscribe & save" defaults.
- Market-specific offers. Combine with country targeting.
Always use purchase as the primary goal for these tests. Add-to-cart rates often go up for changes that don't increase revenue.
FAQ
Why not just use a page-view goal on the thank-you page?
The Testa storefront script can't run on Shopify's thank-you page, so a page-view goal there would never fire. The custom pixel is the only reliable way to record the purchase.
Will this double-count purchases if the customer reloads the thank-you page?
No. Shopify fires checkout_completed once per checkout, regardless of
reloads. If you use post-purchase upsells, it fires on the first upsell page
instead of the thank-you page. Goals in Testa also count once per visitor, so a
repeated event wouldn't inflate conversions anyway.
Does this work with Shopify Plus and non-Plus stores?
Yes. Customer Events and custom pixels are available on all Shopify plans.
Can I track revenue, not just conversions?
Yes. The purchase event above sends the order amount and currency with every conversion.
Run this test in Testa
Launch experiments without rebuilding your site, and see which variation actually drives revenue.
Start testing with TestaTalk to us