Skip to content

Commit

Permalink
feat: onboard new tiktok version events 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 committed Dec 28, 2023
1 parent 429ca71 commit 8e86313
Show file tree
Hide file tree
Showing 8 changed files with 1,978 additions and 69 deletions.
11 changes: 11 additions & 0 deletions src/v0/destinations/tiktok_ads/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const ConfigCategory = {
type: 'track',
name: 'TikTokTrack',
},
TRACK_V2: {
type: 'track',
name: 'TikTokTrackV2',
},
};

const PARTNER_NAME = 'RudderStack';
Expand All @@ -32,12 +36,19 @@ const eventNameMapping = {

const mappingConfig = getMappingConfig(ConfigCategory, __dirname);

// tiktok docs for max batch size for events 2.0: https://business-api.tiktok.com/portal/docs?id=1771100779668482
const maxBatchSizeV2 = 1000;
const trackEndpointV2 = 'https://business-api.tiktok.com/open_api/v1.3/event/track/';

module.exports = {
TRACK_ENDPOINT,
BATCH_ENDPOINT,
MAX_BATCH_SIZE,
PARTNER_NAME,
trackMapping: mappingConfig[ConfigCategory.TRACK.name],
trackMappingV2: mappingConfig[ConfigCategory.TRACK_V2.name],
eventNameMapping,
DESTINATION: 'TIKTOK_ADS',
trackEndpointV2,
maxBatchSizeV2,
};
16 changes: 16 additions & 0 deletions src/v0/destinations/tiktok_ads/data/TikTokTrack.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@
"type": "toString"
}
},
{
"destKey": "properties.shop_id",
"sourceKeys": ["properties.shop_id", "properties.shopId"],
"required": false,
"metadata": {
"type": "toString"
}
},
{
"destKey": "properties.order_id",
"sourceKeys": ["properties.order_id", "properties.orderId"],
"required": false,
"metadata": {
"type": "toString"
}
},
{
"destKey": "properties.content_type",
"sourceKeys": ["properties.contentType", "properties.content_type"],
Expand Down
128 changes: 128 additions & 0 deletions src/v0/destinations/tiktok_ads/data/TikTokTrackV2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
[
{
"destKey": "event_id",
"sourceKeys": ["properties.eventId", "properties.event_id", "messageId"],
"required": false
},
{
"destKey": "event_time",
"sourceKeys": "timestamp",
"sourceFromGenericMap": true,
"required": true,
"metadata": {
"type": "secondTimestamp"
}
},
{
"destKey": "test_event_code",
"sourceKeys": "properties.testEventCode",
"required": false
},
{
"destKey": "limited_data_use",
"sourceKeys": "properties.limited_data_use",
"required": false
},
{
"destKey": "properties.contents",
"sourceKeys": "properties.contents",
"required": false
},
{
"destKey": "properties.content_type",
"sourceKeys": ["properties.contentType", "properties.content_type"],
"metadata": {
"defaultValue": "product"
}
},
{
"destKey": "properties.shop_id",
"sourceKeys": ["properties.shop_id", "properties.shopId"],
"required": false,
"metadata": {
"type": "toString"
}
},
{
"destKey": "properties.order_id",
"sourceKeys": ["properties.order_id", "properties.orderId"],
"required": false,
"metadata": {
"type": "toString"
}
},
{
"destKey": "properties.currency",
"sourceKeys": "properties.currency",
"required": false
},
{
"destKey": "properties.value",
"sourceKeys": "properties.value",
"required": false
},
{
"destKey": "properties.description",
"sourceKeys": "properties.description",
"required": false
},
{
"destKey": "properties.query",
"sourceKeys": "properties.query",
"required": false
},
{
"destKey": "page.url",
"sourceKeys": ["properties.url", "context.page.url"],
"required": true
},
{
"destKey": "page.referrer",
"sourceKeys": ["properties.referrer", "context.page.referrer"],
"required": false
},
{
"destKey": "user.locale",
"sourceKeys": "context.locale",
"required": false
},
{
"destKey": "user.ttclid",
"sourceKeys": "properties.ttclid",
"required": false
},
{
"destKey": "user.ttp",
"sourceKeys": "properties.ttp",
"required": false
},
{
"destKey": "user.email",
"sourceKeys": [
"context.user.email",
"traits.email",
"context.traits.email",
"properties.email"
],
"metadata": {
"type": ["trim", "toLower"]
},
"required": false
},
{
"destKey": "user.phone",
"sourceKeys": "phone",
"sourceFromGenericMap": true,
"required": false
},
{
"destKey": "user.ip",
"sourceKeys": ["context.ip", "request_ip"],
"required": false
},
{
"destKey": "user.user_agent",
"sourceKeys": "context.userAgent",
"required": false
}
]
10 changes: 9 additions & 1 deletion src/v0/destinations/tiktok_ads/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const {
handleRtTfSingleEventError,
batchMultiplexedEvents,
} = require('../../util');
const { process: processV2, processRouterDest: processRouterDestV2 } = require('./transformV2');
const { getContents } = require('./util');
const {
trackMapping,
Expand Down Expand Up @@ -165,7 +166,9 @@ const trackResponseBuilder = async (message, { Config }) => {

const process = async (event) => {
const { message, destination } = event;

if (destination.Config?.version === 'v2') {
return processV2(event);
}
if (!destination.Config.accessToken) {
throw new ConfigurationError('Access Token not found. Aborting ');
}
Expand Down Expand Up @@ -240,6 +243,11 @@ function getEventChunks(event, trackResponseList, eventsChunk) {
}

const processRouterDest = async (inputs, reqMetadata) => {
const { destination } = inputs[0];
const { Config } = destination;
if (Config?.version === 'v2') {
return processRouterDestV2(inputs, reqMetadata);
}
const errorRespEvents = checkInvalidRtTfEvents(inputs);
if (errorRespEvents.length > 0) {
return errorRespEvents;
Expand Down
Loading

0 comments on commit 8e86313

Please sign in to comment.