# Cedar & Coil draft implementation guide: Shopify → Meta conversion tracking
## 1. Recommended architecture: Meta Pixel + Conversions API
Use Shopify’s **Facebook & Instagram by Meta** sales channel to connect the Arc Clip Lamp store to one Meta dataset. Start with the native integration rather than running a separate Pixel or server implementation alongside it.
- **Browser — Meta Pixel:** Records product views, cart actions, checkout starts, and purchases when the browser and the shopper’s consent choices permit it. It also captures browser context that can help Meta match events.
- **Server — Conversions API (CAPI):** Sends supported commerce events directly from Shopify’s servers to Meta. The server path is particularly valuable for `Purchase`: it does not depend on a browser script running on the order confirmation page.
- **Deduplication:** When both paths report the same action, Meta should count it once. Both paths must use the same dataset, event name, and event ID.
The two paths are complementary. CAPI reduces dependence on browser delivery, but it does not bypass consent, guarantee a match to a Meta account, or guarantee ad attribution. An event received by Meta is not necessarily a conversion attributed to an ad.
## 2. Standard events and parameters
Use Meta’s standard event names exactly as written. For every `content_ids` entry, use the **exact item ID in the connected Meta catalog**. Check the catalog before choosing an identifier: a Shopify product ID, variant ID, SKU, and Meta catalog item ID are not necessarily interchangeable.
| Event | When to send | Key parameters |
|---|---|---|
| `ViewContent` | The Arc Clip Lamp product detail page is viewed. | `content_ids` for the viewed item, `content_type: "product"`, `value` for the displayed item price, and `currency`. |
| `AddToCart` | The item is successfully added, not just when someone clicks the button. | `content_ids`, `content_type`, `contents` with item IDs and quantities added, `value` for the items added in that action, and `currency`. |
| `InitiateCheckout` | The shopper starts checkout. | All checkout item IDs in `content_ids`, `content_type`, `contents` with quantities, `num_items` as the sum of quantities, checkout `value`, and `currency`. |
| `Purchase` | An order meets the store’s chosen purchase milestone. For a custom build, use the same milestone on both paths. | **`value`**, **`currency`**, and **`content_ids`** for all purchased items; also send `content_type` and `contents` with quantities and item prices. An `order_id` can help with reconciliation but is not the deduplication key. |
Send `value` as a number in major currency units and `currency` as an uppercase ISO 4217 code, such as `USD`. For `Purchase`, use the actual order amount and currency, not a hard-coded `68`. Document how your reporting treats discounts, shipping, and tax, and verify the resulting value against Shopify. A single lamp with a final total of $68.00 USD should arrive as `value: 68` and `currency: "USD"`.
## 3. How Pixel–CAPI deduplication works
Meta matches browser and server copies when they arrive at the **same dataset** with the **same event name** and the **same event ID** within its deduplication window, documented as 48 hours. Send both promptly; don’t use that window as a delivery target.
For one purchase, the browser call might look like:
```js
fbq("track", "Purchase", purchaseParams, {
eventID: "purchase:1234567890"
});
```
The corresponding CAPI event must include:
```json
{
"event_name": "Purchase",
"event_id": "purchase:1234567890"
}
```
`eventID` is the Pixel option; `event_id` is the top-level CAPI event field. In a custom build, derive the ID on both sides from the same canonical order identifier, or pass a shared ID between them. Normalize the identifier consistently: a Shopify order GID on one side and its numeric suffix on the other will not match unless you convert them to the same format.
Reuse the ID for webhook retries and confirmation-page reloads, and use a different ID for each distinct purchase. Don’t generate independent random IDs in the browser and server, or rely on `order_id`, email, or matching order values to deduplicate. Also make the server delivery idempotent so webhook redelivery does not trigger a fresh conversion. With the native integration, let the app own the IDs; don’t add another `Purchase` sender.
## 4. Preparing customer information for CAPI
Send only customer information you’re permitted to use for advertising measurement. In a custom implementation:
- **Normalize, then SHA-256 hash** fields Meta expects hashed. For `em`, trim surrounding whitespace and lowercase the email. For `ph`, include the country calling code and strip the `+`, spaces, and punctuation so only digits remain. If using other supported fields, apply Meta’s field-specific normalization rules before hashing. Hash once; omit missing or invalid fields rather than hashing empty strings.
- **Do not hash** `fbp`, `fbc`, `client_ip_address`, or `client_user_agent`. If collected and permitted, pass the browser identifiers in Meta’s expected format. Don’t fabricate `fbc` when there’s no genuine Meta click identifier. If you send IP and user agent, use the shopper’s actual browser context, not the Shopify webhook sender’s or your worker’s.
- Keep raw customer data, hashed identifiers, and access tokens out of routine logs. Sanitize `event_source_url` so it does not expose customer details or checkout secrets. Treat hashes as customer data, not as anonymous data.
The native app handles payload preparation. Your job is to verify its settings and consent behavior, not to pre-hash Shopify customer records.
## 5. Shopify setup: native app vs. custom implementation
### Recommended for Cedar & Coil: the native Meta sales channel
1. In **Shopify Admin → Sales channels**, open **Facebook & Instagram**. If it isn’t installed, add **Facebook & Instagram by Meta** from the Shopify App Store.
2. Complete onboarding and connect the correct Meta business portfolio, ad account, catalog, and dataset/Pixel. Record the dataset ID and confirm it is the one the ad account will use.
3. In **Facebook & Instagram → Settings → Data sharing settings**, enable customer data sharing and select the connected dataset. Choose **Maximum** if approved under Cedar & Coil’s consent and data-use policy. Shopify offers **Standard**, **Enhanced**, and **Maximum**; verify the current description in the app and confirm server-side `Purchase` in Events Manager. Don’t assume every funnel event will be sent by both paths.
4. In **Shopify Admin → Settings → Customer privacy**, configure the applicable regions and consent experience. If using a third-party banner, confirm that it integrates with Shopify’s customer privacy controls.
5. Audit **Settings → Customer events**, theme scripts, tag managers, and existing apps for duplicate Meta senders. Retire redundant senders after confirming the native connection works. Check that the Arc Clip Lamp’s catalog item ID matches the ID sent in events.
### When to build a custom integration
Build custom only if you need something the native app can’t support, such as a different purchase milestone or checkout flow. Use Shopify’s **Customer Events / Web Pixels** for supported browser events rather than injecting checkout theme scripts. On the server, verify Shopify webhook signatures against the raw request body and queue eligible orders for delivery. Make sure the worker can retrieve the consent decision associated with that checkout; a webhook is not evidence of consent.
For example, if `Purchase` means **payment confirmed**, use the paid-order webhook. Send a browser copy only if the browser can confirm that same milestone and use the same order ID. For delayed payments, an eligible server-only `Purchase` is better than a premature browser event at checkout completion.
**Draft code sketch — custom path only. Do not deploy alongside the native Purchase sender.** The worker below assumes a verified webhook, a normalized order record, and an eligibility decision tied to the checkout.
```js
async function sendPurchase(order, consent, match, testEventCode) {
if (!consent.metaMeasurementAllowed || !order.paidAt) return;
const sha256 = s => createHash("sha256").update(s, "utf8").digest("hex");
const email = match.email?.trim().toLowerCase();
const user_data = {
...(email ? { em: [sha256(email)] } : {}),
...(match.fbp ? { fbp: match.fbp } : {}),
...(match.fbc ? { fbc: match.fbc } : {})
};
if (!Object.keys(user_data).length) return;
const event = {
event_name: "Purchase",
event_time: Math.floor(Date.parse(order.paidAt) / 1000),
event_id: `purchase:${order.canonicalId}`, // Same ID on Pixel, if sent
action_source: "website",
event_source_url: order.sanitizedSourceUrl,
user_data,
custom_data: {
order_id: order.canonicalId,
value: order.totalInMajorUnits,
currency: order.currency,
content_type: "product",
content_ids: order.lines.map(line => line.metaCatalogId),
contents: order.lines.map(line => ({
id: line.metaCatalogId,
quantity: line.quantity,
item_price: line.unitPriceInMajorUnits
}))
}
};
const response = await fetch(
`https://graph.facebook.com/${GRAPH_API_VERSION}/${DATASET_ID}/events`,
{
method: "POST",
headers: {
Authorization: `Bearer ${CAPI_ACCESS_TOKEN}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
data: [event],
...(testEventCode ? { test_event_code: testEventCode } : {})
})
}
);
const result = await response.json();
if (!response.ok || result.events_received !== 1) {
throw new Error(`CAPI did not acknowledge Purchase (HTTP ${response.status})`);
}
}
```
Import `createHash` from `node:crypto`, pin a supported Graph API version, and keep the token in a server-side secret store. Validate order amounts, timestamps, currency, and catalog IDs before sending. Retry transient failures with the original `event_id` and `event_time`; route persistent errors for review. An API acknowledgment confirms receipt, not deduplication or attribution.
## 6. Validate end to end before scaling spend
1. **Walk the funnel with consent granted.** Open the lamp page, add it to the cart, start checkout, and place a controlled order. Use Meta Pixel Helper to inspect browser events where visible. In **Meta Events Manager → Test Events**, inspect event names, sources, parameters, and IDs where the integration exposes them. A custom sender can use `test_event_code`; if the native app doesn’t expose that control, use the dataset’s event details and Diagnostics. Some integrations may not forward Shopify test-mode orders, so verify that before interpreting a missing `Purchase`.
2. **Check one order against both systems.** Compare Shopify’s final order total, currency, quantities, and catalog IDs with Meta’s event details. Where both sources send `Purchase`, confirm the same event ID and look for deduplication rather than two counted purchases. Reload the confirmation page; for a custom integration, also replay the webhook in a controlled test.
3. **Test browser loss and denied consent separately.** In a consented session, block the Pixel request and confirm an eligible server `Purchase` still arrives. In a separate session, decline advertising consent and confirm that neither route sends events that require that consent. A successful server event in the first test is not a reason for one to appear in the second.
4. **Review Diagnostics before increasing spend.** Look for missing parameters, catalog mismatches, deduplication warnings, and server failures. Compare eligible Shopify orders with Meta’s received events over the same period, allowing for processing delays. Use Ads Manager to evaluate attribution separately; don’t expect it to equal Shopify order totals.
## 7. Consent and compliance
Treat the Pixel and CAPI as two delivery paths for the same advertising measurement purpose. Apply the relevant consent, opt-out, and data-use rules to **both**. Don’t use CAPI to restore signals a shopper declined to share. Confirm the store’s privacy notice describes the Meta integration, limit payloads to necessary fields, and restrict access to tokens and event data. Have the store’s privacy owner approve the regional settings and test results before launch. This is a draft implementation plan; it does not imply that tracking or campaigns are live.