diff --git a/src/v0/destinations/facebook_pixel/transform.js b/src/v0/destinations/facebook_pixel/transform.js index 1c792cfdc0..4a4c79af9e 100644 --- a/src/v0/destinations/facebook_pixel/transform.js +++ b/src/v0/destinations/facebook_pixel/transform.js @@ -7,7 +7,6 @@ const { MAPPING_CONFIG, FB_PIXEL_DEFAULT_EXCLUSION, STANDARD_ECOMM_EVENTS_TYPE, - OTHER_STANDARD_EVENTS, } = require('./config'); const { EventType } = require('../../../constants'); @@ -31,6 +30,7 @@ const { handleOrder, formingFinalResponse, populateCustomDataBasedOnCategory, + getCategoryFromEvent, } = require('./utils'); const { InstrumentationError, ConfigurationError } = require('../../util/errorTypes'); @@ -145,48 +145,6 @@ const responseBuilderSimple = (message, category, destination) => { ); }; -function getCategoryFromEvent(eventName) { - let category; - switch (eventName) { - case CONFIG_CATEGORIES.PRODUCT_LIST_VIEWED.type: - case CONFIG_CATEGORIES.PRODUCT_LIST_VIEWED.eventName: - category = CONFIG_CATEGORIES.PRODUCT_LIST_VIEWED; - break; - case CONFIG_CATEGORIES.PRODUCT_VIEWED.type: - category = CONFIG_CATEGORIES.PRODUCT_VIEWED; - break; - case CONFIG_CATEGORIES.PRODUCT_ADDED.type: - case CONFIG_CATEGORIES.PRODUCT_ADDED.eventName: - category = CONFIG_CATEGORIES.PRODUCT_ADDED; - break; - case CONFIG_CATEGORIES.ORDER_COMPLETED.type: - case CONFIG_CATEGORIES.ORDER_COMPLETED.eventName: - category = CONFIG_CATEGORIES.ORDER_COMPLETED; - break; - case CONFIG_CATEGORIES.PRODUCTS_SEARCHED.type: - case CONFIG_CATEGORIES.PRODUCTS_SEARCHED.eventName: - category = CONFIG_CATEGORIES.PRODUCTS_SEARCHED; - break; - case CONFIG_CATEGORIES.CHECKOUT_STARTED.type: - case CONFIG_CATEGORIES.CHECKOUT_STARTED.eventName: - category = CONFIG_CATEGORIES.CHECKOUT_STARTED; - break; - case CONFIG_CATEGORIES.PAGE_VIEW.eventName: - category = CONFIG_CATEGORIES.PAGE_VIEW; - break; - default: - category = CONFIG_CATEGORIES.SIMPLE_TRACK; - break; - } - - if (OTHER_STANDARD_EVENTS.includes(eventName)) { - category = CONFIG_CATEGORIES.OTHER_STANDARD; - category.eventName = eventName; - } - - return category; -} - const processEvent = (message, destination) => { if (!message.type) { throw new InstrumentationError("'type' is missing"); diff --git a/src/v0/destinations/facebook_pixel/utils.js b/src/v0/destinations/facebook_pixel/utils.js index 2bcd6a5ff2..3b8baba2d7 100644 --- a/src/v0/destinations/facebook_pixel/utils.js +++ b/src/v0/destinations/facebook_pixel/utils.js @@ -9,7 +9,12 @@ const { defaultRequestConfig, getHashFromArray, } = require('../../util'); -const { ACTION_SOURCES_VALUES, CONFIG_CATEGORIES, MAPPING_CONFIG } = require('./config'); +const { + ACTION_SOURCES_VALUES, + CONFIG_CATEGORIES, + MAPPING_CONFIG, + OTHER_STANDARD_EVENTS, +} = require('./config'); const { InstrumentationError, TransformationError } = require('../../util/errorTypes'); @@ -524,6 +529,48 @@ const populateCustomDataBasedOnCategory = ( return updatedCustomData; }; +const getCategoryFromEvent = (eventName) => { + let category; + switch (eventName) { + case CONFIG_CATEGORIES.PRODUCT_LIST_VIEWED.type: + case CONFIG_CATEGORIES.PRODUCT_LIST_VIEWED.eventName: + category = CONFIG_CATEGORIES.PRODUCT_LIST_VIEWED; + break; + case CONFIG_CATEGORIES.PRODUCT_VIEWED.type: + category = CONFIG_CATEGORIES.PRODUCT_VIEWED; + break; + case CONFIG_CATEGORIES.PRODUCT_ADDED.type: + case CONFIG_CATEGORIES.PRODUCT_ADDED.eventName: + category = CONFIG_CATEGORIES.PRODUCT_ADDED; + break; + case CONFIG_CATEGORIES.ORDER_COMPLETED.type: + case CONFIG_CATEGORIES.ORDER_COMPLETED.eventName: + category = CONFIG_CATEGORIES.ORDER_COMPLETED; + break; + case CONFIG_CATEGORIES.PRODUCTS_SEARCHED.type: + case CONFIG_CATEGORIES.PRODUCTS_SEARCHED.eventName: + category = CONFIG_CATEGORIES.PRODUCTS_SEARCHED; + break; + case CONFIG_CATEGORIES.CHECKOUT_STARTED.type: + case CONFIG_CATEGORIES.CHECKOUT_STARTED.eventName: + category = CONFIG_CATEGORIES.CHECKOUT_STARTED; + break; + case CONFIG_CATEGORIES.PAGE_VIEW.eventName: + category = CONFIG_CATEGORIES.PAGE_VIEW; + break; + default: + category = CONFIG_CATEGORIES.SIMPLE_TRACK; + break; + } + + if (OTHER_STANDARD_EVENTS.includes(eventName)) { + category = CONFIG_CATEGORIES.OTHER_STANDARD; + category.eventName = eventName; + } + + return category; +}; + const formingFinalResponse = ( userData, commonData, @@ -570,4 +617,5 @@ module.exports = { handleOrder, formingFinalResponse, populateCustomDataBasedOnCategory, + getCategoryFromEvent, };