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 Ads pixel in post-purchase Additional Scripts

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

Dies 2026-08-26

Paste-ready snippet
// Post-purchase remarketing / custom-audience tagging that used to live in
// the "Additional Scripts" box on the Thank You / Order Status page.
analytics.subscribe('checkout_completed', (event) => {
  const { checkout } = event.data;
  if (!checkout) return;

  // Persist a first-party "purchased" flag so future sessions can be
  // excluded from prospecting audiences client-side, mirroring what the old
  // Additional Scripts snippet did with a cookie.
  browser.cookie.set('pp_purchased', '1');

  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,
        action_source: 'website',
        custom_data: {
          value: checkout.totalPrice ? checkout.totalPrice.amount : undefined,
          currency: checkout.totalPrice ? checkout.totalPrice.currencyCode : undefined,
          content_ids: checkout.lineItems.map((i) => i.variant && i.variant.id).filter(Boolean),
        },
      }],
    }),
  });
});

Legacy pattern detected via: Additional[\s\S]{0,120}(fbq\(|connect\.facebook\.net)

What this does NOT cover

What this does NOT cover: post-purchase UPSELL page events (a separate, later checkout_completed-adjacent flow per Shopify docs) — those need their own verification pass. It also does not cover cross-sell/upsell apps that inject their own additional scripts on the same page; each app's script needs its own duplicate-fire audit.

Test-event verification checklist

  • browser.cookie.set() call is awaited-safe (it is a Promise-returning call per the Web Pixels browser API — do not assume it completes synchronously in code that runs after it).
  • Fires on the Thank You / post-purchase page only (checkout_completed), never on the cart or product pages.
  • Duplicate-fire check: if a separate Meta app pixel is ALSO installed via the Shopify admin Pixel Manager, do not run this custom pixel for the same Purchase event — pick one source of truth to avoid double-counted conversions.
  • Verify live against the platform's own test-event tool: https://developers.facebook.com/tools/events_manager/test_events/