Skip to content

Shopify integration

Install PureMetrix on a Shopify storefront: load the cookieless script, wire the custom pixel for pageviews and funnel steps, and send purchase revenue server-side with Shopify’s Order payment webhook (orders/paid). No app, no code and no private key needed.

Prerequisites

  • A PureMetrix site whose hostname matches your store (custom domain or *.myshopify.com).
  • Public key from the app: open the site → Installation & tracking code dialog → tab HTML Script (label Public Key, also in the snippet as data-key).
  • Shopify admin access: Settings → Customer events (custom pixel), theme/app embed, and Settings → Notifications → Webhooks (revenue, step 3).
  • Owner or admin role on the PureMetrix site to save the Shopify signing secret (editors can see the setup page but not change the secret).

1. Load the PureMetrix script

The custom pixel calls window.puremetrix(). Load the tracking script first (snippet or theme app extension) with your domain and public key. If you use a proxy, point to paths on your own domain instead.

<script defer data-domain="your-shop.myshopify.com" data-key="YOUR_PUBLIC_KEY"
  data-api="https://collect.puremetrix.org/api/event"
  src="https://collect.puremetrix.org/js/script.js"></script>

Use your production custom domain in data-domain when that is the PureMetrix site hostname.

2. Add the custom pixel

  1. In Shopify admin open Settings → Customer events and create a custom pixel.
  2. Paste the PureMetrix Shopify pixel from adapters/shopify/pixel.js in the PureMetrix repo.
  3. Connect the pixel and publish it for the storefront.

The pixel subscribes to Shopify analytics events and forwards:

  • page_viewed → pageview
  • product_added_to_cart → Add to cart
  • checkout_started → Begin checkout
  • checkout_completed → Purchase without revenue (funnel coverage only — so the browser and the webhook never double-count amount)

3. Purchase revenue: Shopify webhook

Revenue comes from Shopify itself, not from the browser: every time an order is paid, Shopify sends it to PureMetrix. You set this up once, in two places.

In PureMetrix: copy your webhook URL

  1. Open the site in PureMetrix → Site settings → Shopify.
  2. Copy the webhook URL. It looks like https://collect.puremetrix.org/webhooks/shopify/orders-paid?site=YOUR_PUBLIC_KEY and is unique to this site.

In Shopify: create the webhook

  1. In your Shopify admin, go to Settings → Notifications and click Webhooks.
  2. Click Create webhook.
  3. Event: Order payment. Format: JSON.
  4. URL: paste the webhook URL from PureMetrix. Leave the webhook API version as it is and click Save.

Back in PureMetrix: paste the signing secret

  1. On the same Webhooks page, Shopify shows “Your webhooks will be signed with …” followed by a long code. Copy that code.
  2. In Site settings → Shopify, paste it into Shopify signing secret and click Save secret.

PureMetrix stores the secret encrypted and only shows its last four characters afterwards. It uses the secret to check Shopify’s signature (X-Shopify-Hmac-Sha256) on every delivery, so orders from anyone else are rejected. Each order is counted once, even if Shopify sends it again.

The webhook is the source of truth for revenue.amount and currency on Purchase. Orders are recorded while the site is collecting data; the revenue reports in the dashboard need the Growth plan or higher.

For developers: the older server-to-server option still works: POST https://collect.puremetrix.org/webhooks/shopify/orders-paid (without ?site=) with Authorization: Bearer <SITE_PRIVATE_KEY> or a data-key header, signed with the collect host’s shared Shopify secret. Query ?key= is rejected.

4. Goals in PureMetrix

Create custom event goals for Add to cart, Begin checkout, and Purchase (and enable ecommerce / revenue widgets when your plan includes them — Growth or higher). See ecommerce revenue tracking.

Verify

  1. In a private window, open a collection → product → cart. DevTools → Network should show the script and the event requests.
  2. Dashboard pageviews update within about a minute.
  3. Place a test order, for example with Shopify’s test payment gateway: the pixel may show a Purchase step for the funnel; revenue and AOV appear within a few minutes after Shopify delivers the paid order.
  4. Use a real test order rather than Shopify’s Send test button: the sample order it sends is signed like a real one and would also be counted as a purchase.
  5. No revenue? Check that the URL in Shopify matches the one in Site settings → Shopify exactly and that the saved secret is the code from the same Shopify Webhooks page.

Privacy

PureMetrix does not set visitor cookies. Other Shopify apps may — if so, set up your consent tool (CMP) for them. PureMetrix visitor stats are hosted in the EU on Hetzner.

Related