Skip to content

feat(ads): add click-to-whatsapp ads conversion tracking and analytics - #943

Merged
viethung0o0 merged 6 commits into
mainfrom
feat/ctwa
Aug 13, 2026
Merged

feat(ads): add click-to-whatsapp ads conversion tracking and analytics#943
viethung0o0 merged 6 commits into
mainfrom
feat/ctwa

Conversation

@viethung0o0

@viethung0o0 viethung0o0 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds end-to-end Click-to-WhatsApp Ads (CTWA) conversion tracking:

  • Connect Accounts — Facebook Ads integration with ad-account selection, plus WhatsApp reconnect/OAuth relay and CAPI scope detection (hasCapiScope, datasetId cached on the integration).
  • Conversion Events — per-workspace rules (WhatsApp & Facebook channels) that qualify contacts as leads/purchases from triggers: qualifying template sent, keyword match, tag added, flow step reached, and WhatsApp Automatic Events. Attributed contacts (referral.ctwaClid on ContactInbox) are forwarded to Meta via the Conversions API with dedup and per-status tracking (pending/sent/failed/skipped).
  • Ads Analytics — funnel dashboard (conversations → qualified leads → purchases), spend/CPC/CPM/ROAS via Marketing API insights, performance-over-time chart, conversion delivery table, per-ad-account breakdown, and CSV exports (conversations/leads/purchases).
  • Retargeting — sync qualified leads into Facebook custom audiences.
  • Worker — new ads-conversion queue and worker handling trigger evaluation, CAPI dispatch, and audience sync, guarded by withBlockedOwnerGuard.
  • DatabaseAdsConversionRule / AdsConversionEvent tables shipped as a single squashed, idempotent migration (guarded with IF NOT EXISTS, so environments that already ran the pre-squash migrations re-apply it as a no-op).

Test plan

  • pnpm lint passes
  • check-types passes for builder, worker, @chatbotx.io/database, @chatbotx.io/business
  • Unit/integration tests added across builder, worker, business, database, integrations (ads analytics, conversion rules, trigger evaluation, CAPI dispatch, retarget sync, webhook automatic events)
  • Squashed migration verified on a scratch database: fresh run creates all objects; second run is a full no-op
  • Manual QA with a live CTWA ad (attribution → qualified lead → CAPI delivery) before promoting from draft

Update — contact-filter segments & analytics locale fix

  • Contact filters: added a "Click to WhatsApp Ads" filter group with two fields — From Click to WhatsApp ad and CTWA conversion (Lead/Purchase). These make CTWA-attributed contacts and conversion segments selectable anywhere the shared contact filter is used (broadcast audiences, contacts list, conversations, exports).
  • Analytics fix: Ads Analytics numbers and currency now format with the request locale, resolving a server/client hydration mismatch.
  • Tests added/updated for the new filter fields (schema, config, query builder) and the analytics view.

Update — WhatsApp broadcast retarget (exact segment)

The per-ad "Retarget → Send WhatsApp broadcast" menu now deep-links into the broadcast create page with the WhatsApp channel + integration preselected and the audience prefilled to exactly that ad's segment (conversations / qualified leads / purchases) over the selected date range — the same recipient set as the Facebook custom-audience path. The user only picks a template.

  • New machine-generated ctwaRetarget contact-filter condition resolves the segment as a single correlated EXISTS, reusing the Facebook export's segment predicates (one source of truth) and scoped by ad, date range, WhatsApp integration, and workspace.
  • Broadcast create page accepts channel / integration / contact-filter prefill via search params.
  • Rendered as a read-only chip in the audience filter.
  • Tests cover the SQL generation (segment/ad/date/integration/workspace scoping and outer-contact correlation), the deep-link builder, the prefill parser, and the form defaults.

@github-actions github-actions Bot added the feature New feature or request label Aug 12, 2026
@viethung0o0
viethung0o0 force-pushed the feat/ctwa branch 2 times, most recently from 875e194 to 90d1a79 Compare August 13, 2026 04:30
@viethung0o0
viethung0o0 marked this pull request as ready for review August 13, 2026 05:03
@viethung0o0
viethung0o0 merged commit 42a5dd4 into main Aug 13, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants