Here's the full guide. A copy is saved at `resources/evals/20261123-072525-e7c43834/shopify-meta-capi/implementation-guide.md`.
One limit to know about: the reference files for this skill weren't on this machine, and I didn't check Meta's or Shopify's docs live. The platform details below come from what I already know. Anything marked **[verify]** should be checked against current docs during setup.
---
# Cedar & Coil: Shopify → Meta conversion tracking guide (DRAFT)
**Store:** Shopify · **Product:** Arc Clip Lamp ($68) · **Sends to:** Meta (browser Pixel + server-side Conversions API)
**Status:** Draft only. Nothing has been installed, connected or tested. No campaign has launched and there's no performance data yet.
## 1. Recommended architecture: Pixel + Conversions API, with deduplication
```
Browser: Meta Pixel (via Shopify web pixel) Shopify backend: order record (source of truth)
ViewContent / AddToCart / InitiateCheckout / │
Purchase + eventID ───────────┐ ▼
│ Conversions API (server → Meta)
▼ same events + same event_id
Meta Events Manager ◄──┘ (merges duplicates by event_name + event_id)
```
**Why you need both:**
- **The Pixel alone misses events.** Ad blockers stop it loading. Safari and iOS privacy features shorten or remove cookies and click IDs. Some shoppers close the tab before the order page finishes loading. Those sales still happened, but Meta either never hears about them or can't link them to an ad.
- **CAPI alone misses context.** The server can't see browser cookies (`_fbp`, `_fbc`), the page URL or the user agent unless you pass them along. Also, browsing events like ViewContent and AddToCart naturally happen in the browser.
- **Together**, the browser supplies session signals. The server supplies a confirmed order record that blockers can't stop, plus hashed customer details. When both copies of an event share an ID (Section 3), Meta merges them into one.
**What this setup won't do:** it won't count shoppers who decline tracking, and no method should. It also doesn't guarantee any particular amount of recovered attribution. The improvement depends on Cedar & Coil's own traffic and can only be measured after launch.
## 2. Standard events and key parameters
Send the same four events from both the Pixel and CAPI, with identical IDs, values and currency.
| Event | When it fires | Key parameters |
|---|---|---|
| **ViewContent** | Arc Clip Lamp product page view | `content_ids` (must match the catalog), `content_type: "product"`, `content_name`, `value: 68.00`, `currency` |
| **AddToCart** | Cart update confirmed (not just the button click) | `content_ids`, `content_type`, `contents: [{id, quantity, item_price}]`, `value` (price × quantity), `currency` |
| **InitiateCheckout** | Checkout started | `content_ids`, `contents`, `num_items`, `value` (cart subtotal), `currency` |
| **Purchase** | Order confirmed (created or paid) | **Required:** `value`, `currency`. **Strongly recommended:** `content_ids`, `content_type`, `contents`, `num_items`, `order_id`, plus `event_id` for deduplication |
**Parameter rules:**
- **currency** is an ISO 4217 code. I've assumed USD from the $68 price; confirm it in Shopify settings.
- **value** must be a number, like `68.00`, not `"$68"`. Choose one definition for Purchase value and use it in both senders. For example: subtotal after discounts, without tax or shipping. Write the choice down so everyone reads ROAS the same way.
- **content_ids** must match the IDs in your Meta catalog. The Shopify-synced catalog often uses a format like `shopify_US_<productId>_<variantId>` **[verify in Commerce Manager]**.
- Fire Purchase only when the order is confirmed, never on the "Pay now" click.
## 3. How deduplication works between Pixel and CAPI
Meta treats a browser event and a server event as the same event when all of these are true:
- both have the same **`event_name`**
- both have the same **event ID**: `eventID` in the Pixel call, `event_id` in the CAPI payload
- both arrive within Meta's deduplication window, about 48 hours **[verify]**
Meta then keeps one and drops the other.
```js
fbq('track', 'Purchase',
{ value: 68.00, currency: 'USD', content_ids: ['<catalog_id>'], content_type: 'product' },
{ eventID: 'purchase_5551234567890' }); // 4th argument, NOT inside the data object
```
The matching server payload uses `"event_name": "Purchase", "event_id": "purchase_5551234567890"`.
**How to generate the IDs:**
- **Purchase:** use `purchase_<order_id>`. The browser and the server both know the order ID, so each can build the same string on its own. Refreshing the page sends the same ID again, so it does no harm.
- **Other events:** there's no shared server record, so create a UUID in the browser and pass it to the server. The native app handles this for you.
**Common ways deduplication breaks:**
- `eventID` is placed inside the data object instead of the 4th argument
- names or IDs don't match exactly (`Purchase` vs `purchase`, or a missing prefix)
- **two full senders run on the same Pixel**, such as the native app plus a custom CAPI build
- server events arrive late. CAPI rejects events more than about 7 days old **[verify]**
## 4. Preparing customer information for server-side sends
**Clean up each field, then SHA-256 hash it** (lowercase hex output):
| Field | Key | How to clean it up first |
|---|---|---|
| Email | `em` | Trim spaces, lowercase |
| Phone | `ph` | Digits only, with country code; no `+`, spaces or leading zeros (`15551234567`) |
| First/last name | `fn`/`ln` | Lowercase, trim, remove punctuation, UTF-8 |
| City | `ct` | Lowercase, no spaces or punctuation |
| State | `st` | 2-letter code, lowercase |
| Zip | `zp` | Lowercase, no spaces; first 5 digits in the US |
| Country | `country` | 2-letter ISO code, lowercase (`us`) |
| External ID | `external_id` | Shopify customer ID; hashing recommended |
**Send these unhashed:**
- `client_ip_address` and `client_user_agent`. These must be the shopper's, not your server's.
- `fbp`, the value of the `_fbp` cookie
- `fbc`, the `_fbc` cookie, or built from the ad's `fbclid` URL parameter as `fb.1.<ms>.<fbclid>`
**Rules:**
- Hash exactly once. Hashing twice, or hashing data that wasn't cleaned up first, quietly ruins matching.
- An order webhook doesn't include browser cookies or the user agent. In a custom build, capture them in the browser and save them on the cart (for example as cart attributes). The native app does this for you.
- Send only real fields you're allowed to use. Never fill in placeholders.
- Never log raw emails or phone numbers.
- Treat Meta's **Event Match Quality** score as something to diagnose with, not a target to hit.
## 5. Shopify setup path
**Option A: Meta's native sales channel** (the "Facebook & Instagram" app)
- **Setup:** install it, then connect your Business account, Pixel, ad account, Page and catalog. Set data sharing to the highest level ("Maximum" **[verify]**). That turns on CAPI alongside the Pixel, and the app handles deduplication.
- **Pros:**
- free
- Shopify and Meta keep it working through checkout changes, such as the removal of checkout Additional Scripts (26 Aug 2026 for non-Plus stores)
- catalog sync keeps `content_ids` matching automatically
- respects Shopify's consent signals
- no server for you to host
- **Cons:** limited control over payloads and the value definition, and no per-event log of what was sent.
**Option B: Custom build**
- **Browser:** a Customer Events custom pixel (Settings → Customer events) that listens for `product_viewed`, `product_added_to_cart`, `checkout_started` and `checkout_completed`, and sends each with an event ID.
- **Server:** a small service that receives the `orders/paid` webhook, checks its HMAC signature, and posts the event to CAPI.
- **Middle ground:** server-side GTM, or a managed CAPI gateway or app. You get more control than the native app, but pay for hosting or a subscription.
- **Tradeoff:** full control, but you own hosting, secrets, deduplication, consent checks, retries and ongoing upkeep.
**Recommendation: use the native Meta sales channel at maximum data sharing.** For a one-product store that hasn't launched campaigns, it gives you Pixel + CAPI + deduplication + catalog sync for free, with the fewest things that can break. Only consider a custom or managed build if testing (Section 6) shows a gap the app can't close. **Don't add a custom CAPI sender on top of the native app for the same events.** That's how purchases get counted twice.
**Code sketch: server-side Purchase event.** This is a reference for a custom build. Values in `<>` are placeholders, and the API version needs checking **[verify]**.
```js
// Node 18+: called from a verified Shopify orders/paid webhook handler
import crypto from 'node:crypto';
const PIXEL_ID = process.env.META_PIXEL_ID;
const ACCESS_TOKEN = process.env.META_CAPI_TOKEN; // secret store only
const API_VERSION = 'v<XX.0>'; // [verify current]
const sha256 = v => crypto.createHash('sha256').update(v).digest('hex');
const norm = {
email: e => e?.trim().toLowerCase(),
phone: p => p?.replace(/\D/g, '').replace(/^0+/, ''), // must include country code
name: n => n?.trim().toLowerCase().replace(/[^\p{L}\s-]/gu, ''),
city: c => c?.toLowerCase().replace(/[^\p{L}]/gu, ''),
lower: s => s?.trim().toLowerCase(),
zip: z => z?.toLowerCase().replace(/\s/g, '').slice(0, 5),
};
const hashed = v => (v ? [sha256(v)] : undefined);
const attr = (o, k) => o.note_attributes?.find(a => a.name === k)?.value; // browser-captured values
export async function sendPurchase(order) {
// Check stored consent for this order first (Section 7); return early if not granted.
const addr = order.billing_address || order.shipping_address || {};
const items = order.line_items.map(li => ({
id: `<catalog_id_for_variant_${li.variant_id}>`, quantity: li.quantity, item_price: Number(li.price),
}));
const payload = { data: [{
event_name: 'Purchase',
event_time: Math.floor(new Date(order.processed_at || order.created_at).getTime() / 1000),
event_id: `purchase_${order.id}`, // identical to Pixel eventID
action_source: 'website',
event_source_url: attr(order, '_event_source_url') || 'https://<store-domain>/',
user_data: {
em: hashed(norm.email(order.email)),
ph: hashed(norm.phone(order.phone || addr.phone)),
fn: hashed(norm.name(addr.first_name)), ln: hashed(norm.name(addr.last_name)),
ct: hashed(norm.city(addr.city)), st: hashed(norm.lower(addr.province_code)),
zp: hashed(norm.zip(addr.zip)), country: hashed(norm.lower(addr.country_code)),
external_id: order.customer?.id ? [sha256(String(order.customer.id))] : undefined,
client_ip_address: order.browser_ip || undefined, // unhashed
client_user_agent: attr(order, '_client_user_agent'), // unhashed
fbp: attr(order, '_fbp'), fbc: attr(order, '_fbc'), // unhashed
},
custom_data: {
currency: order.currency,
value: Number(order.current_subtotal_price), // your documented value definition
content_type: 'product',
content_ids: items.map(i => i.id),
contents: items,
num_items: items.reduce((n, i) => n + i.quantity, 0),
order_id: String(order.id),
},
}],
// test_event_code: 'TEST12345', // validation only; remove before live traffic
};
const res = await fetch(
`https://graph.facebook.com/${API_VERSION}/${PIXEL_ID}/events?access_token=${ACCESS_TOKEN}`,
{ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) });
const body = await res.json();
if (!res.ok) throw new Error(`CAPI ${res.status}: ${JSON.stringify(body)}`); // retry w/ backoff; same event_id = no dupes
return body; // expect { events_received: 1, ... }
}
```
## 6. End-to-end testing before scaling spend
A tag firing doesn't prove the event arrived at Meta. Check both.
1. **List every sender.** Each event should have exactly one owner. Look for leftover theme pixels, old Additional Scripts, extra apps or Zapier jobs.
2. **Check the browser.** With Meta Pixel Helper, walk through product page → add to cart → checkout. Each event should fire **once**, with the right `content_ids`, `value` and `currency`.
3. **Use Test Events** (in Events Manager). Place a real test order with a 100% discount code or Shopify's Bogus Gateway, using a test email like `tracking-test+<date>@<domain>`. You should see each event from **Browser** and from **Server**, with Purchase deduplicated into one event.
4. **Check the Purchase payload.** The value should match your definition, the currency should be correct, the `content_ids` should match the catalog, and the customer parameters should show as received.
5. **Clear Diagnostics.** Resolve any warnings in Events Manager → Diagnostics, such as missing parameters, dedup problems, catalog ID mismatches or currency errors.
6. **Clean up.** Remove `test_event_code`. Cancel or refund the test orders, and note them so they're left out of reporting.
7. **Reconcile with a small budget.** In the first days, compare Shopify paid orders with the Purchases Meta *received* (Events Manager, not Ads Manager) for the same complete dates and time zone.
- Received purchases should be close to the order count and never above it. A higher count means duplicate senders.
- Ignore the most recent ~72 hours.
- Ads Manager's *attributed* purchases will always be lower than total orders. That's normal attribution, not a bug.
8. **Watch the trends.** Track Event Match Quality and the dedup rate over time, and look into drops.
**Status at hand-over:** one of built / installed / firing confirmed / arrival confirmed / arrival pending (with the check still needed named). **Only scale spend after "arrival confirmed" with deduplication verified.**
## 7. Consent and compliance note
- **Consent comes first.** CAPI is not a way around consent. If a shopper declines tracking, neither the Pixel nor CAPI should send their data.
- Set up Shopify's cookie banner and Customer Privacy settings for the regions you sell to.
- The native app and Customer Events pixels read Shopify's consent signals automatically.
- A custom server must check the stored consent for each order before sending.
- **Regional rules.**
- **EEA/UK:** wait for opt-in before tracking.
- **US states with privacy laws:** honour opt-outs, and consider Meta's Limited Data Use setting (`data_processing_options`) **[verify]**.
- **Tell shoppers.** The privacy policy should say that hashed contact details are shared with Meta for ad measurement and optimisation, and explain how to opt out.
- **Keep data minimal and secure.** Send only what you need. Hash contact details. Keep the CAPI token in a secret store, never in theme code. Don't log raw personal data.
- **No sensitive data.** Never put health or other sensitive information in event parameters or URLs.
- This is practical guidance, not legal advice. Have counsel confirm the rules for each market you sell in.
---
**Hand-over checklist:**
- [ ] Store currency confirmed and Purchase value definition written down
- [ ] Native app connected: Pixel, catalog, Page and ad account
- [ ] Data sharing set to the CAPI level
- [ ] No duplicate senders
- [ ] Consent banner and privacy policy updated
- [ ] Test order seen from Browser + Server and deduplicated
- [ ] Diagnostics clean and test orders cleaned up
- [ ] First-week reconciliation of Shopify orders vs Meta received Purchases
**What's likely to break this later:**
- theme or checkout changes
- Shopify script deprecations (storefront script tags go on 1 March 2027)
- a reinstalled app creating a second pixel
- consent banner changes
- catalog ID changes