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', 'AddToCart') outside sandbox

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

Not deadline-gated — duplicate-firing / hygiene fix

Paste-ready snippet
analytics.subscribe('product_added_to_cart', (event) => {
  const { cartLine } = event.data;
  if (!cartLine) return;

  const value = cartLine.cost.totalAmount.amount;
  const currency = cartLine.cost.totalAmount.currencyCode;
  const variant = cartLine.merchandise;

  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: 'AddToCart',
        event_time: Math.floor(Date.now() / 1000),
        action_source: 'website',
        custom_data: {
          value,
          currency,
          content_ids: variant && variant.id ? [variant.id] : [],
          content_type: 'product',
          contents: [{ id: variant && variant.id, quantity: cartLine.quantity }],
        },
      }],
    }),
  });
});

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

What this does NOT cover

What this does NOT cover: server-side Conversions API dedup for AddToCart — only the browser-side pixel call is replaced here, and a matching CAPI event must be verified independently. It also does not cover ViewContent or other funnel-stage Meta events, which each need their own migration snippet.

Test-event verification checklist

  • Fires once per add-to-cart action, matching cartLine.quantity to the quantity actually added.
  • value/currency read from cartLine.cost.totalAmount (line total, not per-unit price) so it matches what fbq AddToCart historically reported.
  • Does NOT double-fire: this migration REPLACES the theme.liquid fbq() call — the old script tag must be deleted, not left running alongside this pixel, or Meta will see two AddToCart events per action. This finding is not Aug-26-gated — it is a duplicate-firing correction, safe to ship on any timeline. Verify no second fbq AddToCart source remains in the theme before removing the old script.
  • Verify live against the platform's own test-event tool: https://developers.facebook.com/tools/events_manager/test_events/