feat(tracking): Add standard Instant Purchase and Phone Confirmation options to Meta conversion tracking - #103
Conversation
|
Hi @konouzdz19-dot, Thank you for this contribution the direction is genuinely valuable for COD merchants, and the Meta reasoning behind it (Purchase at checkout vs. delivery, phone confirmation as the middle ground) is well-grounded against Meta's own documentation. We've completed a detailed review of the PR: every claim was verified against the code, the branch was tested in isolation, and the behavior was cross-checked with Meta's official Pixel/Conversions API docs and Cloudflare's Workflows docs. Full review here: 👉 The short version:
One more thing : we'd genuinely appreciate it if you review our review. Push back on anything you disagree with, double-check our plans, and tell us if you see a better approach for any point. Some of the items are improvements to CodFlow's existing tracking architecture that your PR surfaced your perspective would make the final design better, and we're happy to adjust the plan based on your feedback before you start implementing. Once the review points are addressed (or we've aligned on them together), we'll re-run the full test suite on our side and are excited to get this merged. Thanks again for the kind words about CodFlow, and for putting real care into this! 🙌 |
…#103 - Introduce shared canonical conversion model & resolver (resolveConversionForStage) - Decouple merchant phone confirmation from carrier delivery logistics - Add D1 atomic idempotency claim (0022_capi_event_claim.sql) on (order_id, stage, event_name) - Implement redundant browser Pixel + CAPI at checkout with matching event ID (order.id) - Expose conversionEvent in store context (getStoreConfig) - Standardize CAPI workflow IDs (getCapiWorkflowId) across checkout, transitions, and webhooks - Align delivery mode descriptions across en/fr/ar locales - Add Zod runtime payload validation with NonRetryableError and 7-day cutoff guard in CAPI workflow - Fix test suite mocks and Vitest Cloudflare runtime stubs - Revert unrelated package-lock.json modification
7769f87 to
b7c9da4
Compare
|
Hi @bighadj22, Thank you so much for the detailed guidance and feedback! It helped clean up the architecture and make the tracking flow much more resilient. We’d be really happy to hear your thoughts and review on these updates. We have rebased onto the latest main (incorporating PR #104) and addressed all points from your review: Shared Canonical Conversion Model & Pure Resolver (§1) Added cod-server/src/workflows/conversion-model.ts with typed stages (checkout, confirmed, delivered), event names (Lead, Purchase), and modes (Purchase, Purchase_Confirmed, Purchase_Delivered, Lead). Merchant manual phone verification in the dashboard (confirmed) strictly targets stage: "confirmed". Storefront config (getStoreConfig) now exposes conversionEvent. Added migration 0022_capi_event_claim.sql with a unique composite constraint on capi_event_log(order_id, stage, event_name). Implemented getCapiWorkflowId(orderId, stage, eventName) returning capi-${orderId}-${stage}-${eventName} across checkout, status transitions, and courier webhooks. Updated translations in English, French, and Arabic to replace absolute claims ("Zero returns counted", "Cash collected") with clear, accurate descriptions of carrier delivery triggers. Added Zod runtime payload validation throwing NonRetryableError on malformed inputs to avoid futile retries. Fixed all mock regressions across the test suite and added Cloudflare Workflows test stubs. Looking forward to your review! |
zod v4 removed parsed.error.errors; use parsed.error.issues. Without this cod-server tsc --noEmit fails and CI is red.
…Delivered 4-tier model redefines 'Purchase' as instant checkout Purchase. Existing rows using 'Purchase' (old on-delivery semantics) must keep firing at delivery: map them to Purchase_Delivered so live stores are not silently re-measured at checkout.
|
Merged! 🎉 Thanks so much for this contribution the 4-tier tracking setup is a great addition for COD merchants. We tested it end-to-end in a real Meta (Facebook) account: Instant Purchase, Phone Confirmed, Delivered, and Lead modes all verified working, with dedup and idempotency confirmed. We also added a small hardening on top (a zod v4 fix and a migration to preserve existing stores' tracking behavior) so everything stays backward-compatible. Keep up the good work this was a really solid PR! 👏 |
Thanks a lot @bighadj22!Really glad to hear the live Meta account testing went smoothly and the 4-tier setup is working well end-to-end. Appreciate the quick merge and the extra hardening on top. Happy to contribute to CodFlow and looking forward to future collaborations!
Amine19 |
|
I see the point about merchants forgetting to turn off Test Mode. For now, though, I don't think we need an auto-expiry timer., I'd rather keep it simple and avoid adding more logic than necessary. I think a clear banner or some kind of UI warning would be a more effective solution here, especially if it makes the merchant aware that Test Mode is still enabled before they start receiving live orders. But definitely keep the feedback coming, bro this kind of real-world testing is exactly what helps us make CodFlow better. 🤝 |
|
if you feel comfortable working with tracking and pixels, adding TikTok Pixel and Conversion API is something I'd definitely be interested in. It's actually on my list of things to work on, so if you'd like to take that on, I'd be happy to discuss it with you. 🔥 |
Unfortunately, I'm not familiar with TikTok Ads Manager and theire Pixel implementation, as I haven't had the opportunity to work with it yet. That said, it's something I've always wanted to explore and test out |
|
No worries at all, bro! If it's something you'd like to explore, though, feel free to look into it and see if it's interesting to you and Let me Know . No pressure 🤝 |
What does this PR do?
Hello Big Hadj,
First of all, congratulations on the amazing work on CodFlow — the platform is fast, clean, and a pleasure to work with.
While testing and using CodFlow in production, we noticed that the
Purchaseconversion event is currently configured to trigger only when an order reaches thedeliveredstatus, while checkout defaults to aLeadevent.A
Leadevent is technically intended for form-fills and lead generation inquiries rather than e-commerce sales. Nowadays in Algeria and the wider COD ecosystem, media buyers and store owners rarely run campaigns optimizing forLead— almost everyone optimizes directly forPurchase(Achats) so the Meta algorithm targets users with real buying intent.While triggering
Purchaseon delivery is an interesting option for media buyers who want to test strict net accounting, the standard e-commerce behavior used by platforms like Shopify and WooCommerce — firingPurchaseinstantly upon order placement — is currently missing. In addition, many COD businesses in Algeria confirm orders by phone before shipping, which creates a very useful middle ground.To give merchants full flexibility, we are happy to introduce these additional options while keeping your original delivery logic completely intact!
What this PR adds:
We expanded the Conversion Event selection in Settings → Tracking into 4 clear options:
Fires
Purchaseimmediately upon order submission with cart total and deduplication ID. Recommended for Meta Ads real-time campaign optimization.confirmed)Fires
Leadat checkout, and firesPurchasevia CAPI once the call center confirms the order with the customer.delivered) [Your original model]Preserved 100% as you built it. Fires
Purchaseonly when the parcel is delivered and cash is collected.For campaigns optimizing specifically for lead generation.
Additional improvements included:
Added a check in
capi.tsagainstcapi_event_log(order_idindexed) so that if an order status is toggled or a courier webhook fires twice, Meta will never receive duplicatePurchaseevents.Zero table mutations or database migrations. All existing stores continue to work seamlessly.
Added clear labels and explanations in English, French, and Arabic in
locales/*/settings.json.Related issues
N/A (Feature enhancement & tracking flexibility)
How to test
TESTxxxxx).Instant Purchase: firesPurchaseupon order placement.Purchase on Confirmation: firesLeadupon checkout, andPurchaseonce moved toconfirmed.Purchase on Delivery: firesLeadupon checkout, andPurchaseonce moved todelivered.Purchaseevents are sent.npm run typecheckandnpm testin the affected package(s)Checklist
feat:,fix:,chore:,docs:, ...)Areas affected
cod-shared(schema enum expansion & query helpers)cod-server(CAPI workflow idempotency check & status transition triggers)cod-client-astro(tracking settings options & AR/EN/FR translations)cod-astro/theme01(storefront dynamic thank-you tracking)