Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RequestClient, IntegrationError, APIError } from '@segment/actions-core'
import { StatsContext } from '@segment/actions-core/destination-kit'
import { ADOBE_TARGET_API_VERSION } from './versioning-info'

function getNestedObjects(obj: { [x: string]: any }, objectPath = '', attributes: { [x: string]: string } = {}) {
// Do not run on null or undefined
Expand Down Expand Up @@ -60,7 +61,7 @@ export default class AdobeTarget {
): Promise<IntegrationError | undefined> => {
try {
await this.request(
`https://${clientCode}.tt.omtrdc.net/rest/v1/profiles/thirdPartyId/${userId}?client=${clientCode}`,
`https://${clientCode}.tt.omtrdc.net/rest/${ADOBE_TARGET_API_VERSION}/profiles/thirdPartyId/${userId}?client=${clientCode}`,
{ method: 'get', skipResponseCloning: true }
)
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** ADOBE_TARGET_API_VERSION
* Endpoint segment uses: /rest/v1/profiles/thirdPartyId/{userId}
* API reference: https://experienceleague.adobe.com/en/docs/target-dev/developer/api/profile-apis/profiles-api
*/
export const ADOBE_TARGET_API_VERSION = 'v1'
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const API_VERSION = 'v5'
import { PINTEREST_CONVERSIONS_API_VERSION } from './versioning-info'

export const API_VERSION = PINTEREST_CONVERSIONS_API_VERSION
export const EVENT_NAME = {
ADD_TO_CART: 'add_to_cart',
CHECKOUT: 'checkout',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** PINTEREST_CONVERSIONS_API_VERSION
* Pinterest conversions API version.
* API reference: https://developers.pinterest.com/docs/api/v5/introduction
*/
export const PINTEREST_CONVERSIONS_API_VERSION = 'v5'
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Settings } from './generated-types'
import type { RedditConversionsTestAuthenticationError } from './types'
import standardEvent from './standardEvent'
import customEvent from './customEvent'
import { REDDIT_CONVERSIONS_API_VERSION } from './versioning-info'

const destination: DestinationDefinition<Settings> = {
name: 'Reddit Conversions API',
Expand Down Expand Up @@ -35,33 +36,36 @@ const destination: DestinationDefinition<Settings> = {
},
testAuthentication: async (request, { settings }) => {
try {
return await request(`https://ads-api.reddit.com/api/v2.0/conversions/events/${settings.ad_account_id}`, {
method: 'POST',
headers: {
Authorization: `Bearer ${settings.conversion_token}`
},
json: {
test_mode: true,
events: [
{
event_at: new Date().toISOString(),
user: {
email: 'test@example.com',
external_id: 'identity-test',
ip_address: '127.0.0.1',
user_agent: 'Mozilla/5.0'
},
event_type: {
tracking_type: 'PageVisit'
},
event_metadata: {
currency: 'USD',
value_decimal: 1
return await request(
`https://ads-api.reddit.com/api/${REDDIT_CONVERSIONS_API_VERSION}/conversions/events/${settings.ad_account_id}`,
{
method: 'POST',
headers: {
Authorization: `Bearer ${settings.conversion_token}`
},
json: {
test_mode: true,
events: [
{
event_at: new Date().toISOString(),
user: {
email: 'test@example.com',
external_id: 'identity-test',
ip_address: '127.0.0.1',
user_agent: 'Mozilla/5.0'
},
event_type: {
tracking_type: 'PageVisit'
},
event_metadata: {
currency: 'USD',
value_decimal: 1
}
}
}
]
]
}
}
})
)
} catch (err) {
const error = err as RedditConversionsTestAuthenticationError
if (error.response && error.response.status === 401) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
DatapProcessingOptions
} from './types'
import { processHashing } from '../../lib/hashing-utils'
import { REDDIT_CONVERSIONS_API_VERSION } from './versioning-info'

type EventMetadataType = StandardEvent['event_metadata'] | CustomEvent['event_metadata']
type ProductsType = StandardEvent['products'] | CustomEvent['products']
Expand All @@ -21,11 +22,14 @@ type ScreenDimensionsType = StandardEvent['screen_dimensions'] | CustomEvent['sc

export async function send(request: RequestClient, settings: Settings, payload: StandardEvent[] | CustomEvent[]) {
const data = createRedditPayload(payload, settings)
return request(`https://ads-api.reddit.com/api/v2.0/conversions/events/${settings.ad_account_id}`, {
method: 'POST',
headers: { Authorization: `Bearer ${settings.conversion_token}` },
json: JSON.parse(JSON.stringify(data))
})
return request(
`https://ads-api.reddit.com/api/${REDDIT_CONVERSIONS_API_VERSION}/conversions/events/${settings.ad_account_id}`,
{
method: 'POST',
headers: { Authorization: `Bearer ${settings.conversion_token}` },
json: JSON.parse(JSON.stringify(data))
}
)
}

function createRedditPayload(payloads: StandardEvent[] | CustomEvent[], settings: Settings): StandardEventPayload {
Expand Down Expand Up @@ -170,7 +174,7 @@ const smartHash = (value: string | undefined, cleaningFunction?: (value: string)
}

function cleanPhoneNumber(phoneNumber: string): string {
if (!phoneNumber) return ""
if (!phoneNumber) return ''
phoneNumber = phoneNumber.trim()
const prefix = '+'
if (phoneNumber.startsWith('+')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** REDDIT_CONVERSIONS_API_VERSION
* Reddit conversions API version.
* API reference: https://ads-api.reddit.com/docs/v2/changelog
*/
export const REDDIT_CONVERSIONS_API_VERSION = 'v2.0'
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
smartHash
} from './utils'
import { processHashing } from '../../../lib/hashing-utils'
import { SNAP_CONVERSIONS_API_VERSION } from '../versioning-info'

const CURRENCY_ISO_4217_CODES = new Set([
'USD',
Expand Down Expand Up @@ -687,7 +688,7 @@ const buildRequestURL = (settings: Settings, action_source: string | undefined,
})()
)

return `https://tr.snapchat.com/v3/${appOrPixelID}/events?access_token=${authToken}`
return `https://tr.snapchat.com/${SNAP_CONVERSIONS_API_VERSION}/${appOrPixelID}/events?access_token=${authToken}`
}

const validatePayload = (payload: ReturnType<typeof buildPayloadData>) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** SNAP_CONVERSIONS_API_VERSION
* Snapchat Conversions API version.
* API reference: https://developers.snap.com/api/marketing-api/Conversions-API/UsingTheAPI
*/
export const SNAP_CONVERSIONS_API_VERSION = 'v3'
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import nock from 'nock'
import { createTestIntegration, IntegrationError } from '@segment/actions-core'
import { BASE_URL, GET_AUDIENCE_URL, TIKTOK_API_VERSION } from '../constants'
import { BASE_URL, GET_AUDIENCE_URL } from '../constants'
import Destination from '../index'
import { TIKTOK_AUDIENCES_API_VERSION } from '../versioning-info'

const testDestination = createTestIntegration(Destination)

Expand Down Expand Up @@ -94,7 +95,7 @@ describe('TikTok Audiences', () => {

it('should create a new TikTok Audience', async () => {
nock(BASE_URL)
.post(`/${TIKTOK_API_VERSION}/segment/audience/`, {
.post(`/${TIKTOK_AUDIENCES_API_VERSION}/segment/audience/`, {
custom_audience_name: 'The Super Mario Brothers Fans',
advertiser_id: '42884288',
action: 'create'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import nock from 'nock'
import { createTestEvent, createTestIntegration } from '@segment/actions-core'
import Destination from '../../index'
import { BASE_URL, TIKTOK_API_VERSION } from '../../constants'
import { BASE_URL } from '../../constants'
import { TIKTOK_AUDIENCES_API_VERSION } from '../../versioning-info'

const testDestination = createTestIntegration(Destination)

Expand Down Expand Up @@ -66,7 +67,7 @@ const updateUsersRequestBody = {

describe('TiktokAudiences.addToAudience', () => {
it('should succeed if audience id is valid', async () => {
nock(`${BASE_URL}${TIKTOK_API_VERSION}`).post('/segment/mapping/', updateUsersRequestBody).reply(200)
nock(`${BASE_URL}${TIKTOK_AUDIENCES_API_VERSION}`).post('/segment/mapping/', updateUsersRequestBody).reply(200)

const r = await testDestination.testAction('addToAudience', {
auth,
Expand All @@ -85,7 +86,7 @@ describe('TiktokAudiences.addToAudience', () => {
})

it('should normalize and hash emails correctly', async () => {
nock(`${BASE_URL}${TIKTOK_API_VERSION}`)
nock(`${BASE_URL}${TIKTOK_AUDIENCES_API_VERSION}`)
.post('/segment/mapping/', {
advertiser_ids: ['123'],
action: 'add',
Expand Down Expand Up @@ -120,7 +121,7 @@ describe('TiktokAudiences.addToAudience', () => {
})

it('should normalize and hash phone correctly', async () => {
nock(`${BASE_URL}${TIKTOK_API_VERSION}`)
nock(`${BASE_URL}${TIKTOK_AUDIENCES_API_VERSION}`)
.post('/segment/mapping/', {
advertiser_ids: ['123'],
action: 'add',
Expand Down Expand Up @@ -179,7 +180,7 @@ describe('TiktokAudiences.addToAudience', () => {
}
})

nock(`${BASE_URL}${TIKTOK_API_VERSION}/segment/mapping/`)
nock(`${BASE_URL}${TIKTOK_AUDIENCES_API_VERSION}/segment/mapping/`)
.post(/.*/, {
id_schema: ['EMAIL_SHA256', 'PHONE_SHA256', 'IDFA_SHA256'],
advertiser_ids: [ADVERTISER_ID],
Expand Down Expand Up @@ -217,7 +218,7 @@ describe('TiktokAudiences.addToAudience', () => {
})

it('should fail if all the send fields are false', async () => {
nock(`${BASE_URL}${TIKTOK_API_VERSION}/segment/mapping/`).post(/.*/, updateUsersRequestBody).reply(200)
nock(`${BASE_URL}${TIKTOK_AUDIENCES_API_VERSION}/segment/mapping/`).post(/.*/, updateUsersRequestBody).reply(200)

await expect(
testDestination.testAction('addToAudience', {
Expand All @@ -238,7 +239,7 @@ describe('TiktokAudiences.addToAudience', () => {
).rejects.toThrow('At least one of `Send Email`, `Send Phone` or `Send Advertising ID` must be set to `true`.')
})
it('should fail if email and/or advertising_id is not in the payload', async () => {
nock(`${BASE_URL}${TIKTOK_API_VERSION}/segment/mapping/`).post(/.*/, updateUsersRequestBody).reply(400)
nock(`${BASE_URL}${TIKTOK_AUDIENCES_API_VERSION}/segment/mapping/`).post(/.*/, updateUsersRequestBody).reply(400)

delete event?.context?.device
delete event?.context?.traits
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import nock from 'nock'
import { createTestEvent, createTestIntegration, DynamicFieldResponse } from '@segment/actions-core'
import Destination from '../../index'
import { BASE_URL, TIKTOK_API_VERSION } from '../../constants'
import { BASE_URL } from '../../constants'
import { TIKTOK_AUDIENCES_API_VERSION } from '../../versioning-info'

const testDestination = createTestIntegration(Destination)

Expand Down Expand Up @@ -56,7 +57,7 @@ const updateUsersRequestBody = {

describe('TiktokAudiences.addUser', () => {
it('should succeed if audience id is valid', async () => {
nock(`${BASE_URL}${TIKTOK_API_VERSION}/segment/mapping/`).post(/.*/, updateUsersRequestBody).reply(200)
nock(`${BASE_URL}${TIKTOK_AUDIENCES_API_VERSION}/segment/mapping/`).post(/.*/, updateUsersRequestBody).reply(200)
await expect(
testDestination.testAction('addUser', {
event,
Expand All @@ -74,7 +75,7 @@ describe('TiktokAudiences.addUser', () => {
})

it('should normalize and hash emails correctly', async () => {
nock(`${BASE_URL}${TIKTOK_API_VERSION}/segment/mapping/`)
nock(`${BASE_URL}${TIKTOK_AUDIENCES_API_VERSION}/segment/mapping/`)
.post(/.*/, {
advertiser_ids: ['123'],
action: 'add',
Expand Down Expand Up @@ -109,7 +110,7 @@ describe('TiktokAudiences.addUser', () => {
})

it('should normalize and hash phone correctly', async () => {
nock(`${BASE_URL}${TIKTOK_API_VERSION}/segment/mapping/`)
nock(`${BASE_URL}${TIKTOK_AUDIENCES_API_VERSION}/segment/mapping/`)
.post(/.*/, {
advertiser_ids: ['123'],
action: 'add',
Expand Down Expand Up @@ -144,7 +145,7 @@ describe('TiktokAudiences.addUser', () => {
})

it('should fail if an audience id is invalid', async () => {
nock(`${BASE_URL}${TIKTOK_API_VERSION}/segment/mapping/`).post(/.*/, updateUsersRequestBody).reply(400)
nock(`${BASE_URL}${TIKTOK_AUDIENCES_API_VERSION}/segment/mapping/`).post(/.*/, updateUsersRequestBody).reply(400)

await expect(
testDestination.testAction('addUser', {
Expand All @@ -163,7 +164,7 @@ describe('TiktokAudiences.addUser', () => {
})

it('should fail if all the send fields are false', async () => {
nock(`${BASE_URL}${TIKTOK_API_VERSION}/segment/mapping/`).post(/.*/, updateUsersRequestBody).reply(200)
nock(`${BASE_URL}${TIKTOK_AUDIENCES_API_VERSION}/segment/mapping/`).post(/.*/, updateUsersRequestBody).reply(200)

await expect(
testDestination.testAction('addUser', {
Expand All @@ -184,7 +185,7 @@ describe('TiktokAudiences.addUser', () => {
).rejects.toThrow('At least one of `Send Email`, `Send Phone` or `Send Advertising ID` must be set to `true`.')
})
it('should fail if email and/or advertising_id is not in the payload', async () => {
nock(`${BASE_URL}${TIKTOK_API_VERSION}/segment/mapping/`).post(/.*/, updateUsersRequestBody).reply(400)
nock(`${BASE_URL}${TIKTOK_AUDIENCES_API_VERSION}/segment/mapping/`).post(/.*/, updateUsersRequestBody).reply(400)

delete event?.context?.device
delete event?.context?.traits
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import nock from 'nock'
import createRequestClient from '../../../../../core/src/create-request-client'
import { TikTokAudiences } from './index'
import { BASE_URL, TIKTOK_API_VERSION } from '../constants'
import { BASE_URL } from '../constants'
import { TIKTOK_AUDIENCES_API_VERSION } from '../versioning-info'
const settings = {
advertiser_ids: ['1234567890', '0987654321', '2345675643']
}
Expand All @@ -13,7 +14,7 @@ describe('TikTok', () => {
const tiktok: TikTokAudiences = new TikTokAudiences(requestClient)

it('should fetch a list of advertisers, with their names', async () => {
nock(`${BASE_URL}${TIKTOK_API_VERSION}/advertiser/info`)
nock(`${BASE_URL}${TIKTOK_AUDIENCES_API_VERSION}/advertiser/info`)
.get(`/`)
.query({ advertiser_ids: JSON.stringify(settings.advertiser_ids) })
.reply(200, {
Expand Down Expand Up @@ -86,7 +87,7 @@ describe('TikTok', () => {
})

it('should fallback to stored advertiser_ids if tiktok returns an error', async () => {
nock(`${BASE_URL}${TIKTOK_API_VERSION}/advertiser/info`)
nock(`${BASE_URL}${TIKTOK_AUDIENCES_API_VERSION}/advertiser/info`)
.get(`/`)
.query({ advertiser_ids: JSON.stringify(settings.advertiser_ids) })
.reply(500, {
Expand Down Expand Up @@ -125,7 +126,7 @@ describe('TikTok', () => {
const page_number = 1

it('should dynamically fetch list of audiences and name', async () => {
nock(`${BASE_URL}${TIKTOK_API_VERSION}/dmp/custom_audience/list/`)
nock(`${BASE_URL}${TIKTOK_AUDIENCES_API_VERSION}/dmp/custom_audience/list/`)
.get(`/`)
.query({
advertiser_id: selected_advertiser_id,
Expand Down
Loading
Loading