Shopify

The A vs B Shopify app is the recommended way to run experiments on a Shopify store. One install gives you the snippet on every storefront page, checkout events from Shopify's sandboxed pixel (where theme scripts are not allowed to run), and server-side order webhooks: so revenue is recorded even when a buyer closes the tab before the confirmation page finishes loading.

What the app installs

The app has three working parts:

  • Theme app extension: injects the A vs B snippet <script> tag into your storefront theme with your snippet key. This is what runs your experiments. It also writes the A vs B visitor ID into a cart attribute named avsb_vid, which is what lets orders be attributed back to the experiment the buyer saw, and keeps the snippet's commerce targeting data up to date automatically (see Commerce targeting data below). No theme code editing needed, and nothing is left behind in your theme if you uninstall.
  • Web pixel: Shopify's sandboxed pixel runs everywhere, including checkout, where theme scripts are forbidden. The pixel subscribes to product_viewed, product_added_to_cart, checkout_started, and checkout_completed and forwards them to A vs B as metric events named shopify:product_viewed, shopify:product_added_to_cart, and so on.
  • Order webhooks: the app subscribes to orders/create, orders/updated, and refunds/create. Every order Shopify records is sent to A vs B server-side, including later edits and refunds, so your revenue metrics reflect net revenue without any storefront code.

Install and connect

1

Install the app

Install A vs B from the Shopify App Store listing. Approve the requested permissions: the app needs read access to orders so it can record revenue.

2

Generate a connect code and link the store

In the A vs B dashboard, open Commerce → Sources → Shopify and click Generate connect code. Then open the A vs B app from your Shopify admin, paste the code into the connect field, and click Connect. The code is single-use and expires after a few minutes, so a code that leaks can't be used to link your store to anyone else's project. (This replaces the older step of pasting your public snippet key to connect.)

3

Enable the app embed in your theme

Go to Online Store → Themes → Customize, open App embeds in the left sidebar, toggle on A vs B, paste your snippet key from Project Settings → Snippet into the embed's AvsB snippet key field, and click Save. This activates the theme extension that loads the snippet on your storefront.

4

Verify

Back in the A vs B dashboard, check Project Settings → Snippet: the installation status turns green once the snippet has been seen on your storefront. The Shopify connection (shop domain and status) appears under Commerce → Sources, and Project Settings → Integrations shows the same status with a link to it.

How order attribution works

When a visitor lands on your storefront, the snippet assigns them a visitor ID and buckets them into any matching experiments. The theme app embed copies that visitor ID into the cart attribute avsb_vid. When Shopify fires the orders/create webhook, A vs B reads avsb_vid from the order's cart attributes and attributes the purchase to that visitor's experiment exposures.

Because the webhook is server-side, this works even when:

  • the buyer never returns to your storefront after paying,
  • the confirmation page is interrupted or blocked,
  • the order is edited or refunded later: orders/updated and refunds/create keep the recorded totals in sync, and refunds reduce net revenue.
Orders without a visitor ID

If an order arrives with no avsb_vid cart attribute (for example, the buyer blocked the snippet, or the order came from a draft order or another sales channel), it is stored as unattributed. Unattributed orders appear in the orders summary under Commerce → Orders but do not affect experiment results.

Double reporting is harmless

Orders are deduplicated by order ID with last-write-wins. If you also call avsb.track.purchase on your confirmation page, or push a GA4 purchase event to the dataLayer, the webhook record simply supersedes it. Nothing is counted twice.

Commerce targeting data

Commerce Conditions (targeting by cart value and products viewed) need the snippet to be told the cart total and product views. On a store with the app installed, the theme app embed wires both automatically:

  • Cart value: the embed watches for cart changes on the storefront (add to cart, quantity updates, removals), reads the new total from Shopify's cart API, and passes it to the snippet via avsb.track.cart. It also reports the current total once on page load, so cart conditions work from the first page of a returning session.
  • Product views: on product pages, the embed reports a view two ways: locally via avsb.recs.trackView (the product's SKU plus its Shopify product type as the category) and server-side via avsb.commerce.productView. Both use the same product-grain identifier, String(product.id) (the value the order webhook stamps on each line item), so recommendations, targeting, and revenue all agree on the product. The local view feeds the Recently viewed recommendation seed and the Products viewed audience condition; the server-side view records a product_view event that also feeds the Viewed together ("customers also viewed") recommendation, with no extra setup. On pages where Shopify does not expose the product object, no view is recorded: the embed never scrapes the page to guess.

Purchase history conditions need no storefront wiring at all: they are built nightly from the order webhooks the app already sends.

Stores not using the app (or non-Shopify platforms) get the same targeting by making the two calls themselves: avsb.track.cart on cart changes and avsb.recs.trackView on product pages.

Checkout events

Shopify does not allow theme scripts to run on checkout pages. The app's web pixel covers this gap: checkout_started and checkout_completed are captured inside Shopify's pixel sandbox and forwarded to A vs B, so you can build funnel and conversion metrics on checkout steps even though the snippet itself never runs there.

Use these as custom event metrics with the event keys shopify:checkout_started and shopify:checkout_completed (and shopify:product_viewed, shopify:product_added_to_cart for the storefront events).

Privacy and compliance

The app declares and handles Shopify's three mandatory compliance webhooks automatically: no setup required. customers/redact erases the named shopper's data, customers/data_request exports it, and shop/redact (sent by Shopify ~48 hours after uninstall) purges all of the store's commerce data. Each is verified, mapped to your project, and turned into an auditable background job.

Disconnect

To disconnect the store, go to Commerce → Sources in the A vs B dashboard, find the Shopify card, and click Disconnect. Uninstalling the app from your Shopify admin has the same effect: the connection is marked uninstalled and the webhooks are deregistered.

Historical orders and experiment data are kept either way; disconnecting only stops new data from flowing.

One store per project

A Shopify store connects to exactly one A vs B project. To run experiments on several stores, create one project per store.

Manual installation (without the app)

If you prefer not to install the app, you can paste the snippet tag into your theme's theme.liquid by hand: see Popular Platforms. You lose checkout events, automatic order webhooks, and refund sync, so you would need to record purchases yourself with avsb.track.purchase on the order status page. The app is the better path for almost every store.

Was this helpful?