Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: onboard new tiktok version events 2.0 #2961

Merged
merged 10 commits into from
Jan 18, 2024
10 changes: 10 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,18 @@ 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
133 changes: 133 additions & 0 deletions src/v0/destinations/tiktok_ads/data/TikTokTrackV2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
[
{
"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": "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.context.page.url", "properties.url", "context.page.url"],
koladilip marked this conversation as resolved.
Show resolved Hide resolved
"required": true
},
{
"destKey": "page.referrer",
"sourceKeys": [
"properties.context.page.referrer",
"properties.referrer",
"context.page.referrer"
],
"required": false
},
{
"destKey": "user.locale",
"sourceKeys": ["properties.context.user.locale", "context.locale"],
"required": false
},
{
"destKey": "user.ttclid",
"sourceKeys": "properties.ttclid",
"required": false
},
{
"destKey": "user.ttp",
"sourceKeys": ["properties.context.user.ttp", "properties.ttp"],
"required": false
},
{
"destKey": "user.email",
"sourceKeys": [
ItsSudip marked this conversation as resolved.
Show resolved Hide resolved
"properties.context.user.email",
"context.user.email",
"traits.email",
"context.traits.email",
"properties.email"
],
"metadata": {
"type": ["trim", "toLower"]
},
"required": false
},
{
"destKey": "user.phone",
"sourceKeys": [
"properties.context.user.phone",
"traits.phone",
"context.traits.phone",
"properties.phone"
],
"sourceFromGenericMap": false,
"required": false
},
{
"destKey": "user.ip",
"sourceKeys": ["properties.context.user.ip", "context.ip", "request_ip"],
"required": false
},
{
"destKey": "user.user_agent",
"sourceKeys": ["properties.context.user.userAgent", "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
Loading