Skip to content

STRATCONN-6441 - [Facebook CAPI] - refactor and additional features#3675

Open
joe-ayoub-segment wants to merge 30 commits intomainfrom
fb-capi-countrycode
Open

STRATCONN-6441 - [Facebook CAPI] - refactor and additional features#3675
joe-ayoub-segment wants to merge 30 commits intomainfrom
fb-capi-countrycode

Conversation

@joe-ayoub-segment
Copy link
Copy Markdown
Contributor

@joe-ayoub-segment joe-ayoub-segment commented Mar 18, 2026

Summary

This PR is refactors the Facebook Conversions API destination.

Action Fields are moved to a single file (fields.ts).
Perform logic is moved to a single file (functions.ts).
Original logic is still in place, and the new new code is behind feature flags (one for each Action).

Unit test changes:

  1. Additional unit tests added for new code logic
  2. All existing unit tests maintained, and are executed twice - once with the feature flag on, and then again with the flag off.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 93.96325% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.82%. Comparing base (155ff1e) to head (8e05564).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
...tions/facebook-conversions-api/shared/functions.ts 92.30% 0 Missing and 16 partials ⚠️
...ations/facebook-conversions-api/purchase2/index.ts 70.83% 6 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             main    #3675     +/-   ##
=========================================
  Coverage   80.82%   80.82%             
=========================================
  Files        1382     1327     -55     
  Lines       27507    24924   -2583     
  Branches     5853     5184    -669     
=========================================
- Hits        22233    20146   -2087     
+ Misses       4341     3830    -511     
- Partials      933      948     +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Facebook Conversions API destination to fix state/country hashing during user_data construction (normalizing to 2-letter codes before hashing), while also incorporating a broader refactor that centralizes request-building/validation logic and updates tests accordingly.

Changes:

  • Centralized event validation + request construction behind send() / getUserData() logic and updated actions to call it.
  • Normalized state and country to 2-letter codes prior to hashing to match Meta CAPI expectations.
  • Extended payload/user_data support (e.g., ctwa_clid, append-value flows) and updated/expanded unit tests and snapshots.

Reviewed changes

