We’re upgrading our email infrastructure — for immediate response, email andrewjgaber@gmail.com meanwhile.
Skip to main content
Part of Digital Empire
Meta / Facebook

Meta Pixel fbq('track', 'Purchase') in checkout.liquid

Meta / Facebook · Web Pixels API replacement · confidence: high

Dies 2026-08-26

Paste-ready snippet
// Web Pixels API replacement — subscribe to checkout_completed, which fires
// once per checkout (Thank You page), per Shopify's own docs.
analytics.subscribe('checkout_completed', (event) => {
  const { checkout } = event.data;
  if (!checkout || !checkout.totalPrice) return;

  const value = checkout.totalPrice.amount;
  const currency = checkout.totalPrice.currencyCode;
  const contentIds = checkout.lineItems
    .map((item) => item.variant && item.variant.id)
    .filter(Boolean);

  // Meta's fbq() global does not exist inside the Web Pixels sandbox (no DOM,
  // no window.fbq). Send the event to Meta's Conversions API endpoint via
  // fetch instead — this is the sandbox-correct equivalent of a browser-side
  // fbq('track','Purchase') call. Replace PIXEL_ID and ACCESS_TOKEN with your
  // Meta Pixel ID and a server-side Conversions API access token (Events
  // Manager > Settings > Conversions API).
  fetch(`https://graph.facebook.com/v20.0/PIXEL_ID/events?access_token=ACCESS_TOKEN`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    keepalive: true,
    body: JSON.stringify({
      data: [{
        event_name: 'Purchase',
        event_time: Math.floor(Date.now() / 1000),
        event_id: checkout.token, // dedup key shared with any server-side CAPI call
        action_source: 'website',
        custom_data: {
          value,
          currency,
          content_ids: contentIds,
          content_type: 'product',
        },
      }],
    }),
  });
});

Legacy pattern detected via: fbq\(\s*['"]track['"]\s*,\s*['"]Purchase['"]

What this does NOT cover

What this does NOT cover: the server-side Conversions API purchase call, which is a separate integration merchants must verify independently for event_id dedup against this browser-side fire. It also does not cover Meta events earlier in the funnel (AddToCart, InitiateCheckout) — those need their own templates.

Test-event verification checklist

  • Fires exactly once per completed checkout, on the Thank You page (checkout_completed only fires there, per Shopify docs).
  • event.data.checkout.token is present and used as the Conversions API event_id so this browser-side event dedupes against any existing server-side CAPI Purchase event for the same order.
  • value / currency read from checkout.totalPrice (MoneyV2: amount + currencyCode) and match the Shopify Markets currency shown at checkout, not a hardcoded store currency. Does not fire on cart page, product page, or checkout_started — only checkout_completed.
  • Verify live against the platform's own test-event tool: https://developers.facebook.com/tools/events_manager/test_events/