From 243555acbe10d42613c952a2865b0e9676d737c0 Mon Sep 17 00:00:00 2001 From: Anant Jain Date: Wed, 29 May 2024 16:59:24 +0530 Subject: [PATCH 1/2] fix: tiktok_v2 assigning value to undefined properties --- src/v0/destinations/tiktok_ads/transformV2.js | 4 + .../destinations/tiktok_ads/processor/data.ts | 103 ++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/src/v0/destinations/tiktok_ads/transformV2.js b/src/v0/destinations/tiktok_ads/transformV2.js index 4624ec91819..be7e4f84f35 100644 --- a/src/v0/destinations/tiktok_ads/transformV2.js +++ b/src/v0/destinations/tiktok_ads/transformV2.js @@ -42,6 +42,8 @@ const getTrackResponsePayload = (message, destConfig, event, setDefaultForConten // if contents is not present but we have properties.products present which has fields with superset of contents fields if (!payload.properties?.contents && message.properties?.products) { // retreiving data from products only when contents is not present + // properties object may be empty due which next line may give some error + payload.properties = payload.properties ? payload.properties : {}; payload.properties.contents = getContents(message, false); } @@ -55,6 +57,8 @@ const getTrackResponsePayload = (message, destConfig, event, setDefaultForConten } // setting content-type default value in case of all standard event except `page-view` if (!payload.properties?.content_type && setDefaultForContentType) { + // properties object may be empty due which next line may give some error + payload.properties = payload.properties ? payload.properties : {}; payload.properties.content_type = 'product'; } payload.event = event; diff --git a/test/integrations/destinations/tiktok_ads/processor/data.ts b/test/integrations/destinations/tiktok_ads/processor/data.ts index af58b66302e..4dfd32d6715 100644 --- a/test/integrations/destinations/tiktok_ads/processor/data.ts +++ b/test/integrations/destinations/tiktok_ads/processor/data.ts @@ -6971,6 +6971,109 @@ export const data = [ }, }, }, + { + name: 'tiktok_ads', + description: 'Test 46 -> V2 -> Standard Event with no properties', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + message: { + anonymousId: '21e13f4bc7ceddad', + channel: 'web', + context: { + traits: { + email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f', + }, + userAgent: + 'Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion', + ip: '13.57.97.131', + locale: 'en-US', + externalId: [ + { + type: 'tiktokExternalId', + id: 'f0e388f53921a51f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc', + }, + ], + }, + messageId: '84e26acc-56a5-4835-8233-591137fca468', + session_id: '3049dc4c-5a95-4ccd-a3e7-d74a7e411f22', + originalTimestamp: '2019-10-14T09:03:17.562Z', + timestamp: '2020-09-17T19:49:27Z', + type: 'track', + event: 'Search', + integrations: { + All: true, + }, + sentAt: '2019-10-14T09:03:22.563Z', + }, + destination: { + Config: { + version: 'v2', + accessToken: 'dummyAccessToken', + pixelCode: '{{PIXEL-CODE}}', + hashUserProperties: false, + sendCustomEvents: true, + }, + }, + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: { + version: '1', + type: 'REST', + method: 'POST', + endpoint: 'https://business-api.tiktok.com/open_api/v1.3/event/track/', + headers: { + 'Access-Token': 'dummyAccessToken', + 'Content-Type': 'application/json', + }, + params: {}, + body: { + JSON: { + event_source: 'web', + event_source_id: '{{PIXEL-CODE}}', + partner_name: 'RudderStack', + data: [ + { + event: 'Search', + event_id: '84e26acc-56a5-4835-8233-591137fca468', + event_time: 1600372167, + properties: { content_type: 'product' }, + user: { + locale: 'en-US', + email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f', + external_id: + 'f0e388f53921a51f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc', + ip: '13.57.97.131', + user_agent: + 'Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion', + }, + }, + ], + }, + JSON_ARRAY: {}, + XML: {}, + FORM: {}, + }, + files: {}, + userId: '', + }, + statusCode: 200, + }, + ], + }, + }, + }, { name: 'tiktok_ads', description: 'Testing if the event name provided as a string or not', From 45ca50cc3b5805bad9c52e536da643e6cdcf0d24 Mon Sep 17 00:00:00 2001 From: Anant Jain Date: Wed, 29 May 2024 17:06:41 +0530 Subject: [PATCH 2/2] chore: address comments --- src/v0/destinations/tiktok_ads/transformV2.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/v0/destinations/tiktok_ads/transformV2.js b/src/v0/destinations/tiktok_ads/transformV2.js index be7e4f84f35..8760dee52cf 100644 --- a/src/v0/destinations/tiktok_ads/transformV2.js +++ b/src/v0/destinations/tiktok_ads/transformV2.js @@ -43,7 +43,7 @@ const getTrackResponsePayload = (message, destConfig, event, setDefaultForConten if (!payload.properties?.contents && message.properties?.products) { // retreiving data from products only when contents is not present // properties object may be empty due which next line may give some error - payload.properties = payload.properties ? payload.properties : {}; + payload.properties = payload.properties || {}; payload.properties.contents = getContents(message, false); } @@ -58,7 +58,7 @@ const getTrackResponsePayload = (message, destConfig, event, setDefaultForConten // setting content-type default value in case of all standard event except `page-view` if (!payload.properties?.content_type && setDefaultForContentType) { // properties object may be empty due which next line may give some error - payload.properties = payload.properties ? payload.properties : {}; + payload.properties = payload.properties || {}; payload.properties.content_type = 'product'; } payload.event = event;