How to Set Up Purchase Conversions in Shopify

If you run A/B tests on your Shopify store, you need to know which variant actually drives more sales—not just clicks or add-to-carts. Stellar lets you track completed purchases as conversions so you can see real revenue impact. This article walks you through the full setup in three steps: install the snippet, add the pixel, and create the goal.

Quick overview: You'll add the Stellar snippet to your store (for visitor attribution), a Custom Pixel in Shopify (to capture checkout completions), and a Shopify Purchase goal in Stellar. Total setup time is about 10 minutes.

Before You Start

You'll need:

  • A Shopify store
  • A Stellar project with your store domain configured (e.g. yourstore.com)
  • Your Stellar API key — find it in Stellar under your project's domain settings, or when you copy the snippet

Step 1: Install the Stellar Snippet

The Stellar snippet runs on your store pages and attaches a visitor ID to your cart. When a customer completes checkout, Shopify sends that ID with the order—so we can attribute the purchase to the right experiment variant. Without this step, purchases won't be attributed.

  1. In Stellar, go to your project's domain settings and copy your snippet.
  2. In Shopify: Online StoreThemesActionsEdit code
  3. Open theme.liquid and paste the snippet inside the <head> section.
  4. Save your changes.

See our Install Stellar Snippet guide for detailed instructions.

Step 2: Add the Custom Pixel in Shopify

Shopify's Custom Pixels let you run code when checkout completes. We send that purchase event to Stellar so it can be counted as a conversion. Make sure Step 1 is done first—the pixel needs the visitor ID from the snippet.

  1. In Shopify Admin, go to Settings Customer events
  2. Click Add custom pixel
  3. Give it a name (e.g. "Stellar Purchase Tracking")
  4. Paste the following code and replace YOUR_API_KEY with your Stellar API key (from your project's domain settings or the snippet installation screen):

Where to find your API key: In Stellar, go to your project → Domain settings (or the page where you copy the snippet). Your API key is the long encrypted string in the snippet URL.

analytics.subscribe('checkout_completed', (event) => {
  const checkout = event.data?.checkout;
  if (!checkout) return;

  const visitorId = checkout.attributes?.find(
    (a) => a.key === 'stellar_visitor_id'
  )?.value;
  const orderId = checkout.order?.id;

  fetch('https://api.gostellar.app/public/shopify/purchase', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      apiKey: 'YOUR_API_KEY',
      visitor_id: visitorId,
      order_id: orderId,
      shopify: { checkout },
      ts: Date.now(),
    }),
    keepalive: true,
  });
});

The stellar_visitor_id comes from the cart attributes that the Stellar snippet adds when visitors browse your store. This allows us to attribute the purchase to the correct experiment variant.

Important: Without the visitor ID, we cannot attribute the purchase to an experiment. Make sure the Stellar snippet is installed on your store before the pixel.

Step 3: Create the Shopify Purchase Goal

In Stellar, create a conversion goal of type "Shopify Purchase" and attach it to your experiment. This tells Stellar which experiment results to update when a purchase comes in.

  1. In Stellar, go to Conversions (or create a goal when setting up an experiment)
  2. Click Create Conversion
  3. Select Shopify Purchase as the conversion type
  4. Optionally set a Conversion Value (e.g. your average order value) for revenue reporting in the experiment dashboard
  5. Save the goal
  6. Add this goal to your experiment as the main or secondary goal

Once set up, purchases will be attributed to the variant the visitor saw when they completed checkout. You can use the same Shopify Purchase goal across multiple experiments.

Thank You Page Fallback

If your thank you page is on your store domain (not Shopify's checkout domain), you can use a Custom goal as a fallback. Add a script to your thank you page that calls:

window.__stellar.conversion(YOUR_GOAL_ID);

Create a Custom goal, note its ID, and call this when the thank you page loads. This works when the Stellar snippet loads on that page.

Troubleshooting

Purchases not showing up in my experiment

  • Check the snippet: Ensure the Stellar snippet is in theme.liquid and loads on your store pages.
  • Check the pixel: Verify the Custom Pixel is active in Settings → Customer events.
  • Visitor attribution: Purchases without a visitor ID cannot be attributed. The visitor must have visited your store (with the snippet) before checkout.

Duplicate conversions

We deduplicate by order ID. If the same order is sent multiple times (e.g. customer revisits the thank you page), we only count it once.

Content Security Policy

If you have a CSP, ensure api.gostellar.app (or your Stellar API domain) is allowed for fetch requests.

You're All Set

After completing these steps, purchases will flow into Stellar as conversions. You'll see them in your experiment results, including conversion rate and revenue (if you set a conversion value). Run a test order to confirm everything works.

Need help? Contact us at hello@gostellar.app.