Skip to content

Commit

Permalink
feat(facebook): update content_type mapping logic for fb conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepdsvs committed Feb 21, 2024
1 parent 0eb6684 commit 175dfa1
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions src/v0/destinations/facebook_conversions/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,26 @@ const populateCustomDataBasedOnCategory = (customData, message, category, catego
);

const contentCategory = eventTypeCustomData.content_category;
let contentType;
let defaultContentType;
if (contentIds.length > 0) {
contentType = 'product';
defaultContentType = 'product';
} else if (contentCategory) {
contentIds.push(contentCategory);
contents.push({
id: contentCategory,
quantity: 1,
});
contentType = 'product_group';
defaultContentType = 'product_group';
}
const contentType =
message.properties?.content_type ||
getContentType(message, defaultContentType, categoryToContent, DESTINATION.toLowerCase());

eventTypeCustomData = {
...eventTypeCustomData,
content_ids: contentIds,
contents,
content_type: getContentType(
message,
contentType,
categoryToContent,
DESTINATION.toLowerCase(),
),
content_type: contentType,
content_category: getContentCategory(contentCategory),
};
break;
Expand All @@ -125,18 +123,20 @@ const populateCustomDataBasedOnCategory = (customData, message, category, catego
case 'payment info entered':
case 'product added to wishlist': {
const contentCategory = eventTypeCustomData.content_category;
const contentType = eventTypeCustomData.content_type;
const contentType =
message.properties?.content_type ||
getContentType(
message,
eventTypeCustomData.content_type,
categoryToContent,
DESTINATION.toLowerCase(),
);
const { contentIds, contents } = populateContentsAndContentIDs([message.properties]);
eventTypeCustomData = {
...eventTypeCustomData,
content_ids: contentIds,
contents,
content_type: getContentType(
message,
contentType,
categoryToContent,
DESTINATION.toLowerCase(),
),
content_type: contentType,
content_category: getContentCategory(contentCategory),
};
validateProductSearchedData(eventTypeCustomData);
Expand All @@ -151,18 +151,20 @@ const populateCustomDataBasedOnCategory = (customData, message, category, catego
);

const contentCategory = eventTypeCustomData.content_category;
const contentType = eventTypeCustomData.content_type;
const contentType =
message.properties?.content_type ||
getContentType(
message,
eventTypeCustomData.content_type,
categoryToContent,
DESTINATION.toLowerCase(),
);

eventTypeCustomData = {
...eventTypeCustomData,
content_ids: contentIds,
contents,
content_type: getContentType(
message,
contentType,
categoryToContent,
DESTINATION.toLowerCase(),
),
content_type: contentType,
content_category: getContentCategory(contentCategory),
num_items: contentIds.length,
};
Expand Down

0 comments on commit 175dfa1

Please sign in to comment.