# How to track Shopify checkout conversions in A/B tests

// 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:

1. **Visit the storefront in a private window** and make sure you're in the
   experiment, so the Testa script sets the `_testa_uuid` cookie. You can log your
   assignment with the [browser events](/guides/subscribing-to-events).
2. **Place a test order.** Use Shopify's Bogus Gateway or your payment provider's
   test mode.
3. **On the thank-you page, open DevTools → Network** and filter for `pixel`. You
   should see a request with `event=purchase` and your order data.
4. **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](/guides/ab-testing-by-country).

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.
