___INFO___ { "type": "TAG", "id": "cvt_temp_public_id", "version": 1, "securityGroups": [], "displayName": "DataNostro — TikTok Events API", "description": "Server-side TikTok Events API tag. Pixel ID + access token from Marketing API.", "containerContexts": ["SERVER"] } ___TEMPLATE_PARAMETERS___ [ {"type": "TEXT","name": "pixel_id","displayName": "Pixel ID","simpleValueType": true,"valueValidators": [{"type":"NON_EMPTY"}]}, {"type": "TEXT","name": "access_token","displayName": "Marketing API access token","simpleValueType": true,"valueValidators": [{"type":"NON_EMPTY"}]}, {"type": "TEXT","name": "event","displayName": "Event name","simpleValueType": true,"defaultValue": "CompletePayment"} ] ___SANDBOXED_JS_FOR_SERVER___ const sendHttpRequest = require("sendHttpRequest"); const getEventData = require("getEventData"); const getTimestampMillis = require("getTimestampMillis"); const sha256Sync = require("sha256Sync"); const url = "https://business-api.tiktok.com/open_api/v1.3/event/track/"; const body = { pixel_code: data.pixel_id, event: data.event, event_id: getEventData("event_id") || "", timestamp: Math.floor(getTimestampMillis() / 1000).toString(), context: { user: { email: getEventData("user_data.email_address") ? sha256Sync(getEventData("user_data.email_address").toLowerCase().trim(), {outputEncoding: "hex"}) : "", phone_number: getEventData("user_data.phone_number") ? sha256Sync(getEventData("user_data.phone_number"), {outputEncoding: "hex"}) : "", ttp: getEventData("user_data.ttp") || "" }, page: {url: getEventData("page_location") || ""} }, properties: { value: getEventData("value") || 0, currency: getEventData("currency") || "USD" } }; sendHttpRequest(url, {method: "POST", headers: {"Content-Type": "application/json", "Access-Token": data.access_token}}, JSON.stringify(body)); data.gtmOnSuccess(); ___SERVER_PERMISSIONS___ [ {"instance": {"key": {"publicId": "send_http"}, "param": [{"key": "allowedUrls","value": {"type": 1,"string": "specific"}},{"key": "urls","value": {"type": 2,"listItem": [{"type": 1,"string": "https://business-api.tiktok.com/*"}]}}]}} ] ___TESTS___ scenarios: [] ___NOTES___ TikTok Events API v1.3. Generate Marketing API access token in TikTok Ads Manager.