diff --git a/packages/destination-actions/src/destinations/first-party-dv360/_tests_/index.test.ts b/packages/destination-actions/src/destinations/first-party-dv360/_tests_/index.test.ts index 0ffd7ede63..0b72875a12 100644 --- a/packages/destination-actions/src/destinations/first-party-dv360/_tests_/index.test.ts +++ b/packages/destination-actions/src/destinations/first-party-dv360/_tests_/index.test.ts @@ -53,7 +53,7 @@ beforeEach(() => { // Create Audience Tests describe('Audience Destination', () => { describe('createAudience', () => { - it('creates an audience successfully with feature flag ON (v4)', async () => { + it('creates an audience successfully with CANARY VERSION', async () => { nock('https://displayvideo.googleapis.com') .post('/v4/firstPartyAndPartnerAudiences?advertiserId=12345', { displayName: audienceName, @@ -68,27 +68,7 @@ describe('Audience Destination', () => { const result = await testDestination.createAudience({ ...createAudienceInput, - features: { 'actions-first-party-dv360-version-update': true } - }) - expect(result).toEqual({ externalId: 'audience-id-123' }) - }) - - it('creates an audience successfully with feature flag OFF (v3)', async () => { - nock('https://displayvideo.googleapis.com') - .post('/v3/firstAndThirdPartyAudiences?advertiserId=12345', { - displayName: audienceName, - audienceType: 'CUSTOMER_MATCH_CONTACT_INFO', - membershipDurationDays: '30', - description: 'Test description', - audienceSource: 'AUDIENCE_SOURCE_UNSPECIFIED', - firstAndThirdPartyAudienceType: 'FIRST_AND_THIRD_PARTY_AUDIENCE_TYPE_FIRST_PARTY' - }) - .matchHeader('Authorization', 'Bearer temp-token') - .reply(200, { firstAndThirdPartyAudienceId: 'audience-id-123' }) - - const result = await testDestination.createAudience({ - ...createAudienceInput, - features: { 'actions-first-party-dv360-version-update': false } + features: { 'first-party-dv360-canary-version': true } }) expect(result).toEqual({ externalId: 'audience-id-123' }) }) @@ -100,7 +80,7 @@ describe('Audience Destination', () => { }) describe('getAudience', () => { - it('should succeed with feature flag ON (v4)', async () => { + it('should succeed with CANARY VERSION', async () => { nock('https://displayvideo.googleapis.com') .get(`/v4/firstPartyAndPartnerAudiences/audience-id-123?advertiserId=12345`) .matchHeader('Authorization', 'Bearer temp-token') @@ -108,20 +88,7 @@ describe('Audience Destination', () => { const result = await testDestination.getAudience({ ...getAudienceInput, - features: { 'actions-first-party-dv360-version-update': true } - }) - expect(result).toEqual({ externalId: 'audience-id-123' }) - }) - - it('should succeed with feature flag OFF (v3)', async () => { - nock('https://displayvideo.googleapis.com') - .get(`/v3/firstAndThirdPartyAudiences/audience-id-123?advertiserId=12345`) - .matchHeader('Authorization', 'Bearer temp-token') - .reply(200, { firstAndThirdPartyAudienceId: 'audience-id-123' }) - - const result = await testDestination.getAudience({ - ...getAudienceInput, - features: { 'actions-first-party-dv360-version-update': false } + features: { 'first-party-dv360-canary-version': true } }) expect(result).toEqual({ externalId: 'audience-id-123' }) }) @@ -164,14 +131,14 @@ describe('Audience Destination', () => { } }) - it('should add customer match members successfully with feature flag ON (v4)', async () => { + it('should add customer match members successfully with CANARY VERSION', async () => { nock('https://displayvideo.googleapis.com') .post('/v4/firstPartyAndPartnerAudiences/audience-id-123:editCustomerMatchMembers') .reply(200, { firstPartyAndPartnerAudienceId: 'audience-id-123' }) const result = await testDestination.testAction('addToAudContactInfo', { event, useDefaultMappings: true, - features: { 'actions-first-party-dv360-version-update': true } + features: { 'first-party-dv360-canary-version': true } }) expect(result).toContainEqual( expect.objectContaining({ @@ -181,24 +148,7 @@ describe('Audience Destination', () => { }) ) }) - it('should add customer match members successfully with feature flag OFF (v3)', async () => { - nock('https://displayvideo.googleapis.com') - .post('/v3/firstAndThirdPartyAudiences/audience-id-123:editCustomerMatchMembers') - .reply(200, { firstAndThirdPartyAudienceId: 'audience-id-123' }) - const result = await testDestination.testAction('addToAudContactInfo', { - event, - useDefaultMappings: true, - features: { 'actions-first-party-dv360-version-update': false } - }) - expect(result).toContainEqual( - expect.objectContaining({ - data: expect.objectContaining({ - firstAndThirdPartyAudienceId: 'audience-id-123' - }) - }) - ) - }) - it('should remove customer match members successfully with feature flag ON (v4)', async () => { + it('should remove customer match members successfully with CANARY VERSION', async () => { nock('https://displayvideo.googleapis.com') .post('/v4/firstPartyAndPartnerAudiences/audience-id-123:editCustomerMatchMembers', { advertiserId: '12345', @@ -224,7 +174,7 @@ describe('Audience Destination', () => { const result = await testDestination.testAction('removeFromAudContactInfo', { event, useDefaultMappings: true, - features: { 'actions-first-party-dv360-version-update': true } + features: { 'first-party-dv360-canary-version': true } }) expect(result).toContainEqual( expect.objectContaining({ @@ -234,42 +184,6 @@ describe('Audience Destination', () => { }) ) }) - it('should remove customer match members successfully with feature flag OFF (v3)', async () => { - nock('https://displayvideo.googleapis.com') - .post('/v3/firstAndThirdPartyAudiences/audience-id-123:editCustomerMatchMembers', { - advertiserId: '12345', - removedContactInfoList: { - contactInfos: [ - { - hashedEmails: '87924606b4131a8aceeeae8868531fbb9712aaa07a5d3a756b26ce0f5d6ca674', - hashedPhoneNumbers: 'c775e7b757ede630cd0aa1113bd102661ab38829ca52a6422ab782862f268646', - zipCodes: '12345', - hashedFirstName: '96d9632f363564cc3032521409cf22a852f2032eec099ed5967c0d000cec607a', - hashedLastName: '799ef92a11af918e3fb741df42934f3b568ed2d93ac1df74f1b8d41a27932a6f', - countryCode: '+1' - } - ], - consent: { - adUserData: 'CONSENT_STATUS_GRANTED', - adPersonalization: 'CONSENT_STATUS_GRANTED' - } - } - }) - .reply(200, { firstAndThirdPartyAudienceId: 'audience-id-123' }) - - const result = await testDestination.testAction('removeFromAudContactInfo', { - event, - useDefaultMappings: true, - features: { 'actions-first-party-dv360-version-update': false } - }) - expect(result).toContainEqual( - expect.objectContaining({ - data: expect.objectContaining({ - firstAndThirdPartyAudienceId: 'audience-id-123' - }) - }) - ) - }) }) // Edit Customer Match Members - Mobile Device ID List @@ -294,7 +208,7 @@ describe('Audience Destination', () => { } }) - it('should add customer match members successfully with feature flag ON (v4)', async () => { + it('should add customer match members successfully with CANARY VERSION', async () => { nock('https://displayvideo.googleapis.com') .post('/v4/firstPartyAndPartnerAudiences/audience-id-123:editCustomerMatchMembers', { advertiserId: '12345', @@ -311,7 +225,7 @@ describe('Audience Destination', () => { const result = await testDestination.testAction('addToAudMobileDeviceId', { event, useDefaultMappings: true, - features: { 'actions-first-party-dv360-version-update': true } + features: { 'first-party-dv360-canary-version': true } }) expect(result).toContainEqual( expect.objectContaining({ @@ -322,35 +236,7 @@ describe('Audience Destination', () => { ) }) - it('should add customer match members successfully with feature flag OFF (v3)', async () => { - nock('https://displayvideo.googleapis.com') - .post('/v3/firstAndThirdPartyAudiences/audience-id-123:editCustomerMatchMembers', { - advertiserId: '12345', - addedMobileDeviceIdList: { - mobileDeviceIds: ['123'], - consent: { - adUserData: 'CONSENT_STATUS_GRANTED', - adPersonalization: 'CONSENT_STATUS_GRANTED' - } - } - }) - .reply(200, { firstAndThirdPartyAudienceId: 'audience-id-123' }) - - const result = await testDestination.testAction('addToAudMobileDeviceId', { - event, - useDefaultMappings: true, - features: { 'actions-first-party-dv360-version-update': false } - }) - expect(result).toContainEqual( - expect.objectContaining({ - data: expect.objectContaining({ - firstAndThirdPartyAudienceId: 'audience-id-123' - }) - }) - ) - }) - - it('should remove customer match members successfully with feature flag ON (v4)', async () => { + it('should remove customer match members successfully with CANARY VERSION', async () => { nock('https://displayvideo.googleapis.com') .post('/v4/firstPartyAndPartnerAudiences/audience-id-123:editCustomerMatchMembers', { advertiserId: '12345', @@ -367,7 +253,7 @@ describe('Audience Destination', () => { const result = await testDestination.testAction('removeFromAudMobileDeviceId', { event, useDefaultMappings: true, - features: { 'actions-first-party-dv360-version-update': true } + features: { 'first-party-dv360-canary-version': true } }) expect(result).toContainEqual( expect.objectContaining({ @@ -377,33 +263,5 @@ describe('Audience Destination', () => { }) ) }) - - it('should remove customer match members successfully with feature flag OFF (v3)', async () => { - nock('https://displayvideo.googleapis.com') - .post('/v3/firstAndThirdPartyAudiences/audience-id-123:editCustomerMatchMembers', { - advertiserId: '12345', - removedMobileDeviceIdList: { - mobileDeviceIds: ['123'], - consent: { - adUserData: 'CONSENT_STATUS_GRANTED', - adPersonalization: 'CONSENT_STATUS_GRANTED' - } - } - }) - .reply(200, { firstAndThirdPartyAudienceId: 'audience-id-123' }) - - const result = await testDestination.testAction('removeFromAudMobileDeviceId', { - event, - useDefaultMappings: true, - features: { 'actions-first-party-dv360-version-update': false } - }) - expect(result).toContainEqual( - expect.objectContaining({ - data: expect.objectContaining({ - firstAndThirdPartyAudienceId: 'audience-id-123' - }) - }) - ) - }) }) }) diff --git a/packages/destination-actions/src/destinations/first-party-dv360/addToAudContactInfo/_tests_/index.test.ts b/packages/destination-actions/src/destinations/first-party-dv360/addToAudContactInfo/_tests_/index.test.ts index 1bee78a586..4fd5246524 100644 --- a/packages/destination-actions/src/destinations/first-party-dv360/addToAudContactInfo/_tests_/index.test.ts +++ b/packages/destination-actions/src/destinations/first-party-dv360/addToAudContactInfo/_tests_/index.test.ts @@ -27,7 +27,7 @@ const event = createTestEvent({ describe('First-Party-dv360.addToAudContactInfo', () => { it('should hash pii data if not already hashed', async () => { - nock('https://displayvideo.googleapis.com/v3/firstAndThirdPartyAudiences') + nock('https://displayvideo.googleapis.com/v4/firstPartyAndPartnerAudiences') .post('/1234567890:editCustomerMatchMembers') .reply(200, { success: true }) @@ -53,7 +53,7 @@ describe('First-Party-dv360.addToAudContactInfo', () => { }) it('should not hash pii data if already hashed', async () => { - nock('https://displayvideo.googleapis.com/v3/firstAndThirdPartyAudiences') + nock('https://displayvideo.googleapis.com/v4/firstPartyAndPartnerAudiences') .post('/1234567890:editCustomerMatchMembers') .reply(200, { success: true }) @@ -79,7 +79,7 @@ describe('First-Party-dv360.addToAudContactInfo', () => { }) it('should batch multiple payloads into a single request when enable_batching is true', async () => { - nock('https://displayvideo.googleapis.com/v3/firstAndThirdPartyAudiences') + nock('https://displayvideo.googleapis.com/v4/firstPartyAndPartnerAudiences') .post('/1234567890:editCustomerMatchMembers') .reply(200, { success: true }) @@ -107,7 +107,7 @@ describe('First-Party-dv360.addToAudContactInfo', () => { // Optionally, check that the emails are correctly hashed and correspond to the input }) - it('should batch multiple payloads into a single request when enable_batching is true (feature flag ON, v4)', async () => { + it('should batch multiple payloads into a single request when enable_batching is true ( CANARY VERSION )', async () => { nock('https://displayvideo.googleapis.com/v4/firstPartyAndPartnerAudiences') .post('/1234567890:editCustomerMatchMembers') .reply(200, { success: true }) @@ -127,36 +127,7 @@ describe('First-Party-dv360.addToAudContactInfo', () => { enable_batching: true, batch_size: 2 }, - features: { 'actions-first-party-dv360-version-update': true } - }) - - const requestBody = JSON.parse(String(responses[0].options.body)) - expect(requestBody.addedContactInfoList.contactInfos.length).toBe(2) - expect(requestBody.addedContactInfoList.contactInfos[0].hashedEmails).toBeDefined() - expect(requestBody.addedContactInfoList.contactInfos[1].hashedEmails).toBeDefined() - }) - - it('should batch multiple payloads into a single request when enable_batching is true (feature flag OFF, v3)', async () => { - nock('https://displayvideo.googleapis.com/v3/firstAndThirdPartyAudiences') - .post('/1234567890:editCustomerMatchMembers') - .reply(200, { success: true }) - - const events = createBatchTestEvents(createContactList) - const responses = await testDestination.testBatchAction('addToAudContactInfo', { - events: events, - mapping: { - emails: ['584c4423c421df49955759498a71495aba49b8780eb9387dff333b6f0982c777'], - phoneNumbers: ['422ce82c6fc1724ac878042f7d055653ab5e983d186e616826a72d4384b68af8'], - zipCodes: ['12345'], - firstName: '96d9632f363564cc3032521409cf22a852f2032eec099ed5967c0d000cec607a', - lastName: '799ef92a11af918e3fb741df42934f3b568ed2d93ac1df74f1b8d41a27932a6f', - countryCode: 'US', - external_id: '1234567890', - advertiser_id: '1234567890', - enable_batching: true, - batch_size: 2 - }, - features: { 'actions-first-party-dv360-version-update': false } + features: { 'first-party-dv360-canary-version': true } }) const requestBody = JSON.parse(String(responses[0].options.body)) diff --git a/packages/destination-actions/src/destinations/first-party-dv360/addToAudMobileDeviceId/_tests_/index.test.ts b/packages/destination-actions/src/destinations/first-party-dv360/addToAudMobileDeviceId/_tests_/index.test.ts index 86457b99b1..f2cd5767a4 100644 --- a/packages/destination-actions/src/destinations/first-party-dv360/addToAudMobileDeviceId/_tests_/index.test.ts +++ b/packages/destination-actions/src/destinations/first-party-dv360/addToAudMobileDeviceId/_tests_/index.test.ts @@ -21,7 +21,7 @@ const event = createTestEvent({ }) describe('First-Party-dv360.addToAudMobileDeviceId', () => { - it('should use v4 endpoint when feature flag is ON', async () => { + it('should use v4 endpoint when CANARY VERSION', async () => { nock('https://displayvideo.googleapis.com/v4/firstPartyAndPartnerAudiences') .post('/1234567890:editCustomerMatchMembers') .reply(200, { firstPartyAndPartnerAudienceId: '1234567890' }) @@ -35,7 +35,7 @@ describe('First-Party-dv360.addToAudMobileDeviceId', () => { enable_batching: false, batch_size: 1 }, - features: { 'actions-first-party-dv360-version-update': true } + features: { 'first-party-dv360-canary-version': true } }) expect(JSON.parse(responses[0].options.body as string)).toMatchInlineSnapshot(` @@ -54,42 +54,10 @@ describe('First-Party-dv360.addToAudMobileDeviceId', () => { `) }) - it('should use v3 endpoint when feature flag is OFF', async () => { - nock('https://displayvideo.googleapis.com/v3/firstAndThirdPartyAudiences') - .post('/1234567890:editCustomerMatchMembers') - .reply(200, { firstAndThirdPartyAudienceId: '1234567890' }) - - const responses = await testDestination.testAction('addToAudMobileDeviceId', { - event, - mapping: { - mobileDeviceIds: ['test-id'], - external_id: '1234567890', - advertiser_id: '1234567890', - enable_batching: false, - batch_size: 1 - }, - features: { 'actions-first-party-dv360-version-update': false } - }) - - expect(JSON.parse(responses[0].options.body as string)).toMatchInlineSnapshot(` - Object { - "addedMobileDeviceIdList": Object { - "consent": Object { - "adPersonalization": "CONSENT_STATUS_GRANTED", - "adUserData": "CONSENT_STATUS_GRANTED", - }, - "mobileDeviceIds": Array [ - "test-id", - ], - }, - "advertiserId": "1234567890", - } - `) - }) it('should addToAudMobileDeviceId', async () => { - nock('https://displayvideo.googleapis.com/v3/firstAndThirdPartyAudiences') + nock('https://displayvideo.googleapis.com/v4/firstPartyAndPartnerAudiences') .post('/1234567890:editCustomerMatchMembers') - .reply(200, { firstAndThirdPartyAudienceId: '1234567890' }) + .reply(200, { firstPartyAndPartnerAudienceId: '1234567890' }) const responses = await testDestination.testAction('addToAudMobileDeviceId', { event, @@ -108,9 +76,9 @@ describe('First-Party-dv360.addToAudMobileDeviceId', () => { }) it('should batch multiple payloads into a single request when enable_batching is true', async () => { - nock('https://displayvideo.googleapis.com/v3/firstAndThirdPartyAudiences') + nock('https://displayvideo.googleapis.com/v4/firstPartyAndPartnerAudiences') .post('/1234567890:editCustomerMatchMembers') - .reply(200, { firstAndThirdPartyAudienceId: '1234567890' }) + .reply(200, { firstPartyAndPartnerAudienceId: '1234567890' }) const events = createBatchTestEvents(createContactList) const responses = await testDestination.testBatchAction('addToAudMobileDeviceId', { diff --git a/packages/destination-actions/src/destinations/first-party-dv360/functions.ts b/packages/destination-actions/src/destinations/first-party-dv360/functions.ts index d4c87af788..90bb51e5d0 100644 --- a/packages/destination-actions/src/destinations/first-party-dv360/functions.ts +++ b/packages/destination-actions/src/destinations/first-party-dv360/functions.ts @@ -2,11 +2,34 @@ import { Features, IntegrationError, RequestClient, StatsContext } from '@segmen import { Payload } from './addToAudContactInfo/generated-types' import { Payload as DeviceIdPayload } from './addToAudMobileDeviceId/generated-types' import { processHashing } from '../../lib/hashing-utils' -import { FLAGON_NAME_FIRST_PARTY_DV360_VERSION_UPDATE } from './properties' + +export const API_VERSION = 'v4' +export const CANARY_API_VERSION = 'v4' +export const FLAGON_NAME = 'first-party-dv360-canary-version' const DV360API = `https://displayvideo.googleapis.com/` const CONSENT_STATUS_GRANTED = 'CONSENT_STATUS_GRANTED' // Define consent status +export function getApiVersion(features?: Features, statsContext?: StatsContext): string { + const statsClient = statsContext?.statsClient + const tags = statsContext?.tags + const version = features && features[FLAGON_NAME] ? CANARY_API_VERSION : API_VERSION + statsClient?.incr('dv360_api_version', 1, [...(tags || []), `version:${version}`]) + return version +} + +function getAudienceEndpoint(version: string, advertiserId: string, audienceId?: string): string { + if (audienceId) { + return DV360API + `${version}/firstPartyAndPartnerAudiences/` + `${audienceId}?advertiserId=${advertiserId}` + } else { + return DV360API + `${version}/firstPartyAndPartnerAudiences` + `?advertiserId=${advertiserId}` + } +} + +function getEditCustomerMatchMembersEndpoint(version: string, audienceId: string): string { + return DV360API + `${version}/firstPartyAndPartnerAudiences/` + audienceId + ':editCustomerMatchMembers' +} + interface createAudienceRequestParams { advertiserId: string audienceName: string @@ -16,6 +39,7 @@ interface createAudienceRequestParams { appId?: string token?: string features?: Features + statsContext?: StatsContext } interface getAudienceParams { @@ -23,10 +47,10 @@ interface getAudienceParams { audienceId: string token?: string features?: Features + statsContext?: StatsContext } interface DV360editCustomerMatchResponse { - firstAndThirdPartyAudienceId?: string firstPartyAndPartnerAudienceId?: string error: [ { @@ -41,15 +65,20 @@ export const createAudienceRequest = ( request: RequestClient, params: createAudienceRequestParams ): Promise => { - const { advertiserId, audienceName, description, membershipDurationDays, audienceType, appId, token, features } = - params + const { + advertiserId, + audienceName, + description, + membershipDurationDays, + audienceType, + appId, + token, + features, + statsContext + } = params - let endpoint - if (features && features[FLAGON_NAME_FIRST_PARTY_DV360_VERSION_UPDATE]) { - endpoint = DV360API + 'v4/firstPartyAndPartnerAudiences' + `?advertiserId=${advertiserId}` - } else { - endpoint = DV360API + 'v3/firstAndThirdPartyAudiences' + `?advertiserId=${advertiserId}` - } + const version = getApiVersion(features, statsContext) + const endpoint = getAudienceEndpoint(version, advertiserId) return request(endpoint, { method: 'POST', @@ -63,26 +92,17 @@ export const createAudienceRequest = ( membershipDurationDays: membershipDurationDays, description: description, audienceSource: 'AUDIENCE_SOURCE_UNSPECIFIED', - firstAndThirdPartyAudienceType: - features && features[FLAGON_NAME_FIRST_PARTY_DV360_VERSION_UPDATE] - ? undefined - : 'FIRST_AND_THIRD_PARTY_AUDIENCE_TYPE_FIRST_PARTY', - firstPartyAndPartnerAudienceType: - features && features[FLAGON_NAME_FIRST_PARTY_DV360_VERSION_UPDATE] ? 'TYPE_FIRST_PARTY' : undefined, + firstPartyAndPartnerAudienceType: 'TYPE_FIRST_PARTY', appId: appId } }) } export const getAudienceRequest = (request: RequestClient, params: getAudienceParams): Promise => { - const { advertiserId, audienceId, token, features } = params + const { advertiserId, audienceId, token, features, statsContext } = params - let endpoint - if (features && features[FLAGON_NAME_FIRST_PARTY_DV360_VERSION_UPDATE]) { - endpoint = DV360API + 'v4/firstPartyAndPartnerAudiences' + `/${audienceId}?advertiserId=${advertiserId}` - } else { - endpoint = DV360API + 'v3/firstAndThirdPartyAudiences' + `/${audienceId}?advertiserId=${advertiserId}` - } + const version = getApiVersion(features, statsContext) + const endpoint = getAudienceEndpoint(version, advertiserId, audienceId) return request(endpoint, { method: 'GET', @@ -109,13 +129,9 @@ export async function editDeviceMobileIds( ) //Format the endpoint - let endpoint - if (features && features[FLAGON_NAME_FIRST_PARTY_DV360_VERSION_UPDATE]) { - // Handle version update logic - endpoint = DV360API + 'v4/firstPartyAndPartnerAudiences/' + audienceId + ':editCustomerMatchMembers' - } else { - endpoint = DV360API + 'v3/firstAndThirdPartyAudiences/' + audienceId + ':editCustomerMatchMembers' - } + + const version = getApiVersion(features, statsContext) + const endpoint = getEditCustomerMatchMembersEndpoint(version, audienceId) // Prepare the request payload const mobileDeviceIdList = { @@ -139,10 +155,7 @@ export async function editDeviceMobileIds( }, body: requestPayload }) - const responseAudienceId = - features && features[FLAGON_NAME_FIRST_PARTY_DV360_VERSION_UPDATE] - ? response.data.firstPartyAndPartnerAudienceId - : response.data.firstAndThirdPartyAudienceId + const responseAudienceId = response.data.firstPartyAndPartnerAudienceId if (!response.data || !responseAudienceId) { statsContext?.statsClient?.incr('addCustomerMatchMembers.error', allMobileDeviceIds.length, statsContext?.tags) throw new IntegrationError( @@ -213,12 +226,8 @@ export async function editContactInfo( const contactInfos = validPayloads.map(processPayload) const contactInfoList = buildContactInfoList(contactInfos) const requestPayload = buildRequestPayload(advertiserId, contactInfoList, operation) - let endpoint - if (features && features[FLAGON_NAME_FIRST_PARTY_DV360_VERSION_UPDATE]) { - endpoint = DV360API + 'v4/firstPartyAndPartnerAudiences/' + audienceId + ':editCustomerMatchMembers' - } else { - endpoint = DV360API + 'v3/firstAndThirdPartyAudiences/' + audienceId + ':editCustomerMatchMembers' - } + const version = getApiVersion(features, statsContext) + const endpoint = getEditCustomerMatchMembersEndpoint(version, audienceId) const response = await request(endpoint, { method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8' }, diff --git a/packages/destination-actions/src/destinations/first-party-dv360/index.ts b/packages/destination-actions/src/destinations/first-party-dv360/index.ts index 1d875163c8..8ed0aa720b 100644 --- a/packages/destination-actions/src/destinations/first-party-dv360/index.ts +++ b/packages/destination-actions/src/destinations/first-party-dv360/index.ts @@ -11,7 +11,6 @@ import removeFromAudMobileDeviceId from './removeFromAudMobileDeviceId' import addToAudContactInfo from './addToAudContactInfo' import addToAudMobileDeviceId from './addToAudMobileDeviceId' import { _CreateAudienceInput, _GetAudienceInput } from './types' -import { FLAGON_NAME_FIRST_PARTY_DV360_VERSION_UPDATE } from './properties' export interface RefreshTokenResponse { access_token: string @@ -167,17 +166,15 @@ const destination: AudienceDestinationDefinition = { audienceType, appId, token, - features + features, + statsContext }) // Parse and return the externalId const r = await response.json() statsClient?.incr(`${statsName}.success`, 1, statsTags) return { - externalId: - features && features[FLAGON_NAME_FIRST_PARTY_DV360_VERSION_UPDATE] - ? r.firstPartyAndPartnerAudienceId - : r.firstAndThirdPartyAudienceId + externalId: r.firstPartyAndPartnerAudienceId } }, @@ -228,7 +225,7 @@ const destination: AudienceDestinationDefinition = { } // Make API request to get audience details - const response = await getAudienceRequest(_request, { advertiserId, audienceId, token, features }) + const response = await getAudienceRequest(_request, { advertiserId, audienceId, token, features, statsContext }) if (!response.ok) { // Handle non-OK responses @@ -241,10 +238,7 @@ const destination: AudienceDestinationDefinition = { const audienceData = await response.json() statsClient?.incr(`${statsName}.success`, 1, statsTags) return { - externalId: - features && features[FLAGON_NAME_FIRST_PARTY_DV360_VERSION_UPDATE] - ? audienceData.firstPartyAndPartnerAudienceId - : audienceData.firstAndThirdPartyAudienceId + externalId: audienceData.firstPartyAndPartnerAudienceId } } }, diff --git a/packages/destination-actions/src/destinations/first-party-dv360/properties.ts b/packages/destination-actions/src/destinations/first-party-dv360/properties.ts index 537d3cd666..b147e85eca 100644 --- a/packages/destination-actions/src/destinations/first-party-dv360/properties.ts +++ b/packages/destination-actions/src/destinations/first-party-dv360/properties.ts @@ -1,7 +1,5 @@ import { InputField } from '@segment/actions-core/index' -export const FLAGON_NAME_FIRST_PARTY_DV360_VERSION_UPDATE = 'actions-first-party-dv360-version-update' - export const external_id: InputField = { label: 'External ID', description: 'The ID of the DV360 Audience.', diff --git a/packages/destination-actions/src/destinations/first-party-dv360/removeFromAudContactInfo/_tests_/index.test.ts b/packages/destination-actions/src/destinations/first-party-dv360/removeFromAudContactInfo/_tests_/index.test.ts index 31e990c87f..8564e9a118 100644 --- a/packages/destination-actions/src/destinations/first-party-dv360/removeFromAudContactInfo/_tests_/index.test.ts +++ b/packages/destination-actions/src/destinations/first-party-dv360/removeFromAudContactInfo/_tests_/index.test.ts @@ -27,7 +27,7 @@ const event = createTestEvent({ describe('First-Party-dv360.removeFromAudContactInfo', () => { it('should hash pii data if not already hashed', async () => { - nock('https://displayvideo.googleapis.com/v3/firstAndThirdPartyAudiences') + nock('https://displayvideo.googleapis.com/v4/firstPartyAndPartnerAudiences') .post('/1234567890:editCustomerMatchMembers') .reply(200, { success: true }) @@ -53,7 +53,7 @@ describe('First-Party-dv360.removeFromAudContactInfo', () => { }) it('should not hash pii data if already hashed', async () => { - nock('https://displayvideo.googleapis.com/v3/firstAndThirdPartyAudiences') + nock('https://displayvideo.googleapis.com/v4/firstPartyAndPartnerAudiences') .post('/1234567890:editCustomerMatchMembers') .reply(200, { success: true }) @@ -96,36 +96,7 @@ describe('First-Party-dv360.removeFromAudContactInfo', () => { `) }) - it('should batch multiple payloads into a single request when enable_batching is true', async () => { - nock('https://displayvideo.googleapis.com/v3/firstAndThirdPartyAudiences') - .post('/1234567890:editCustomerMatchMembers') - .reply(200, { success: true }) - - const events = createBatchTestEvents(createContactList) - const responses = await testDestination.testBatchAction('removeFromAudContactInfo', { - events: events, - mapping: { - emails: ['584c4423c421df49955759498a71495aba49b8780eb9387dff333b6f0982c777'], - phoneNumbers: ['422ce82c6fc1724ac878042f7d055653ab5e983d186e616826a72d4384b68af8'], - zipCodes: ['12345'], - firstName: '96d9632f363564cc3032521409cf22a852f2032eec099ed5967c0d000cec607a', - lastName: '799ef92a11af918e3fb741df42934f3b568ed2d93ac1df74f1b8d41a27932a6f', - countryCode: 'US', - external_id: '1234567890', - advertiser_id: '1234567890', - enable_batching: true, - batch_size: 2 - } - }) - - const requestBody = JSON.parse(String(responses[0].options.body)) - expect(requestBody.removedContactInfoList.contactInfos.length).toBe(2) - expect(requestBody.removedContactInfoList.contactInfos[0].hashedEmails).toBeDefined() - expect(requestBody.removedContactInfoList.contactInfos[1].hashedEmails).toBeDefined() - // Optionally, check that the emails are correctly hashed and correspond to the input - }) - - it('should batch multiple payloads into a single request when enable_batching is true (feature flag ON, v4)', async () => { + it('should batch multiple payloads into a single request when enable_batching is true ( CANARY VERSION )', async () => { nock('https://displayvideo.googleapis.com/v4/firstPartyAndPartnerAudiences') .post('/1234567890:editCustomerMatchMembers') .reply(200, { success: true }) @@ -145,36 +116,7 @@ describe('First-Party-dv360.removeFromAudContactInfo', () => { enable_batching: true, batch_size: 2 }, - features: { 'actions-first-party-dv360-version-update': true } - }) - - const requestBody = JSON.parse(String(responses[0].options.body)) - expect(requestBody.removedContactInfoList.contactInfos.length).toBe(2) - expect(requestBody.removedContactInfoList.contactInfos[0].hashedEmails).toBeDefined() - expect(requestBody.removedContactInfoList.contactInfos[1].hashedEmails).toBeDefined() - }) - - it('should batch multiple payloads into a single request when enable_batching is true (feature flag OFF, v3)', async () => { - nock('https://displayvideo.googleapis.com/v3/firstAndThirdPartyAudiences') - .post('/1234567890:editCustomerMatchMembers') - .reply(200, { success: true }) - - const events = createBatchTestEvents(createContactList) - const responses = await testDestination.testBatchAction('removeFromAudContactInfo', { - events: events, - mapping: { - emails: ['584c4423c421df49955759498a71495aba49b8780eb9387dff333b6f0982c777'], - phoneNumbers: ['422ce82c6fc1724ac878042f7d055653ab5e983d186e616826a72d4384b68af8'], - zipCodes: ['12345'], - firstName: '96d9632f363564cc3032521409cf22a852f2032eec099ed5967c0d000cec607a', - lastName: '799ef92a11af918e3fb741df42934f3b568ed2d93ac1df74f1b8d41a27932a6f', - countryCode: 'US', - external_id: '1234567890', - advertiser_id: '1234567890', - enable_batching: true, - batch_size: 2 - }, - features: { 'actions-first-party-dv360-version-update': false } + features: { 'first-party-dv360-canary-version': true } }) const requestBody = JSON.parse(String(responses[0].options.body))