Platform guides Doc #4 Reviewed Nov 1, 2026

Shopify: purchases with Customer Events

Send Shopify purchases to your Anacoic gateway with a Customer Events custom pixel, the replacement for checkout Additional scripts

Shopify is retiring Additional scripts on the order status page. Its replacement for tracking is Customer Events: small pieces of code, called custom pixels, that Shopify runs on every page including checkout. This guide adds one that sends each completed purchase to your Anacoic gateway (Fix).

For the storefront snippet and the older methods, see Shopify: gateway setup.

Why ana.js isn’t used here

Shopify runs custom pixels in a sandbox, apart from the page. Inside it there is no document.cookie, no window.Shopify.checkout and no real page address, which are what ana.js reads. So the pixel builds the event itself from what Shopify hands it, and sends it straight to the gateway.

What you need

  • A Shopify store with access to Settings → Customer events
  • An Anacoic gateway and its gateway ID (open the gateway in Fix, then the Setup tab)
  • If domain locking is on: your store’s domains in the gateway’s allowed domains (see Domain locking)

Step 1: add a custom pixel

  1. In the Shopify admin, go to Settings → Customer events.
  2. Choose Add custom pixel and name it “Anacoic”.
  3. Under Customer privacy, set Permission to Required and tick Marketing and Analytics. Shopify then only runs the pixel for visitors who allowed both. The code below checks again, so it stays safe if someone changes this setting later.
  4. Paste the code from step 2 into the code box.
  5. Choose Save, then Connect.

Step 2: the code

Replace YOUR_GATEWAY_ID with your gateway ID. If your gateway runs on a custom domain, change GATEWAY_URL to it, for example https://track.yourstore.com/track.

const GATEWAY_URL = 'https://edge.anacoic.com/track';
const GATEWAY_ID = 'YOUR_GATEWAY_ID';

// Consent: what the visitor allowed when the pixel started, kept up to date below
let privacy = init.customerPrivacy || {};
const allowed = () => Boolean(privacy.analyticsProcessingAllowed && privacy.marketingAllowed);

// A purchase that happened before the visitor answered the consent banner waits here
let waiting = null;

const privacyApi = (typeof api !== 'undefined' && api.customerPrivacy) || null;
if (privacyApi) {
  privacyApi.subscribe('visitorConsentCollected', (event) => {
    privacy = event.customerPrivacy || {};
    if (waiting && allowed()) {
      send(waiting);
      waiting = null;
    }
  });
}

function send(payload) {
  fetch(GATEWAY_URL, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json', 'X-Gateway-ID': GATEWAY_ID },
    body: JSON.stringify(payload),
    keepalive: true,
  }).catch(() => {});
}

analytics.subscribe('checkout_completed', async (event) => {
  const checkout = event.data.checkout;
  const page = event.context.document;

  // Meta and TikTok browser cookies, read through Shopify's sandbox API
  const [fbp, fbc, ttp] = await Promise.all([
    browser.cookie.get('_fbp'),
    browser.cookie.get('_fbc'),
    browser.cookie.get('_ttp'),
  ]);

  const items = (checkout.lineItems || []).map((item) => ({
    id: item.variant && item.variant.id,
    quantity: item.quantity,
    item_price: item.variant && item.variant.price ? item.variant.price.amount : undefined,
    title: item.title,
  }));

  const payload = {
    event_name: 'Purchase',
    // Shopify's ID for this event: the platforms use it to recognise the same event sent twice
    event_id: event.id,
    timestamp: Math.floor(new Date(event.timestamp).getTime() / 1000),
    user: {
      email: checkout.email || undefined,
      phone: checkout.phone || undefined,
      fbp: fbp || undefined,
      fbc: fbc || undefined,
      ttp: ttp || undefined,
      client_user_agent: event.context.navigator.userAgent,
      event_source_url: page.location.href,
    },
    context: {
      url: page.location.href,
      referrer: page.referrer,
      title: page.title,
    },
    custom_data: {
      order_id: checkout.order && checkout.order.id,
      value: checkout.totalPrice && checkout.totalPrice.amount,
      currency: checkout.currencyCode,
      content_type: 'product',
      content_ids: items.map((item) => item.id),
      contents: items,
      num_items: items.reduce((sum, item) => sum + (item.quantity || 0), 0),
    },
  };

  if (allowed()) send(payload);
  else waiting = payload;
});

What it sends:

FieldFrom Shopify
event_nameAlways Purchase
event_idevent.id, used for deduplication
custom_data.order_idcheckout.order.id
custom_data.value, currencycheckout.totalPrice.amount, checkout.currencyCode
custom_data.contentsThe line items: variant ID, quantity, price and title
user.email, user.phoneFrom the checkout. The gateway hashes them with SHA-256 before anything leaves it
user.fbp, user.fbc, user.ttpThe _fbp, _fbc and _ttp cookies, when the visitor has them
context.url, user.event_source_urlThe checkout page’s address

The gateway adds the visitor’s IP address itself. If your product catalogue uses product IDs rather than variant IDs, change item.variant.id to item.variant.product.id.

Step 3: check it works

  1. In Customer events, open the Anacoic pixel and choose Test, or place a test order on your store.
  2. In Anacoic, open the gateway’s Overview: a Purchase event should show in the live stream within a few seconds.
  3. Open Diagnostics, then Delivery log, to see how each platform answered.

Nothing arriving? Open your browser’s developer tools on the order status page and look in the Network tab for a request to /track. A 403 answer usually means domain locking (next section).

Domain locking

Requests from a custom pixel come from Shopify’s sandbox, so the browser marks their origin as null instead of your store’s address. When domain locking is on, the gateway then checks the page address the pixel sends (context.url) against your allowed domains instead. So:

  • Add the domain your checkout runs on, for example yourstore.com, under Diagnostics → Security controls.
  • If your checkout still uses the yourstore.myshopify.com address, add that too.

A request whose addresses are none of your allowed domains is still refused.

Deduplication

If Shopify’s own Meta or TikTok channel also sends purchases, the platforms see two copies of each order with different IDs. Turn on one path per platform, or use the gateway alone for purchases, so each order is counted once.