# Cedar & Coil: Shopify → Meta conversion tracking guide
**Draft implementation plan.** Use Shopify’s native **Facebook & Instagram by Meta** channel, connect one Meta web dataset, and validate `Purchase` before scaling spend. Treat Shopify as the source of truth for orders and revenue; use Meta to measure and optimize ads.
## 1. Recommended architecture: Meta Pixel + Conversions API
Send eligible storefront and checkout events to the **same Meta dataset** through two paths:
- **Browser — Meta Pixel:** Captures shopper actions as they happen, along with browser context and, where available and permitted, Meta click and browser identifiers. It can miss events when scripts are blocked, cookies are restricted, or a page closes before the request completes.
- **Server — Conversions API (CAPI):** Sends events without depending on the browser’s request to Meta. For `Purchase`, a trusted Shopify order record lets the server report an order even if the confirmation-page Pixel never fires. The server still needs the applicable permission to share the event, and Meta may not be able to match or attribute every event it receives.
Use **deduplication** so that an action reported through both paths counts once. A browser event and its server copy are two records of the same action, not two conversions.
## 2. Standard events and parameters
Use Meta’s exact event names and capitalization. Send `value` as a number in major currency units (`68.00`, not `6800`) and `currency` as an uppercase ISO 4217 code such as `USD`. Use the IDs that appear in the connected Meta catalog’s item `id` field. Don’t assume a Shopify variant ID or SKU matches without checking the synced catalog.
| Meta event | Fire when | Key parameters |
|---|---|---|
| `ViewContent` | The Arc Clip Lamp product detail page is viewed; Shopify `product_viewed` in a custom setup. | `content_ids` for the displayed item or variant, `content_type: "product"` for item IDs, `value` for the displayed price, and `currency`. |
| `AddToCart` | Shopify confirms an item was added; use `product_added_to_cart`, not the button click. | `content_ids`, `content_type`, `contents` with item IDs and quantities, `value` for the items **added in this action**, and `currency`. |
| `InitiateCheckout` | Checkout starts; use `checkout_started`, not every checkout step or reload. | `content_ids`, `content_type`, `contents`, `num_items` as total quantity, and the checkout’s `value` and `currency`. |
| `Purchase` | Shopify confirms a completed order, not a payment-button click or a thank-you page reload. | **`value`, `currency`, and `content_ids`** from the completed order, plus `content_type`, `contents` with IDs and quantities, and `num_items`. |
For a custom implementation, define Purchase value as the final amount charged or due at order completion after discounts, including shipping and tax. Use the same value definition and transaction currency on both paths. Read the amount from Shopify rather than hard-coding the lamp’s $68 list price. With the native integration, verify what Shopify actually sends and document that definition for reconciliation.
## 3. Exactly how Pixel and CAPI deduplicate
Meta pairs browser and server events using the same **dataset**, exact **event name**, and exact **event ID**. The browser option is `eventID`; the CAPI field is `event_id`. Meta’s matching window is 48 hours, but send both copies promptly rather than relying on the entire window.
```javascript
// Browser: fourth argument contains the deduplication ID.
fbq("track", "Purchase", purchaseParams, {
eventID: "purchase:cedar-and-coil:123456789"
});
```
The server copy must use `event_name: "Purchase"` and `event_id: "purchase:cedar-and-coil:123456789"`. In a custom integration, derive that ID from the **same canonical Shopify order ID** on both paths. Normalize Shopify global IDs and numeric IDs consistently. Persist the ID across webhook retries and never create a new one on page reload. For repeatable actions such as `AddToCart`, generate one ID per successful action and pass it to both senders; a product ID alone would collapse distinct adds.
Deduplication IDs identify **actions**. Hashed email, `fbp`, and `fbc` help Meta **match** events to people or ad interactions; they do not replace the shared event ID. Also make the server sender idempotent: Meta’s browser/server deduplication is not a substitute for preventing duplicate webhook processing.
## 4. Prepare customer information before sending it server-side
In the native integration, let Shopify and Meta handle formatting. In a custom integration, send only permitted, documented fields in CAPI’s `user_data` object:
- **Normalize, then SHA-256 hash fields Meta requires hashed.** For `em`, trim and lowercase the email before hashing. For `ph`, normalize to digits including the country code before hashing; omit it if the country code is unknown. Apply Meta’s field-specific rules for any additional approved fields, such as name, postal code, country, or `external_id`. Send hexadecimal digests, not plaintext or hashes of empty placeholders, and do not double-hash.
- **Do not hash** `fbp`, `fbc`, `client_ip_address`, or `client_user_agent`. Forward only permitted values from the shopper’s actual session. Do not invent an `fbc` for a non-Meta visit or use the Shopify webhook’s IP or user agent as the shopper’s.
- Keep customer identifiers out of `custom_data`, event IDs, URLs, and logs. Send the request over HTTPS and store the CAPI token server-side. Hashing does not make customer information anonymous or remove consent obligations.
## 5. Shopify setup: native vs. custom
| Option | What it gives you | Trade-off |
|---|---|---|
| **Facebook & Instagram by Meta channel** | Managed Pixel and CAPI setup, catalog sync, and deduplication. | Less control over payloads and event mapping. Verify actual event coverage in Events Manager. |
| **Custom Shopify app + Web Pixel + server worker** | Control over triggers, event IDs, value definitions, consent checks, and delivery logs. | Cedar & Coil owns checkout coverage, secure data handling, retries, and maintenance as Shopify and Meta change. |
**Recommendation: use the native channel.** For a small DTC store launching with one product, it gives Cedar & Coil a supported path to reliable Purchase tracking without maintaining a second integration. Use custom only if testing identifies a specific requirement the native channel cannot meet.
**Native setup path**
1. In Shopify admin, open or install **Facebook & Instagram by Meta** under **Sales channels**. Connect the Meta business portfolio, ad account, and catalog, and select the intended Pixel/web dataset. Confirm the ad account can use that dataset.
2. In the channel’s **Settings → Data sharing settings**, enable customer data sharing. Select **Maximum** if that level is approved for Cedar & Coil’s privacy setup, then verify that both browser and server events arrive. If Maximum is not approved, verify what the permitted setting actually sends rather than assuming it provides identical coverage.
3. Check **Settings → Customer events**, theme code, GTM, and any existing tracking apps for other Meta senders. Remove or disable overlapping events so the native channel is the sole owner. Don’t add the custom example below on top of native Purchase tracking.
4. Confirm the Arc Clip Lamp’s synced catalog item ID and the intended dataset in Meta Events Manager before testing.
**Custom implementation sketch — alternative to native**
Use Shopify Customer Events via a Web Pixel for the browser path. For a confirmed-order Purchase, pair browser `checkout_completed` with a verified Shopify `orders/create` webhook, scoped to completed online-store orders. Verify the webhook signature against the raw body before processing, and enqueue the order once using its canonical ID. If the business instead defines Purchase as *paid*, don’t pair an unconditional browser checkout event with a later paid-order webhook: delayed payments can make the two triggers represent different actions.
The server worker below assumes the order has already been verified and normalized, and that any permitted browser context was associated with its checkout. The API version is pinned through configuration.
```javascript
import { createHash } from "node:crypto";
const sha256 = (s) => createHash("sha256").update(s, "utf8").digest("hex");
async function sendPurchase(order, ctx, { testEventCode } = {}) {
// Missing or unknown permission is not treated as approval.
if (ctx.metaSharingAllowed !== true) return;
const email = order.email?.trim().toLowerCase();
const contents = order.lines.map((line) => ({
id: line.metaCatalogItemId,
quantity: line.quantity
}));
const event = {
event_name: "Purchase",
event_time: order.completedAtUnixSeconds, // Actual event time, not retry time.
event_id: `purchase:cedar-and-coil:${order.canonicalId}`,
action_source: "website",
event_source_url: ctx.safeEventUrl, // Real event URL, stripped of tokens/PII.
user_data: {
...(email && { em: [sha256(email)] }),
...(ctx.fbp && { fbp: ctx.fbp }),
...(ctx.fbc && { fbc: ctx.fbc }),
...(ctx.shopperIp && { client_ip_address: ctx.shopperIp }),
...(ctx.shopperUserAgent && { client_user_agent: ctx.shopperUserAgent })
},
custom_data: {
value: order.totalMajorUnits,
currency: order.currency,
content_type: "product",
content_ids: [...new Set(contents.map(({ id }) => id))],
contents,
num_items: contents.reduce((sum, item) => sum + item.quantity, 0)
}
};
const { META_GRAPH_VERSION, META_DATASET_ID, META_CAPI_TOKEN } = process.env;
const response = await fetch(
`https://graph.facebook.com/${META_GRAPH_VERSION}/${META_DATASET_ID}/events`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${META_CAPI_TOKEN}`
},
body: JSON.stringify({
data: [event],
...(testEventCode && { test_event_code: testEventCode })
})
}
);
const result = await response.json().catch(() => null);
if (!response.ok || result?.events_received !== 1) {
throw new Error(`Meta Purchase not accepted (HTTP ${response.status})`);
}
}
```
Before deploying a custom sender, validate required website event fields against the pinned API version. If required context is missing, surface the failure rather than fabricating it. Retry transient failures with the original ID and event time; route permanent validation errors for review. Meta accepting a request is not proof that it matched, deduplicated, or attributed the event.
## 6. Validate end to end before scaling spend
1. **Run a controlled purchase.** With applicable permission granted, view the lamp, add it to the cart, start checkout, and complete a test order through a supported Shopify payment test flow. Use Meta Pixel Helper for browser events and Events Manager’s **Test Events** and **Diagnostics** for delivery and warnings. For a custom CAPI test, use `test_event_code` and remove it for production.
2. **Check payloads against Shopify.** Verify exact event names, triggers, item IDs, quantities, currency, and value. Include a discounted or multi-quantity order so the test catches a hard-coded `$68` or unit-price-versus-total error.
3. **Prove deduplication and retry behavior.** Where both paths report `Purchase`, check that the event IDs match and Meta treats them as one purchase. Reload the completion page; for a custom sender, replay the webhook. Neither should create another Purchase. Confirm that a second order gets a different ID.
4. **Test privacy and browser scenarios separately.** Try mobile and a browser that restricts the Pixel. When sharing is permitted, verify that the server Purchase still arrives where the browser copy does not. Then test denied consent independently and verify the configured restriction applies to **both** paths.
5. **Reconcile a closed test window.** Exclude test orders from production totals. Use an order export and available event or delivery records to reconcile eligible Shopify orders to deduplicated Purchase counts and values over the same time window and currency. Check the totals independently from order or line-item detail and investigate discrepancies. Use Events Manager to verify receipt; Ads Manager reports **attributed** purchases, so its total need not equal Shopify’s.
Scale only after Purchase values and catalog IDs are correct, duplicates are ruled out, expected server delivery is observed, and consent tests pass.
## 7. Consent and compliance
CAPI is a second delivery path, **not a way to bypass consent, opt-outs, or browser privacy choices**. Configure Shopify **Customer privacy** settings and any consent management platform for the regions Cedar & Coil serves. For a custom integration, make the server enforce the relevant permission and opt-out state before sending, including on retries. An order existing in Shopify is not itself permission to send it to Meta.
Document what is shared, why it is shared, how long it is retained, and how deletion and opt-out requests are handled. Review the setup against applicable law and Meta’s terms before launch. Tracking can improve event delivery, but delivery, matching, and ad attribution are separate outcomes; none guarantees a specific recovery rate.