Skip to content

Commit

Permalink
fix: tiktok_v2 assigning value to undefined properties (#3426)
Browse files Browse the repository at this point in the history
* fix: tiktok_v2 assigning value to undefined properties

* chore: address comments
  • Loading branch information
anantjain45823 authored May 29, 2024
1 parent cd0b81b commit 323396b
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/v0/destinations/tiktok_ads/transformV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.contents = getContents(message, false);
}

Expand All @@ -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.content_type = 'product';
}
payload.event = event;
Expand Down
103 changes: 103 additions & 0 deletions test/integrations/destinations/tiktok_ads/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 323396b

Please sign in to comment.