Skip to content

Commit

Permalink
fix: trade desk enrichTrackPayload util (#3059)
Browse files Browse the repository at this point in the history
fix: trade desk extract custom properties util
  • Loading branch information
Gauravudia authored Feb 6, 2024
1 parent 61462b6 commit 6919a9e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
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

0 comments on commit 6919a9e

Please sign in to comment.