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

refactor: split trade desk into audience and realtime conversions destinations #3091

Merged
merged 4 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
60 changes: 1 addition & 59 deletions src/cdk/v2/destinations/the_trade_desk/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const { getMappingConfig } = require('../../../../v0/util');

const SUPPORTED_EVENT_TYPE = ['record', 'track'];
const SUPPORTED_EVENT_TYPE = ['record'];
const ACTION_TYPES = ['insert', 'delete'];
const DATA_PROVIDER_ID = 'rudderstack';

Expand All @@ -15,66 +13,10 @@ const DATA_SERVERS_BASE_ENDPOINTS_MAP = {
china: 'https://data-cn2.adsrvr.cn',
};

// ref:- https://partner.thetradedesk.com/v3/portal/data/doc/DataConversionEventsApi
const REAL_TIME_CONVERSION_ENDPOINT = 'https://insight.adsrvr.org/track/realtimeconversion';

const CONVERSION_SUPPORTED_ID_TYPES = [
'TDID',
'IDFA',
'AAID',
'DAID',
'NAID',
'IDL',
'EUID',
'UID2',
];

const ECOMM_EVENT_MAP = {
'product added': {
event: 'addtocart',
rootLevelPriceSupported: true,
},
'order completed': {
event: 'purchase',
itemsArray: true,
revenueFieldSupported: true,
},
'product viewed': {
event: 'viewitem',
rootLevelPriceSupported: true,
},
'checkout started': {
event: 'startcheckout',
itemsArray: true,
revenueFieldSupported: true,
},
'cart viewed': {
event: 'viewcart',
itemsArray: true,
},
'product added to wishlist': {
event: 'wishlistitem',
rootLevelPriceSupported: true,
},
};

const CONFIG_CATEGORIES = {
COMMON_CONFIGS: { name: 'TTDCommonConfig' },
ITEM_CONFIGS: { name: 'TTDItemConfig' },
};

const MAPPING_CONFIG = getMappingConfig(CONFIG_CATEGORIES, __dirname);

module.exports = {
SUPPORTED_EVENT_TYPE,
ACTION_TYPES,
DATA_PROVIDER_ID,
MAX_REQUEST_SIZE_IN_BYTES: 2500000,
DATA_SERVERS_BASE_ENDPOINTS_MAP,
CONVERSION_SUPPORTED_ID_TYPES,
CONFIG_CATEGORIES,
COMMON_CONFIGS: MAPPING_CONFIG[CONFIG_CATEGORIES.COMMON_CONFIGS.name],
ITEM_CONFIGS: MAPPING_CONFIG[CONFIG_CATEGORIES.ITEM_CONFIGS.name],
ECOMM_EVENT_MAP,
REAL_TIME_CONVERSION_ENDPOINT,
};
18 changes: 6 additions & 12 deletions src/cdk/v2/destinations/the_trade_desk/rtWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ bindings:
path: ../../../../constants
- name: processRecordInputs
path: ./transformRecord
- name: processConversionInputs
path: ./transformConversion
- name: handleRtTfSingleEventError
path: ../../../../v0/util/index
- name: InstrumentationError
path: '@rudderstack/integrations-lib'

steps:
- name: validateCommonConfig
description: |
validate common config for first party data and realtime conversion flow
- name: validateConfig
template: |
const config = ^[0].destination.Config
$.assertConfig(config.audienceId, "Segment name/Audience ID is not present. Aborting")
$.assertConfig(config.advertiserId, "Advertiser ID is not present. Aborting")
$.assertConfig(config.advertiserSecretKey, "Advertiser Secret Key is not present. Aborting")
config.ttlInDays ? $.assertConfig(config.ttlInDays >=0 && config.ttlInDays <= 180, "TTL is out of range. Allowed values are 0 to 180 days")

- name: validateInput
template: |
Expand All @@ -26,22 +25,17 @@ steps:
template: |
$.processRecordInputs(^.{.message.type === $.EventType.RECORD}[], ^[0].destination)

- name: processConversionEvents
template: |
$.processConversionInputs(^.{.message.type === $.EventType.TRACK}[])

- name: failOtherEvents
template: |
const otherEvents = ^.{.message.type !== $.EventType.TRACK && .message.type !== $.EventType.RECORD}[]
const otherEvents = ^.{.message.type !== $.EventType.RECORD}[]
let failedEvents = otherEvents.map(
function(event) {
const error = new $.InstrumentationError("Event type " + event.message.type + " is not supported");
$.handleRtTfSingleEventError(event, error, {})
}
)

failedEvents ?? []

- name: finalPayload
template: |
[...$.outputs.processRecordEvents, ...$.outputs.processConversionEvents, ...$.outputs.failOtherEvents]
[...$.outputs.processRecordEvents, ...$.outputs.failOtherEvents]
98 changes: 0 additions & 98 deletions src/cdk/v2/destinations/the_trade_desk/transformConversion.js

This file was deleted.

18 changes: 1 addition & 17 deletions src/cdk/v2/destinations/the_trade_desk/transformRecord.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { InstrumentationError, ConfigurationError } = require('@rudderstack/integrations-lib');
const { InstrumentationError } = require('@rudderstack/integrations-lib');
const { BatchUtils } = require('@rudderstack/workflow-engine');
const {
defaultPostRequestConfig,
Expand All @@ -13,20 +13,6 @@ const tradeDeskConfig = require('./config');

const { DATA_PROVIDER_ID } = tradeDeskConfig;

const validateConfig = (config) => {
if (!config.advertiserSecretKey) {
throw new ConfigurationError('Advertiser Secret Key is not present. Aborting');
}

if (config.ttlInDays && !(config.ttlInDays >= 0 && config.ttlInDays <= 180)) {
throw new ConfigurationError('TTL is out of range. Allowed values are 0 to 180 days');
}

if (!config.audienceId) {
throw new ConfigurationError('Segment name/Audience ID is not present. Aborting');
}
};

const responseBuilder = (items, config) => {
const { advertiserId, dataServer } = config;

Expand Down Expand Up @@ -64,8 +50,6 @@ const processRecordInputs = (inputs, destination) => {
return [];
}

validateConfig(Config);

const invalidActionTypeError = new InstrumentationError(
'Invalid action type. You can only add or remove IDs from the audience/segment',
);
Expand Down
Loading
Loading