Shopify

Storefront, checkout and order events from a Shopify store: the three parts of the integration, the event and property mapping, and what you can wire up today.

A Shopify store produces behaviour in two places that do not see each other: the storefront and checkout, which are in the browser, and orders, refunds and fulfilments, which are facts the platform records server-side. A complete picture needs both, stitched onto one visitor.

Status

The Shopify app is being built. The mapping, the event names and the group key below are settled and will not change; the installable app is not available yet.

The three parts, and why all three

  1. Web Pixel extension. Shopify's sandboxed pixel API is the only supported way to observe storefront and checkout behaviour on modern themes. A script tag in the theme cannot see checkout at all.
  2. Webhooks. The server-side truth. An order that completes after the browser closed, a refund issued from the admin, a fulfilment: none of these produce a browser event, and all of them are what revenue reporting is built on.
  3. The app itself. The OAuth install that registers the webhooks, holds the store's access token and links the store to a Project.

The pixel alone under-reports revenue. The webhooks alone lose the whole funnel before the order.

Events

From the storefront pixel

From webhooks

Checkout Started can arrive from both sides. The webhook is authoritative; the pixel event is what gives you the funnel step in the browser. Keep them distinguishable by their source (web from the pixel, server from the webhook) when you build a funnel, or you will count the step twice.

Properties

Revenue properties are normalised, so a report does not need to know Shopify's field names:

One event from two places

Checkout Started and Order Completed arrive twice on purpose: once from the pixel (instant, in the shopper's browser, source = web) and once from the webhook (the money-authoritative copy, immune to ad blockers, source = server). Funnels and flows can use either. Revenue reports must filter on source = server, or every order counts twice.

Identity and the shop group

  • Who. The distinct id is the Shopify customer id when the customer is known, and a hash of the email address otherwise, so a guest checkout still resolves to one person across orders.
  • Anonymous stitching. The pixel carries the same ip_aid cookie name the web client uses, so storefront, checkout and any events from your own site or app belong to one visitor. If you also run your own client on the same domain, do not rename that cookie.
  • The shop. Every event carries the group shop with the store's myshopify.com domain as the id. One Project can therefore hold several stores and still report on each, and a report can compare them. Declare shop in the Project's group keys. See Identity and merge.

The pixel fires only when Shopify's Customer Privacy API reports that marketing and analytics consent has been granted. That is Shopify's own gate, and it is the one a merchant's cookie banner drives, so a consent choice made in the storefront is respected without anything to configure.

Webhooks are server-side facts about a transaction and are not affected by a browser consent choice.

The three mandatory GDPR webhooks (customers/data_request, customers/redact, shop/redact) are handled by the app; a Shopify listing is rejected without them.

Doing it today, without the app

The routes the app will use are live, so a store can be wired up by hand. Two pieces:

A custom pixel in the Shopify admin (Settings, Customer events, Add custom pixel), with your Project token:

analytics.subscribe('checkout_completed', (event) => {
  const c = event.data.checkout;
  const body = JSON.stringify({
    v: 1,
    token: 'ipa_pub_REPLACE_ME',
    events: [{
      id: event.id,
      ts: new Date(event.timestamp).toISOString(),
      event: 'Checkout Completed',
      aid: event.clientId,
      props: {
        revenue: Number(c.totalPrice.amount),
        currency: c.totalPrice.currencyCode,
        items: c.lineItems.length,
        order_id: String(c.order?.id ?? ''),
      },
    }],
  });
  navigator.sendBeacon(
    'https://t.intelligent.page/v1/ingest',
    new Blob([body], { type: 'text/plain' })
  );
});

Subscribe to as many of the events in the first table as you want. event.id as our id makes a retry idempotent, and the token is in the request body because sendBeacon cannot set headers.

A webhook receiver of your own: verify Shopify's X-Shopify-Hmac-Sha256 against the raw request body before parsing it, ignore a repeated X-Shopify-Webhook-Id, map the order to an event and post it to /v1/ingest with a Server key so the write is trusted and can set did directly. Use the Shopify order id as our id so a Shopify retry does not double-count.

Verify

curl -N https://t.intelligent.page/v1/live -H 'Authorization: Bearer ipa_sec_REPLACE_ME'

Place a test order with that stream open. Check that the pixel event and the webhook event carry the same distinct id: that is the whole point of the integration, and it is the part most likely to be wrong.

Next