Skip to content

Commit

Permalink
fix: tiktok_v2 remove default value for content-type for custom events (
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 authored May 22, 2024
1 parent c249a69 commit 6e7b5a0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
5 changes: 1 addition & 4 deletions src/v0/destinations/tiktok_ads/data/TikTokTrackV2.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
},
{
"destKey": "properties.content_type",
"sourceKeys": ["properties.contentType", "properties.content_type"],
"metadata": {
"defaultValue": "product"
}
"sourceKeys": ["properties.contentType", "properties.content_type"]
},
{
"destKey": "properties.shop_id",
Expand Down
16 changes: 12 additions & 4 deletions src/v0/destinations/tiktok_ads/transformV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const { JSON_MIME_TYPE } = require('../../util/constant');
* @param {*} event
* @returns track payload
*/
const getTrackResponsePayload = (message, destConfig, event) => {
const getTrackResponsePayload = (message, destConfig, event, setDefaultForContentType = true) => {
const payload = constructPayload(message, trackMappingV2);

// if contents is not an array converting it into array
Expand All @@ -53,6 +53,10 @@ const getTrackResponsePayload = (message, destConfig, event) => {
if (destConfig.hashUserProperties && isDefinedAndNotNullAndNotEmpty(payload.user)) {
payload.user = hashUserField(payload.user);
}
// setting content-type default value in case of all standard event except `page-view`
if (!payload.properties?.content_type && setDefaultForContentType) {
payload.properties.content_type = 'product';
}
payload.event = event;
// add partner name and return payload
return removeUndefinedAndNullValues(payload);
Expand Down Expand Up @@ -90,13 +94,17 @@ const trackResponseBuilder = async (message, { Config }) => {
});
}
});
} else {
} else if (!eventNameMapping[event]) {
/*
Custom Event Case -> if there exists no event mapping we will build payload with custom event recieved
For custom event we do not want to lower case the event or trim it we just want to send those as it is
Doc https://ads.tiktok.com/help/article/standard-events-parameters?lang=en
*/
event = eventNameMapping[event] || message.event;
// if there exists no event mapping we will build payload with custom event recieved
event = message.event;
responseList.push(getTrackResponsePayload(message, Config, event, false));
} else {
// incoming event name is already a standard event name
event = eventNameMapping[event];
responseList.push(getTrackResponsePayload(message, Config, event));
}
// set event source and event_source_id
Expand Down
4 changes: 1 addition & 3 deletions test/integrations/destinations/tiktok_ads/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5224,7 +5224,6 @@ export const data = [
event_id: '1616318632825_357',
event_time: 1600372167,
properties: {
content_type: 'product',
contents: [
{
price: 8,
Expand Down Expand Up @@ -6872,7 +6871,7 @@ export const data = [
},
{
name: 'tiktok_ads',
description: 'Test 46 -> V2 -> Event with no properties',
description: 'Test 46 -> V2 -> Custom Event with no properties',
feature: 'processor',
module: 'destination',
version: 'v0',
Expand Down Expand Up @@ -6947,7 +6946,6 @@ export const data = [
event: 'customEvent',
event_id: '84e26acc-56a5-4835-8233-591137fca468',
event_time: 1600372167,
properties: { content_type: 'product' },
user: {
locale: 'en-US',
email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f',
Expand Down

0 comments on commit 6e7b5a0

Please sign in to comment.