Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: payment info entered event in facebook_conversions #3762

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/v0/destinations/facebook_conversions/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,31 @@ const validateProductSearchedData = (eventTypeCustomData) => {
}
};

const getProducts = (message, category) => {
let products = message.properties?.products;
koladilip marked this conversation as resolved.
Show resolved Hide resolved
if (['product added', 'product viewed', 'products searched'].includes(category.type)) {
return [message.properties];
}
if (
['payment info entered', 'product added to wishlist'].includes(category.type) &&
!Array.isArray(products)
) {
products = [message.properties];
}
return products;
};

const populateCustomDataBasedOnCategory = (customData, message, category, categoryToContent) => {
let eventTypeCustomData = {};
if (category.name) {
eventTypeCustomData = constructPayload(message, MAPPING_CONFIG[category.name]);
}
const products = getProducts(message, category);

switch (category.type) {
case 'product list viewed': {
const { contentIds, contents } = populateContentsAndContentIDs(
message.properties?.products,
products,
message.properties?.quantity,
);

Expand Down Expand Up @@ -119,9 +134,7 @@ const populateCustomDataBasedOnCategory = (customData, message, category, catego
}
case 'product added':
case 'product viewed':
case 'products searched':
case 'payment info entered':
case 'product added to wishlist': {
case 'products searched': {
const contentCategory = eventTypeCustomData.content_category;
const contentType =
message.properties?.content_type ||
Expand All @@ -131,7 +144,7 @@ const populateCustomDataBasedOnCategory = (customData, message, category, catego
categoryToContent,
DESTINATION.toLowerCase(),
);
const { contentIds, contents } = populateContentsAndContentIDs([message.properties]);
const { contentIds, contents } = populateContentsAndContentIDs(products);
eventTypeCustomData = {
...eventTypeCustomData,
content_ids: contentIds.length === 1 ? contentIds[0] : contentIds,
Expand All @@ -142,10 +155,12 @@ const populateCustomDataBasedOnCategory = (customData, message, category, catego
validateProductSearchedData(eventTypeCustomData);
break;
}
case 'payment info entered':
case 'product added to wishlist':
case 'order completed':
case 'checkout started': {
const { contentIds, contents } = populateContentsAndContentIDs(
message.properties?.products,
products,
message.properties?.quantity,
message.properties?.delivery_category,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ export const data = [
JSON_ARRAY: {},
FORM: {
data: [
'{"user_data":{"em":"48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08","zp":"03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4"},"event_name":"AddToWishlist","event_time":1699784211,"action_source":"website","custom_data":{"revenue":400,"additional_bet_index":0,"content_ids":[],"contents":[],"currency":"USD","value":400}}',
'{"user_data":{"em":"48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08","zp":"03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4"},"event_name":"AddToWishlist","event_time":1699784211,"action_source":"website","custom_data":{"revenue":400,"additional_bet_index":0,"content_ids":[],"contents":[],"currency":"USD","value":400,"num_items":0}}',
],
},
},
Expand Down Expand Up @@ -1104,8 +1104,143 @@ export const data = [
},
message_id: 'a80f82be-9bdc-4a9f-b2a5-15621ee41df8',
properties: {
revenue: 400,
additional_bet_index: 0,
application_tracking_enabled: 1,
content_name: 'Checkout',
content_type: 'product',
num_items: 1,
products: [
{
id: '12809',
price: 80,
quantity: 1,
},
],
revenue: 93.99,
},
timestamp: '2023-11-12T15:46:51.693229+05:30',
type: 'track',
},
destination: {
Config: {
limitedDataUsage: true,
blacklistPiiProperties: [
{
blacklistPiiProperties: '',
blacklistPiiHash: false,
},
],
accessToken: '09876',
datasetId: 'dummyID',
eventsToEvents: [
{
from: '',
to: '',
},
],
eventCustomProperties: [
{
eventCustomProperties: '',
},
],
removeExternalId: true,
whitelistPiiProperties: [
{
whitelistPiiProperties: '',
},
],
actionSource: 'website',
},
Enabled: true,
},
},
],
},
},
output: {
response: {
status: 200,
body: [
{
output: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://graph.facebook.com/v20.0/dummyID/events?access_token=09876',
headers: {},
params: {},
body: {
JSON: {},
XML: {},
JSON_ARRAY: {},
FORM: {
data: [
'{"user_data":{"em":"48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08","zp":"03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4"},"event_name":"AddPaymentInfo","event_time":1699784211,"action_source":"website","custom_data":{"application_tracking_enabled":1,"content_name":"Checkout","content_type":"product","num_items":1,"products":[{"id":"12809","price":80,"quantity":1}],"revenue":93.99,"content_ids":["12809"],"contents":[{"id":"12809","quantity":1,"item_price":80}],"currency":"USD","value":93.99}}',
],
},
},
files: {},
userId: '',
},
statusCode: 200,
},
],
},
},
mockFns: defaultMockFns,
},
{
name: 'facebook_conversions',
description: 'Track event with standard event payment info entered without products',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
message: {
anonymousId: 'c82cbdff-e5be-4009-ac78-cdeea09ab4b1',
channel: 'web',
context: {
device: {
id: 'df16bffa-5c3d-4fbb-9bce-3bab098129a7R',
manufacturer: 'Xiaomi',
model: 'Redmi 6',
name: 'xiaomi',
},
network: {
carrier: 'Banglalink',
},
os: {
name: 'android',
version: '8.1.0',
},
screen: {
height: '100',
density: 50,
},
traits: {
email: ' [email protected] ',
address: {
zip: 1234,
},
anonymousId: 'c82cbdff-e5be-4009-ac78-cdeea09ab4b1',
},
},
event: 'payment info entered',
integrations: {
All: true,
},
message_id: 'a80f82be-9bdc-4a9f-b2a5-15621ee41df8',
properties: {
application_tracking_enabled: 1,
content_name: 'Checkout',
content_type: 'product',
num_items: 1,
id: '12809',
price: 80,
quantity: 1,
revenue: 93.99,
},
timestamp: '2023-11-12T15:46:51.693229+05:30',
type: 'track',
Expand Down Expand Up @@ -1164,7 +1299,7 @@ export const data = [
JSON_ARRAY: {},
FORM: {
data: [
'{"user_data":{"em":"48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08","zp":"03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4"},"event_name":"AddPaymentInfo","event_time":1699784211,"action_source":"website","custom_data":{"revenue":400,"additional_bet_index":0,"content_ids":[],"contents":[],"currency":"USD","value":400}}',
'{"user_data":{"em":"48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08","zp":"03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4"},"event_name":"AddPaymentInfo","event_time":1699784211,"action_source":"website","custom_data":{"application_tracking_enabled":1,"content_name":"Checkout","content_type":"product","num_items":1,"id":"12809","price":80,"quantity":1,"revenue":93.99,"content_ids":["12809"],"contents":[{"id":"12809","quantity":1,"item_price":80}],"currency":"USD","value":93.99}}',
],
},
},
Expand Down
Loading