Copilot reviewed 55 out of 55 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/destination-actions/src/destinations/facebook-conversions-api/viewContent2/index.ts Switched action implementation to shared fields + centralized send() path.
packages/destination-actions/src/destinations/facebook-conversions-api/viewContent2/generated-types.ts Added ctwa_clid to user_data typing.
packages/destination-actions/src/destinations/facebook-conversions-api/viewContent/index.ts Switched action implementation to shared fields + centralized send() path.
packages/destination-actions/src/destinations/facebook-conversions-api/viewContent/generated-types.ts Added ctwa_clid to user_data typing.
packages/destination-actions/src/destinations/facebook-conversions-api/utils.ts Removed legacy API version helper (moved/renamed).
packages/destination-actions/src/destinations/facebook-conversions-api/types.ts Added shared event/request/user_data types for centralized send pipeline.
packages/destination-actions/src/destinations/facebook-conversions-api/search2/index.ts Switched action implementation to shared fields + centralized send() path.
packages/destination-actions/src/destinations/facebook-conversions-api/search2/generated-types.ts Added ctwa_clid to user_data typing.
packages/destination-actions/src/destinations/facebook-conversions-api/search/index.ts Switched action implementation to shared fields + centralized send() path.
packages/destination-actions/src/destinations/facebook-conversions-api/search/generated-types.ts Added ctwa_clid to user_data typing.
packages/destination-actions/src/destinations/facebook-conversions-api/purchase2/index.ts Routed action through centralized send() with explicit EventType.Purchase.
packages/destination-actions/src/destinations/facebook-conversions-api/purchase2/generated-types.ts Added append-event fields, predicted_ltv, order_id, and ctwa_clid.
packages/destination-actions/src/destinations/facebook-conversions-api/purchase2/functions.ts Removed per-action send implementation in favor of shared functions.ts.
packages/destination-actions/src/destinations/facebook-conversions-api/purchase2/fields.ts Removed per-action field definitions in favor of shared fields.
packages/destination-actions/src/destinations/facebook-conversions-api/purchase/index.ts Switched action implementation to shared fields + centralized send() path.
packages/destination-actions/src/destinations/facebook-conversions-api/purchase/generated-types.ts Added append-event fields, predicted_ltv, order_id, and ctwa_clid.
packages/destination-actions/src/destinations/facebook-conversions-api/pageView2/index.ts Switched action implementation to shared fields + centralized send() path.
packages/destination-actions/src/destinations/facebook-conversions-api/pageView2/generated-types.ts Added ctwa_clid to user_data typing.
packages/destination-actions/src/destinations/facebook-conversions-api/pageView/index.ts Switched action implementation to shared fields + centralized send() path.
packages/destination-actions/src/destinations/facebook-conversions-api/pageView/generated-types.ts Added ctwa_clid to user_data typing.
packages/destination-actions/src/destinations/facebook-conversions-api/initiateCheckout2/index.ts Switched action implementation to shared fields + centralized send() path.
packages/destination-actions/src/destinations/facebook-conversions-api/initiateCheckout2/generated-types.ts Added ctwa_clid to user_data typing.
packages/destination-actions/src/destinations/facebook-conversions-api/initiateCheckout/index.ts Switched action implementation to shared fields + centralized send() path.
packages/destination-actions/src/destinations/facebook-conversions-api/initiateCheckout/generated-types.ts Added ctwa_clid to user_data typing.
packages/destination-actions/src/destinations/facebook-conversions-api/functions.ts Added centralized send/validate/event-build + hashing/normalization helpers (incl. state/country normalization).
packages/destination-actions/src/destinations/facebook-conversions-api/fb-capi-user-data.ts Removed legacy user_data field + normalization/hashing implementation.
packages/destination-actions/src/destinations/facebook-conversions-api/fb-capi-properties.ts Removed legacy shared field definitions and helpers.
packages/destination-actions/src/destinations/facebook-conversions-api/fb-capi-app-data.ts Removed legacy app-data generator + field definition.
packages/destination-actions/src/destinations/facebook-conversions-api/custom2/index.ts Switched action implementation to shared fields + centralized send() path.
packages/destination-actions/src/destinations/facebook-conversions-api/custom2/generated-types.ts Added append-event fields and ctwa_clid.
packages/destination-actions/src/destinations/facebook-conversions-api/custom/index.ts Switched action implementation to shared fields + centralized send() path.
packages/destination-actions/src/destinations/facebook-conversions-api/custom/generated-types.ts Added append-event fields and ctwa_clid.
packages/destination-actions/src/destinations/facebook-conversions-api/constants.ts Added FLAGON_NAME + EventType constant used by the refactor.
packages/destination-actions/src/destinations/facebook-conversions-api/addToCart2/index.ts Switched action implementation to shared fields + centralized send() path (includes syncMode guard).
packages/destination-actions/src/destinations/facebook-conversions-api/addToCart2/generated-types.ts Added ctwa_clid to user_data typing.
packages/destination-actions/src/destinations/facebook-conversions-api/addToCart/index.ts Switched action implementation to shared fields + centralized send() path.
packages/destination-actions/src/destinations/facebook-conversions-api/addToCart/generated-types.ts Added ctwa_clid to user_data typing.
packages/destination-actions/src/destinations/facebook-conversions-api/tests/viewContent2.test.ts Updated snapshots for new request shape; added ctwa_clid test.
packages/destination-actions/src/destinations/facebook-conversions-api/tests/viewContent.test.ts Updated snapshots for new request shape; added ctwa_clid test.
packages/destination-actions/src/destinations/facebook-conversions-api/tests/utils.test.ts Updated to use getApiVersion from functions.ts.
packages/destination-actions/src/destinations/facebook-conversions-api/tests/search2.test.ts Updated snapshots for new request shape; added ctwa_clid test.
packages/destination-actions/src/destinations/facebook-conversions-api/tests/search.test.ts Updated snapshots for new request shape; added ctwa_clid test.
packages/destination-actions/src/destinations/facebook-conversions-api/tests/purchase2.test.ts Updated snapshots for new request shape; added ctwa_clid coverage.
packages/destination-actions/src/destinations/facebook-conversions-api/tests/pageView2.test.ts Updated snapshots for new request shape; added ctwa_clid test.
packages/destination-actions/src/destinations/facebook-conversions-api/tests/pageView.test.ts Updated snapshots for new request shape; added ctwa_clid test.
packages/destination-actions/src/destinations/facebook-conversions-api/tests/initiateCheckout2.test.ts Updated snapshots for new request shape; added ctwa_clid test.
packages/destination-actions/src/destinations/facebook-conversions-api/tests/initiateCheckout.test.ts Updated snapshots for new request shape; added ctwa_clid test.
packages/destination-actions/src/destinations/facebook-conversions-api/tests/custom2.test.ts Updated snapshots for new request shape; added ctwa_clid test.
packages/destination-actions/src/destinations/facebook-conversions-api/tests/custom.test.ts Updated snapshots; added extensive append-event/AppendValue behavior tests and ctwa_clid test.
packages/destination-actions/src/destinations/facebook-conversions-api/tests/app-data.test.ts Updated to use centralized generateAppData implementation.
packages/destination-actions/src/destinations/facebook-conversions-api/tests/addToCart2.test.ts Updated snapshots for new request shape; added ctwa_clid test.
packages/destination-actions/src/destinations/facebook-conversions-api/tests/addToCart.test.ts Updated snapshots for new request shape; added ctwa_clid test.

@joe-ayoub-segment joe-ayoub-segment changed the title STRATCONN-6441 - [Facebook CAPI] - country and state fix STRATCONN-6441 - [Facebook CAPI] - refactor and additional features Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants