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: trade desk enrichTrackPayload util #3059

Merged
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
9 changes: 7 additions & 2 deletions src/cdk/v2/destinations/the_trade_desk/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ const prepareItemsPayload = (message) => {
let items;
const eventMapInfo = ECOMM_EVENT_MAP[event.toLowerCase()];
if (eventMapInfo?.itemsArray) {
// if event is one of the supported ecommerce events and products array is present
items = prepareItemsFromProducts(message);
} else if (eventMapInfo) {
// if event is one of the supported ecommerce events and products array is not present
items = prepareItemsFromProperties(message);
}
return items;
Expand Down Expand Up @@ -304,14 +306,17 @@ const enrichTrackPayload = (message, payload) => {
if (eventsMapInfo && !eventsMapInfo.itemsArray) {
const itemExclusionList = generateExclusionList(ITEM_CONFIGS);
rawPayload = extractCustomFields(message, rawPayload, ['properties'], itemExclusionList);
} else {
// for custom events
} else if (eventsMapInfo) {
// for ecomm events with products array supports. e.g Order Completed event
rawPayload = extractCustomFields(
message,
rawPayload,
['properties'],
['products', 'revenue', 'value'],
);
} else {
// for custom events
rawPayload = extractCustomFields(message, rawPayload, ['properties'], ['value']);
}
return rawPayload;
};
Expand Down
28 changes: 19 additions & 9 deletions src/cdk/v2/destinations/the_trade_desk/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,25 +635,35 @@ describe('enrichTrackPayload', () => {
order_id: 'ord123',
property1: 'value1',
property2: 'value2',
revenue: 10,
value: 11,
products: [
{
product_id: 'prd123',
test: 'test',
},
],
},
};
const payload = {
order_id: 'ord123',
value: 11,
};
let expectedPayload = {
const expectedPayload = {
order_id: 'ord123',
property1: 'value1',
property2: 'value2',
revenue: 10,
value: 11,
products: [
{
product_id: 'prd123',
test: 'test',
},
],
};

let result = enrichTrackPayload(message, payload);
const result = enrichTrackPayload(message, payload);
expect(result).toEqual(expectedPayload);

expectedPayload = {
order_id: 'ord123',
property1: 'value1',
property2: 'value2',
};
expect(enrichTrackPayload(message, {})).toEqual(expectedPayload);
});
});
14 changes: 14 additions & 0 deletions test/integrations/destinations/the_trade_desk/router/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1681,9 +1681,16 @@ export const data = [
properties: {
key1: 'value1',
value: 25,
revenue: 10,
product_id: 'prd123',
key2: true,
test: 'test123',
products: [
{
product_id: 'prd123',
test: 'test',
},
],
},
},
destination: sampleDestination,
Expand Down Expand Up @@ -1779,6 +1786,13 @@ export const data = [
test: 'test123',
key1: 'value1',
key2: true,
revenue: 10,
products: [
{
product_id: 'prd123',
test: 'test',
},
],
},
],
},
Expand Down
Loading