Skip to content

Commit

Permalink
feat: facebook pixel audit refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepdsvs committed Oct 11, 2023
1 parent 3ca8d7b commit 4377df3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 44 deletions.
44 changes: 1 addition & 43 deletions src/v0/destinations/facebook_pixel/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const {
MAPPING_CONFIG,
FB_PIXEL_DEFAULT_EXCLUSION,
STANDARD_ECOMM_EVENTS_TYPE,
OTHER_STANDARD_EVENTS,
} = require('./config');
const { EventType } = require('../../../constants');

Expand All @@ -31,6 +30,7 @@ const {
handleOrder,
formingFinalResponse,
populateCustomDataBasedOnCategory,
getCategoryFromEvent,
} = require('./utils');

const { InstrumentationError, ConfigurationError } = require('../../util/errorTypes');
Expand Down Expand Up @@ -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");
Expand Down
50 changes: 49 additions & 1 deletion src/v0/destinations/facebook_pixel/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -570,4 +617,5 @@ module.exports = {
handleOrder,
formingFinalResponse,
populateCustomDataBasedOnCategory,
getCategoryFromEvent,
};

0 comments on commit 4377df3

Please sign in to comment.