Meta Ads support in this repo is optional. If you do not run Meta Ads, you do
not need to enable any of this.
What This Feature Does
This repo can help you track the two Meta events most people care about for paid traffic:InitiateCheckoutwhen someone clicks a hosted checkout CTAPurchasewhen the payment webhook succeeds and the purchase is stored
Why Meta Ads Is Separate From Analytics
In this repo:- product analytics live under
lib/analytics/* - Meta checkout attribution lives under
lib/attribution/meta/*
Required Env Vars
Enable Meta attribution only when you actually want it:NEXT_PUBLIC_ENABLE_META_ATTRIBUTION is false or the required Meta values
are missing, the feature stays off.
How The Repo Is Wired
The main files are:lib/attribution/meta/provider.tsxlib/attribution/meta/browser.tslib/attribution/meta/conversions-api.tscomponents/(ui-components)/payments/checkout-link.tsxlib/payments/processor.ts
- a user clicks a checkout CTA rendered through
CheckoutLink - the repo sends Meta
InitiateCheckoutin the browser - the payment provider completes checkout
- your webhook is verified by the shared payment route
- the purchase is stored by the shared payment processor
- the repo sends Meta
Purchasethrough Conversions API
Important Constraint
Only checkout buttons that go through the shared checkout abstraction get the Meta browser event automatically. That means you should use:components/(ui-components)/payments/checkout-link.tsx
- hardcoded raw checkout URLs directly inside random UI files
What Meta Receives
The current implementation sends:- product/content identifiers from the shared checkout catalog
- value and currency
- hashed user identity data when available
- a stable event id for purchase deduplication
Verification Checklist
Your Meta Ads setup is working if:- the Meta Pixel loads only when enabled
- clicking a checkout CTA triggers
InitiateCheckout - a successful purchase webhook triggers
Purchase - the events appear in Meta Events Manager
NEXT_PUBLIC_META_TEST_EVENT_CODE and confirm the test
events appear under that code.
Common Mistakes
- setting
NEXT_PUBLIC_META_PIXEL_IDbut forgettingMETA_ACCESS_TOKEN - expecting Meta events from a CTA that does not use
CheckoutLink - enabling Meta while checkout URLs are still missing from env
- mixing generic analytics expectations with Meta attribution expectations
- changing env vars without restarting the app

