-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: onboard facebook_conversions destination (#2720)
* feat: onboard facebook_conversions destination * feat: onboard facebook_conversions destination * feat: added support for app events * feat: renamed FBAppEventsConfig to FBCAppEventsConfig * feat: add Config.actionSource as fallback for action_source * feat: use both content_name and contentName to populate destKey content_name * feat: reduced cognitive complexity * feat: added tests * feat: reduced deduplication * feat: add router tests and moved common functions to root utils folder * feat: add mapping config for payment info entered and product added to wishlist * feat: add tests for AddPaymentInfo and AddToWishlist * feat: addressed review comments * feat: moved networkHandler to fb common utils * feat: resolved code smells
- Loading branch information
1 parent
3aabe81
commit 5269af4
Showing
27 changed files
with
3,101 additions
and
523 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
const { getMappingConfig } = require('../../util'); | ||
|
||
const ENDPOINT = (datasetId, accessToken) => | ||
`https://graph.facebook.com/v17.0/${datasetId}/events?access_token=${accessToken}`; | ||
|
||
const CONFIG_CATEGORIES = { | ||
USERDATA: { | ||
standard: false, | ||
type: 'identify', | ||
name: 'FBCUserDataConfig', | ||
}, | ||
COMMON: { name: 'FBCCommonConfig' }, | ||
APPDATA: { name: 'FBCAppEventsConfig' }, | ||
SIMPLE_TRACK: { | ||
standard: false, | ||
type: 'simple track', | ||
name: 'FBCSimpleCustomConfig', | ||
}, | ||
PRODUCT_LIST_VIEWED: { | ||
standard: true, | ||
type: 'product list viewed', | ||
eventName: 'ViewContent', | ||
name: 'FBCProductListViewedCustomData', | ||
}, | ||
PRODUCT_VIEWED: { | ||
standard: true, | ||
type: 'product viewed', | ||
eventName: 'ViewContent', | ||
name: 'FBCProductViewedCustomData', | ||
}, | ||
PRODUCT_ADDED: { | ||
standard: true, | ||
type: 'product added', | ||
eventName: 'AddToCart', | ||
name: 'FBCProductAddedCustomData', | ||
}, | ||
ORDER_COMPLETED: { | ||
standard: true, | ||
type: 'order completed', | ||
eventName: 'Purchase', | ||
name: 'FBCOrderCompletedCustomData', | ||
}, | ||
PRODUCTS_SEARCHED: { | ||
standard: true, | ||
type: 'products searched', | ||
eventName: 'Search', | ||
name: 'FBCProductSearchedCustomData', | ||
}, | ||
CHECKOUT_STARTED: { | ||
standard: true, | ||
type: 'checkout started', | ||
eventName: 'InitiateCheckout', | ||
name: 'FBCCheckoutStartedCustomData', | ||
}, | ||
PAYMENT_INFO_ENTERED: { | ||
standard: true, | ||
type: 'payment info entered', | ||
eventName: 'AddPaymentInfo', | ||
name: 'FBCPaymentInfoEnteredCustomData', | ||
}, | ||
PRODUCT_ADDED_TO_WISHLIST: { | ||
standard: true, | ||
type: 'product added to wishlist', | ||
eventName: 'AddToWishlist', | ||
name: 'FBCProductAddedToWishlistCustomData', | ||
}, | ||
OTHER_STANDARD: { | ||
standard: true, | ||
type: 'otherStandard', | ||
name: 'FBCSimpleCustomConfig', | ||
}, | ||
PAGE_VIEW: { | ||
standard: true, | ||
type: 'page_view', | ||
eventName: 'PageView', | ||
name: 'FBCSimpleCustomConfig', | ||
}, | ||
}; | ||
|
||
const MAPPING_CONFIG = getMappingConfig(CONFIG_CATEGORIES, __dirname); | ||
const ACTION_SOURCES_VALUES = [ | ||
'email', | ||
'website', | ||
'app', | ||
'phone_call', | ||
'chat', | ||
'physical_store', | ||
'system_generated', | ||
'other', | ||
]; | ||
|
||
const OTHER_STANDARD_EVENTS = [ | ||
'Lead', | ||
'CompleteRegistration', | ||
'Contact', | ||
'CustomizeProduct', | ||
'Donate', | ||
'FindLocation', | ||
'Schedule', | ||
'StartTrial', | ||
'SubmitApplication', | ||
'Subscribe', | ||
]; | ||
|
||
const FB_CONVERSIONS_DEFAULT_EXCLUSION = ['opt_out', 'event_id', 'action_source']; | ||
const STANDARD_ECOMM_EVENTS_CATEGORIES = [ | ||
CONFIG_CATEGORIES.PRODUCT_LIST_VIEWED, | ||
CONFIG_CATEGORIES.PRODUCT_VIEWED, | ||
CONFIG_CATEGORIES.PRODUCT_ADDED, | ||
CONFIG_CATEGORIES.ORDER_COMPLETED, | ||
CONFIG_CATEGORIES.PRODUCTS_SEARCHED, | ||
CONFIG_CATEGORIES.CHECKOUT_STARTED, | ||
CONFIG_CATEGORIES.PAYMENT_INFO_ENTERED, | ||
CONFIG_CATEGORIES.PRODUCT_ADDED_TO_WISHLIST, | ||
]; | ||
|
||
module.exports = { | ||
ENDPOINT, | ||
MAPPING_CONFIG, | ||
CONFIG_CATEGORIES, | ||
ACTION_SOURCES_VALUES, | ||
FB_CONVERSIONS_DEFAULT_EXCLUSION, | ||
STANDARD_ECOMM_EVENTS_CATEGORIES, | ||
OTHER_STANDARD_EVENTS, | ||
DESTINATION: 'FACEBOOK_CONVERSIONS', | ||
}; |
101 changes: 101 additions & 0 deletions
101
src/v0/destinations/facebook_conversions/data/FBCAppEventsConfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
[ | ||
{ | ||
"destKey": "advertiser_tracking_enabled", | ||
"sourceKeys": "context.device.adTrackingEnabled", | ||
"required": true | ||
}, | ||
{ | ||
"destKey": "application_tracking_enabled", | ||
"sourceKeys": "properties.application_tracking_enabled", | ||
"required": true | ||
}, | ||
{ | ||
"destKey": "extinfo.0", | ||
"sourceKeys": "context.device.type", | ||
"required": true, | ||
"metadata": { | ||
"type": "toLower" | ||
} | ||
}, | ||
{ | ||
"destKey": "extinfo.1", | ||
"sourceKeys": "context.app.namespace" | ||
}, | ||
{ | ||
"destKey": "extinfo.2", | ||
"sourceKeys": "context.app.build" | ||
}, | ||
{ | ||
"destKey": "extinfo.3", | ||
"sourceKeys": "context.app.version" | ||
}, | ||
{ | ||
"destKey": "extinfo.4", | ||
"sourceKeys": "context.os.version", | ||
"required": true | ||
}, | ||
{ | ||
"destKey": "extinfo.5", | ||
"sourceKeys": "context.device.model" | ||
}, | ||
{ | ||
"destKey": "extinfo.6", | ||
"sourceKeys": "context.locale" | ||
}, | ||
{ | ||
"destKey": "extinfo.7", | ||
"sourceKeys": "context.abv_timezone" | ||
}, | ||
{ | ||
"destKey": "extinfo.8", | ||
"sourceKeys": "context.network.carrier" | ||
}, | ||
{ | ||
"destKey": "extinfo.9", | ||
"sourceKeys": "context.screen.width" | ||
}, | ||
{ | ||
"destKey": "extinfo.10", | ||
"sourceKeys": "context.screen.height" | ||
}, | ||
{ | ||
"destKey": "extinfo.11", | ||
"sourceKeys": "context.screen.density" | ||
}, | ||
{ | ||
"destKey": "extinfo.12", | ||
"sourceKeys": "context.cpu_cores" | ||
}, | ||
{ | ||
"destKey": "extinfo.13", | ||
"sourceKeys": "context.ext_storage_size" | ||
}, | ||
{ | ||
"destKey": "extinfo.14", | ||
"sourceKeys": "context.avl_storage_size" | ||
}, | ||
{ | ||
"destKey": "extinfo.15", | ||
"sourceKeys": "context.timezone" | ||
}, | ||
{ | ||
"destKey": "campaign_ids", | ||
"sourceKeys": ["properties.campaignId", "context.traits.campaignId", "context.campaign.name"] | ||
}, | ||
{ | ||
"destKey": "install_referrer", | ||
"sourceKeys": "properties.install_referrer" | ||
}, | ||
{ | ||
"destKey": "installer_package", | ||
"sourceKeys": "properties.installer_package" | ||
}, | ||
{ | ||
"destKey": "url_schemes", | ||
"sourceKeys": "properties.url_schemes" | ||
}, | ||
{ | ||
"destKey": "windows_attribution_id", | ||
"sourceKeys": "properties.windows_attribution_id" | ||
} | ||
] |
53 changes: 53 additions & 0 deletions
53
src/v0/destinations/facebook_conversions/data/FBCCheckoutStartedCustomData.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
[ | ||
{ | ||
"destKey": "content_ids", | ||
"sourceKeys": "", | ||
"metadata": { | ||
"defaultValue": [] | ||
} | ||
}, | ||
{ | ||
"destKey": "contents", | ||
"sourceKeys": "", | ||
"metadata": { | ||
"defaultValue": [] | ||
} | ||
}, | ||
{ | ||
"destKey": "content_type", | ||
"sourceKeys": "", | ||
"metadata": { | ||
"defaultValue": "product" | ||
} | ||
}, | ||
{ | ||
"destKey": "content_category", | ||
"sourceKeys": "properties.category" | ||
}, | ||
{ | ||
"destKey": "currency", | ||
"sourceKeys": "properties.currency", | ||
"metadata": { | ||
"defaultValue": "USD" | ||
} | ||
}, | ||
{ | ||
"destKey": "value", | ||
"sourceKeys": [ | ||
"properties.revenue", | ||
"properties.value", | ||
"properties.price", | ||
"properties.total" | ||
], | ||
"metadata": { | ||
"type": "numberForRevenue" | ||
} | ||
}, | ||
{ | ||
"destKey": "num_items", | ||
"sourceKeys": "", | ||
"metadata": { | ||
"defaultValue": 0 | ||
} | ||
} | ||
] |
37 changes: 37 additions & 0 deletions
37
src/v0/destinations/facebook_conversions/data/FBCCommonConfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[ | ||
{ | ||
"destKey": "event_name", | ||
"sourceKeys": ["event", "type"], | ||
"required": true | ||
}, | ||
{ | ||
"destKey": "event_time", | ||
"sourceKeys": "timestamp", | ||
"sourceFromGenericMap": true, | ||
"required": true, | ||
"metadata": { | ||
"type": "secondTimestamp" | ||
} | ||
}, | ||
{ | ||
"destKey": "event_source_url", | ||
"sourceKeys": "pageUrl", | ||
"sourceFromGenericMap": true | ||
}, | ||
{ | ||
"destKey": "opt_out", | ||
"sourceKeys": ["traits.opt_out", "context.traits.opt_out", "properties.opt_out"] | ||
}, | ||
{ | ||
"destKey": "event_id", | ||
"sourceKeys": ["traits.event_id", "context.traits.event_id", "properties.event_id", "messageId"] | ||
}, | ||
{ | ||
"destKey": "action_source", | ||
"sourceKeys": [ | ||
"traits.action_source", | ||
"context.traits.action_source", | ||
"properties.action_source" | ||
] | ||
} | ||
] |
57 changes: 57 additions & 0 deletions
57
src/v0/destinations/facebook_conversions/data/FBCOrderCompletedCustomData.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
[ | ||
{ | ||
"destKey": "content_ids", | ||
"sourceKeys": "", | ||
"metadata": { | ||
"defaultValue": [] | ||
} | ||
}, | ||
{ | ||
"destKey": "contents", | ||
"sourceKeys": "", | ||
"metadata": { | ||
"defaultValue": [] | ||
} | ||
}, | ||
{ | ||
"destKey": "content_type", | ||
"sourceKeys": "", | ||
"metadata": { | ||
"defaultValue": "product" | ||
} | ||
}, | ||
{ | ||
"destKey": "content_category", | ||
"sourceKeys": "properties.category" | ||
}, | ||
{ | ||
"destKey": "content_name", | ||
"sourceKeys": ["properties.content_name", "properties.contentName"] | ||
}, | ||
{ | ||
"destKey": "currency", | ||
"sourceKeys": "properties.currency", | ||
"metadata": { | ||
"defaultValue": "USD" | ||
} | ||
}, | ||
{ | ||
"destKey": "value", | ||
"sourceKeys": [ | ||
"properties.revenue", | ||
"properties.value", | ||
"properties.price", | ||
"properties.total" | ||
], | ||
"metadata": { | ||
"type": "numberForRevenue" | ||
} | ||
}, | ||
{ | ||
"destKey": "num_items", | ||
"sourceKeys": "", | ||
"metadata": { | ||
"defaultValue": 0 | ||
} | ||
} | ||
] |
Oops, something went wrong.