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: add new destination tiktok_audience #2710

Merged
merged 15 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/cdk/v2/bindings/default.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const crypto = require('crypto');
const {
InstrumentationError,
ConfigurationError,
Expand Down Expand Up @@ -47,7 +48,12 @@ function assertHttpResp(processedResponse, message) {
}
}

function MD5(data) {
return crypto.createHash('md5').update(data).digest('hex');
}

module.exports = {
MD5,
isValidEventType,
assert,
assertConfig,
Expand Down
9 changes: 9 additions & 0 deletions src/cdk/v2/destinations/tiktok_audience/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const ACTION_MAP = {
add: 'add',
remove: 'delete',
};
const SHA256_TRAITS = ['IDFA_SHA256', 'AAID_SHA256', 'EMAIL_SHA256', 'PHONE_SHA256'];
module.exports = {
ACTION_MAP,
SHA256_TRAITS,
};
67 changes: 67 additions & 0 deletions src/cdk/v2/destinations/tiktok_audience/procWorkflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

bindings:
- name: EventType
path: ../../../../constants
- path: ../../bindings/jsontemplate
exportAll: true
- path: ./config
- name: removeUndefinedAndNullValues
path: ../../../../v0/util
- name: defaultRequestConfig
path: ../../../../v0/util

steps:
- name: validateInput
template: |
let messageType = .message.type;
$.assert(.message.type, "message Type is not present. Aborting message.");
$.assert(.message.type.toLowerCase() ==='audiencelist', "Event type " + .message.type.toLowerCase() + " is not supported. Aborting message.");
$.assert(.message.properties, "Message properties is not present. Aborting message.");
$.assert(.message.properties.listData, "listData is not present inside properties. Aborting message.");
$.assert($.containsAll(Object.keys(.message.properties.listData), ["add", "remove"]), "unsupported action type. Aborting message.")

- name: prepareIdentifiersList
description: |
Populate list of identifiers to be updated
template: |
const destinationFields = .message.context.destinationFields.split(", ")
const audienceId = .message.context.externalId[0].type.split("-")[1];
const isHashRequired = .destination.Config.isHashRequired;
const advertiserIds = .metadata.secret.advertiserIds;
const hashTraits = function(traits) {
traits@trait.(destinationFields@destinationField.(
trait[destinationField] ? {
id: isHashRequired ?
destinationField in $.SHA256_TRAITS ?
$.SHA256(trait[destinationField]) : $.MD5(trait[destinationField])
: trait[destinationField],
audience_ids:[audienceId]
} : {}
)[])
};
const listData = .message.properties.listData;
const actions = Object.keys(listData)
actions@action.({
"batch_data": hashTraits(listData[action]),
"id_schema": destinationFields,
"advertiser_ids": advertiserIds,
"action": $.ACTION_MAP[action],
})[]


- name: buildResponseForProcessTransformation
description: build response
template: |
const accessToken = .metadata.secret.accessToken
const anonymousId = .message.anonymousId;
$.outputs.prepareIdentifiersList@body.(
let response = $.defaultRequestConfig();
response.body.JSON = body;
response.userId = anonymousId;
response.endpoint = "https://business-api.tiktok.com/open_api/v1.3/segment/mapping/";
response.headers = {
"Access-Token": accessToken,
"Content-Type": "application/json"
};
response
)
32 changes: 32 additions & 0 deletions src/cdk/v2/destinations/tiktok_audience/rtWorkflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
bindings:
- name: handleRtTfSingleEventError
path: ../../../../v0/util/index

steps:
- name: validateInput
template: |
$.assert(Array.isArray(^) && ^.length > 0, "Invalid event array")

- name: transform
externalWorkflow:
path: ./procWorkflow.yaml
loopOverInput: true

- name: successfulEvents
template: |
$.outputs.transform#idx.output.({
"batchedRequest": .,
"batched": true,
"destination": ^[idx].destination,
"metadata": ^[idx].metadata,
"statusCode": 200
})[]

- name: failedEvents
template: |
$.outputs.transform#idx.error.(
$.handleRtTfSingleEventError(^[idx], .originalError ?? ., {})
)[]
- name: finalPayload
template: |
[...$.outputs.failedEvents, ...$.outputs.successfulEvents]
3 changes: 2 additions & 1 deletion src/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"BRAZE": true,
"OPTIMIZELY_FULLSTACK": true,
"TWITTER_ADS": true,
"CLEVERTAP": true
"CLEVERTAP": true,
"TIKTOK_AUDIENCE": true
}
}
Loading
Loading