diff --git a/package.json b/package.json index 2288c2256b8..ffd2c8329b1 100644 --- a/package.json +++ b/package.json @@ -114,5 +114,6 @@ }, "dependencies": { "chance": "^1.1.8" - } + }, + "packageManager": "yarn@1.22.19+sha512.ff4579ab459bb25aa7c0ff75b62acebe576f6084b36aa842971cf250a5d8c6cd3bc9420b22ce63c7f93a0857bc6ef29291db39c3e7a23aab5adfd5a4dd6c5d71" } diff --git a/packages/browser-destinations/destinations/google-analytics-4-web/src/__tests__/setConfigurationFields.test.ts b/packages/browser-destinations/destinations/google-analytics-4-web/src/__tests__/setConfigurationFields.test.ts index feca9da7d30..b2068d9ea9a 100644 --- a/packages/browser-destinations/destinations/google-analytics-4-web/src/__tests__/setConfigurationFields.test.ts +++ b/packages/browser-destinations/destinations/google-analytics-4-web/src/__tests__/setConfigurationFields.test.ts @@ -806,4 +806,36 @@ describe('Set Configuration Fields action', () => { send_page_view: false }) }) + + it('should convert consent values to lower case', async () => { + defaultSettings.enableConsentMode = true + + const [setConfigurationEventPlugin] = await googleAnalytics4Web({ + ...defaultSettings, + subscriptions + }) + setConfigurationEvent = setConfigurationEventPlugin + await setConfigurationEventPlugin.load(Context.system(), {} as Analytics) + + const context = new Context({ + event: 'setConfigurationFields', + type: 'page', + properties: { + ads_storage_consent_state: 'GRANTED', + analytics_storage_consent_state: 'Granted' + } + }) + + setConfigurationEvent.page?.(context) + + expect(mockGtag).toHaveBeenCalledWith('consent', 'update', { + ad_storage: 'granted', + analytics_storage: 'granted' + }) + expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', { + allow_ad_personalization_signals: false, + allow_google_signals: false, + send_page_view: true + }) + }) }) diff --git a/packages/browser-destinations/destinations/google-analytics-4-web/src/setConfigurationFields/index.ts b/packages/browser-destinations/destinations/google-analytics-4-web/src/setConfigurationFields/index.ts index bfc4451ceb9..09bfe17792b 100644 --- a/packages/browser-destinations/destinations/google-analytics-4-web/src/setConfigurationFields/index.ts +++ b/packages/browser-destinations/destinations/google-analytics-4-web/src/setConfigurationFields/index.ts @@ -20,13 +20,23 @@ const action: BrowserActionDefinition = { description: 'Consent state indicated by the user for ad cookies. Value must be “granted” or “denied.” This is only used if the Enable Consent Mode setting is on.', label: 'Ads Storage Consent State', - type: 'string' + type: 'string', + choices: [ + { label: 'Granted', value: 'granted' }, + { label: 'Denied', value: 'denied' } + ], + default: undefined }, analytics_storage_consent_state: { description: 'Consent state indicated by the user for ad cookies. Value must be “granted” or “denied.” This is only used if the Enable Consent Mode setting is on.', label: 'Analytics Storage Consent State', - type: 'string' + type: 'string', + choices: [ + { label: 'Granted', value: 'granted' }, + { label: 'Denied', value: 'denied' } + ], + default: undefined }, ad_user_data_consent_state: { description: @@ -140,10 +150,10 @@ const action: BrowserActionDefinition = { ad_personalization?: ConsentParamsArg } = {} if (payload.ads_storage_consent_state) { - consentParams.ad_storage = payload.ads_storage_consent_state as ConsentParamsArg + consentParams.ad_storage = payload.ads_storage_consent_state.toLowerCase() as ConsentParamsArg } if (payload.analytics_storage_consent_state) { - consentParams.analytics_storage = payload.analytics_storage_consent_state as ConsentParamsArg + consentParams.analytics_storage = payload.analytics_storage_consent_state.toLowerCase() as ConsentParamsArg } if (payload.ad_user_data_consent_state) { consentParams.ad_user_data = payload.ad_user_data_consent_state as ConsentParamsArg diff --git a/packages/browser-destinations/destinations/hubspot-web/src/upsertContact/__tests__/index.test.ts b/packages/browser-destinations/destinations/hubspot-web/src/upsertContact/__tests__/index.test.ts index 9aea19304f5..9da9e398a16 100644 --- a/packages/browser-destinations/destinations/hubspot-web/src/upsertContact/__tests__/index.test.ts +++ b/packages/browser-destinations/destinations/hubspot-web/src/upsertContact/__tests__/index.test.ts @@ -204,4 +204,52 @@ describe('Hubspot.upsertContact', () => { } ]) }) + + test('trims string traits', async () => { + const context = new Context({ + type: 'identify', + userId: 'mike', + traits: { + friendly: false, + email: 'mike_eh@lph.com', + address: { + street: '6th St', + city: ' San Francisco ', // to be trimmed + state: 'CA', + postalCode: '94103', + country: 'USA' + }, + equipment: { + type: '🚘', + color: ' red ', // to be trimmed + make: { + make: 'Tesla', + model: 'Model S', + year: 2019 + } + } + } + }) + + await upsertContactEvent.identify?.(context) + expect(mockHubspot.push).toHaveBeenCalledTimes(1) + expect(mockHubspot.push).toHaveBeenCalledWith([ + 'identify', + { + email: 'mike_eh@lph.com', + id: 'mike', + friendly: false, + address: '6th St', + country: 'USA', + state: 'CA', + city: 'San Francisco', + zip: '94103', + equipment_type: '🚘', + equipment_color: 'red', + equipment_make_make: 'Tesla', + equipment_make_model: 'Model S', + equipment_make_year: 2019 + } + ]) + }) }) diff --git a/packages/browser-destinations/destinations/hubspot-web/src/upsertContact/index.ts b/packages/browser-destinations/destinations/hubspot-web/src/upsertContact/index.ts index 123c0b050f8..7da47406ddf 100644 --- a/packages/browser-destinations/destinations/hubspot-web/src/upsertContact/index.ts +++ b/packages/browser-destinations/destinations/hubspot-web/src/upsertContact/index.ts @@ -30,7 +30,8 @@ const action: BrowserActionDefinition = { } }, custom_properties: { - description: 'A list of key-value pairs that describe the contact. Please see [HubSpot`s documentation](https://knowledge.hubspot.com/account/prevent-contact-properties-update-through-tracking-code-api) for limitations in updating contact properties.', + description: + 'A list of key-value pairs that describe the contact. Please see [HubSpot`s documentation](https://knowledge.hubspot.com/account/prevent-contact-properties-update-through-tracking-code-api) for limitations in updating contact properties.', label: 'Custom Properties', type: 'object', required: false, @@ -103,6 +104,15 @@ const action: BrowserActionDefinition = { return } + payload.email = payload.email?.trim() + payload.id = payload.id?.trim() + payload.company = payload.company?.trim() + payload.country = payload.country?.trim() + payload.state = payload.state?.trim() + payload.city = payload.city?.trim() + payload.address = payload.address?.trim() + payload.zip = payload.zip?.trim() + // custom properties should be key-value pairs of strings, therefore, filtering out any non-primitive const { custom_properties, ...rest } = payload let flattenProperties diff --git a/packages/browser-destinations/destinations/hubspot-web/src/utils/flatten.ts b/packages/browser-destinations/destinations/hubspot-web/src/utils/flatten.ts index 6d1c8b53f6e..daff14e3679 100644 --- a/packages/browser-destinations/destinations/hubspot-web/src/utils/flatten.ts +++ b/packages/browser-destinations/destinations/hubspot-web/src/utils/flatten.ts @@ -23,7 +23,9 @@ export function flatten( const flattened = flatten(data[key] as Properties, `${prefix}_${key}`, skipList, keyTransformation) result = { ...result, ...flattened } } else { - result[keyTransformation(`${prefix}_${key}`.replace(/^_/, ''))] = data[key] as JSONPrimitive + result[keyTransformation(`${prefix}_${key}`.replace(/^_/, ''))] = ( + typeof data[key] === 'string' ? (data[key] as string).trim() : data[key] + ) as JSONPrimitive } } return result diff --git a/packages/destination-actions/package.json b/packages/destination-actions/package.json index 6de0df6fcf8..2d5c46499bf 100644 --- a/packages/destination-actions/package.json +++ b/packages/destination-actions/package.json @@ -1,7 +1,7 @@ { "name": "@segment/action-destinations", "description": "Destination Actions engine and definitions.", - "version": "3.345.0", + "version": "3.345.1", "repository": { "type": "git", "url": "https://github.com/segmentio/action-destinations", diff --git a/packages/destination-actions/src/destinations/drip/__tests__/__snapshots__/snapshot.test.ts.snap b/packages/destination-actions/src/destinations/drip/__tests__/__snapshots__/snapshot.test.ts.snap index 30351312fc8..a9243ea672f 100644 --- a/packages/destination-actions/src/destinations/drip/__tests__/__snapshots__/snapshot.test.ts.snap +++ b/packages/destination-actions/src/destinations/drip/__tests__/__snapshots__/snapshot.test.ts.snap @@ -2,24 +2,32 @@ exports[`Testing snapshot for drip destination: identify action - all fields 1`] = ` Object { - "custom_fields": Object { - "testType": "XoS!vJs", - }, - "email": "mivsaj@pu.co.uk", - "ip_address": "33.172.51.152", - "sms_number": "XoS!vJs", - "status": "XoS!vJs", - "status_updated_at": "2021-02-01T00:00:00.000Z", - "tags": Array [ - "XoS!vJs", + "subscribers": Array [ + Object { + "custom_fields": Object { + "testType": "XoS!vJs", + }, + "email": "mivsaj@pu.co.uk", + "ip_address": "33.172.51.152", + "sms_number": "XoS!vJs", + "status": "XoS!vJs", + "status_updated_at": "2021-02-01T00:00:00.000Z", + "tags": Array [ + "XoS!vJs", + ], + "time_zone": "XoS!vJs", + }, ], - "time_zone": "XoS!vJs", } `; exports[`Testing snapshot for drip destination: identify action - required fields 1`] = ` Object { - "email": "mivsaj@pu.co.uk", + "subscribers": Array [ + Object { + "email": "mivsaj@pu.co.uk", + }, + ], } `; diff --git a/packages/destination-actions/src/destinations/drip/identify/__tests__/__snapshots__/snapshot.test.ts.snap b/packages/destination-actions/src/destinations/drip/identify/__tests__/__snapshots__/snapshot.test.ts.snap index a46fd4300ed..9e665ff3224 100644 --- a/packages/destination-actions/src/destinations/drip/identify/__tests__/__snapshots__/snapshot.test.ts.snap +++ b/packages/destination-actions/src/destinations/drip/identify/__tests__/__snapshots__/snapshot.test.ts.snap @@ -2,23 +2,31 @@ exports[`Testing snapshot for Drip's identify destination action: all fields 1`] = ` Object { - "custom_fields": Object { - "testType": "DVw6A7$UK[I", - }, - "email": "okavno@kulusof.bg", - "ip_address": "100.102.165.77", - "sms_number": "DVw6A7$UK[I", - "status": "DVw6A7$UK[I", - "status_updated_at": "2021-02-01T00:00:00.000Z", - "tags": Array [ - "DVw6A7$UK[I", + "subscribers": Array [ + Object { + "custom_fields": Object { + "testType": "DVw6A7$UK[I", + }, + "email": "okavno@kulusof.bg", + "ip_address": "100.102.165.77", + "sms_number": "DVw6A7$UK[I", + "status": "DVw6A7$UK[I", + "status_updated_at": "2021-02-01T00:00:00.000Z", + "tags": Array [ + "DVw6A7$UK[I", + ], + "time_zone": "DVw6A7$UK[I", + }, ], - "time_zone": "DVw6A7$UK[I", } `; exports[`Testing snapshot for Drip's identify destination action: required fields 1`] = ` Object { - "email": "okavno@kulusof.bg", + "subscribers": Array [ + Object { + "email": "okavno@kulusof.bg", + }, + ], } `; diff --git a/packages/destination-actions/src/destinations/drip/identify/__tests__/index.test.ts b/packages/destination-actions/src/destinations/drip/identify/__tests__/index.test.ts index 204ee624c2e..2870434a715 100644 --- a/packages/destination-actions/src/destinations/drip/identify/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/drip/identify/__tests__/index.test.ts @@ -24,7 +24,15 @@ describe('Drip.identify', () => { phone: '1234567890', status: 'unsubscribed', status_updated_at: '2021-01-01T00:00:00Z', - custom_fields: { fizz: 'buzz', numb:1234, bool:true, oppBool:false, arr: ["hello", 1234, false], obj: { key: 'value' }, null: null }, + custom_fields: { + fizz: 'buzz', + numb: 1234, + bool: true, + oppBool: false, + arr: ['hello', 1234, false], + obj: { key: 'value' }, + null: null + }, tags: 'tag1,tag2' } }) @@ -36,14 +44,25 @@ describe('Drip.identify', () => { }) const body = { - custom_fields: { fizz: 'buzz', numb:"1234", bool:"true", oppBool:"false", arr: "[\"hello\",1234,false]", obj: "{\"key\":\"value\"}" }, - email: 'test@example.com', - ip_address: '127.0.0.1', - sms_number: '1234567890', - status: 'unsubscribed', - status_updated_at: '2021-01-01T00:00:00Z', - tags: ['tag1', 'tag2'], - time_zone: 'Europe/Amsterdam' + subscribers: [ + { + custom_fields: { + fizz: 'buzz', + numb: '1234', + bool: 'true', + oppBool: 'false', + arr: '["hello",1234,false]', + obj: '{"key":"value"}' + }, + email: 'test@example.com', + ip_address: '127.0.0.1', + sms_number: '1234567890', + status: 'unsubscribed', + status_updated_at: '2021-01-01T00:00:00Z', + tags: ['tag1', 'tag2'], + time_zone: 'Europe/Amsterdam' + } + ] } expect(responses.length).toBe(1) diff --git a/packages/destination-actions/src/destinations/drip/identify/index.ts b/packages/destination-actions/src/destinations/drip/identify/index.ts index 2e0faa9dd35..406c6a05a38 100644 --- a/packages/destination-actions/src/destinations/drip/identify/index.ts +++ b/packages/destination-actions/src/destinations/drip/identify/index.ts @@ -11,7 +11,7 @@ const person = (payload: Payload) => { .map(([key, value]) => [key, typeof value === 'object' ? JSON.stringify(value) : String(value)]) ) return Object.keys(result).length > 0 ? result : undefined - })(), + })(), email: payload.email, ip_address: payload.ip, sms_number: payload.phone, @@ -95,7 +95,7 @@ const action: ActionDefinition = { perform: (request, { settings, payload }) => { return request(`https://api.getdrip.com/v2/${settings.accountId}/subscribers`, { method: 'POST', - json: person(payload) + json: { subscribers: [person(payload)] } }) }, performBatch: (request, { settings, payload }) => { diff --git a/packages/destination-actions/src/destinations/drip/index.ts b/packages/destination-actions/src/destinations/drip/index.ts index 3aee56ffa85..132ca6dceff 100644 --- a/packages/destination-actions/src/destinations/drip/index.ts +++ b/packages/destination-actions/src/destinations/drip/index.ts @@ -7,7 +7,7 @@ const destination: DestinationDefinition = { name: 'Drip (Actions)', slug: 'actions-drip', mode: 'cloud', - description: 'Send Segment events to Drip', + description: 'Send Segment analytics events and user profile details to Drip', authentication: { scheme: 'custom', fields: { diff --git a/packages/destination-actions/src/destinations/stackadapt-audiences/__tests__/__snapshots__/snapshot.test.ts.snap b/packages/destination-actions/src/destinations/stackadapt-audiences/__tests__/__snapshots__/snapshot.test.ts.snap index df2cc00f69a..aaf301aa064 100644 --- a/packages/destination-actions/src/destinations/stackadapt-audiences/__tests__/__snapshots__/snapshot.test.ts.snap +++ b/packages/destination-actions/src/destinations/stackadapt-audiences/__tests__/__snapshots__/snapshot.test.ts.snap @@ -18,7 +18,7 @@ Object { upsertProfileMapping( input: { advertiserId: 84GW[vK%wv2xv@UF5iy, - mappingSchema: \\"[{\\\\\\"incoming_key\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"is_pii\\\\\\":false}]\\", + mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"isPii\\\\\\":false,\\\\\\"label\\\\\\":\\\\\\"External Profile ID\\\\\\"}], mappableType: \\"segmentio\\", } ) { @@ -29,7 +29,7 @@ Object { upsertExternalAudienceMapping( input: { advertiserId: 84GW[vK%wv2xv@UF5iy, - mappingSchema: \\"[{\\\\\\"incoming_key\\\\\\":\\\\\\"audienceId\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\"},{\\\\\\"incoming_key\\\\\\":\\\\\\"audienceName\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"name\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\"}]\\", + mappingSchema: \\"[{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"label\\\\\\":\\\\\\"External Audience ID\\\\\\"},{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceName\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"name\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"label\\\\\\":\\\\\\"External Audience Name\\\\\\"}]\\", mappableType: \\"segmentio\\" } ) { @@ -59,7 +59,7 @@ Object { upsertProfileMapping( input: { advertiserId: 84GW[vK%wv2xv@UF5iy, - mappingSchema: \\"[{\\\\\\"incoming_key\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"is_pii\\\\\\":false}]\\", + mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"isPii\\\\\\":false,\\\\\\"label\\\\\\":\\\\\\"External Profile ID\\\\\\"}], mappableType: \\"segmentio\\", } ) { @@ -70,7 +70,7 @@ Object { upsertExternalAudienceMapping( input: { advertiserId: 84GW[vK%wv2xv@UF5iy, - mappingSchema: \\"[{\\\\\\"incoming_key\\\\\\":\\\\\\"audienceId\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\"},{\\\\\\"incoming_key\\\\\\":\\\\\\"audienceName\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"name\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\"}]\\", + mappingSchema: \\"[{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"label\\\\\\":\\\\\\"External Audience ID\\\\\\"},{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceName\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"name\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"label\\\\\\":\\\\\\"External Audience Name\\\\\\"}]\\", mappableType: \\"segmentio\\" } ) { @@ -100,7 +100,7 @@ Object { upsertProfileMapping( input: { advertiserId: PsAwlRv%, - mappingSchema: \\"[{\\\\\\"incoming_key\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"is_pii\\\\\\":false}]\\", + mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"label\\\\\\":\\\\\\"User Id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"isPii\\\\\\":false}], mappableType: \\"segmentio\\", } ) { @@ -130,7 +130,7 @@ Object { upsertProfileMapping( input: { advertiserId: PsAwlRv%, - mappingSchema: \\"[{\\\\\\"incoming_key\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"is_pii\\\\\\":false}]\\", + mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"label\\\\\\":\\\\\\"User Id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"isPii\\\\\\":false}], mappableType: \\"segmentio\\", } ) { diff --git a/packages/destination-actions/src/destinations/stackadapt-audiences/forwardAudienceEvent/__tests__/index.test.ts b/packages/destination-actions/src/destinations/stackadapt-audiences/forwardAudienceEvent/__tests__/index.test.ts index 3cbef3968ce..b9ec5392b13 100644 --- a/packages/destination-actions/src/destinations/stackadapt-audiences/forwardAudienceEvent/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/stackadapt-audiences/forwardAudienceEvent/__tests__/index.test.ts @@ -95,7 +95,7 @@ describe('forwardAudienceEvent', () => { upsertProfileMapping( input: { advertiserId: 23, - mappingSchema: \\"[{\\\\\\"incoming_key\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"is_pii\\\\\\":false}]\\", + mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"isPii\\\\\\":false,\\\\\\"label\\\\\\":\\\\\\"External Profile ID\\\\\\"}], mappableType: \\"segmentio\\", } ) { @@ -106,7 +106,7 @@ describe('forwardAudienceEvent', () => { upsertExternalAudienceMapping( input: { advertiserId: 23, - mappingSchema: \\"[{\\\\\\"incoming_key\\\\\\":\\\\\\"audienceId\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\"},{\\\\\\"incoming_key\\\\\\":\\\\\\"audienceName\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"name\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\"}]\\", + mappingSchema: \\"[{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"label\\\\\\":\\\\\\"External Audience ID\\\\\\"},{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceName\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"name\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"label\\\\\\":\\\\\\"External Audience Name\\\\\\"}]\\", mappableType: \\"segmentio\\" } ) { @@ -169,7 +169,7 @@ describe('forwardAudienceEvent', () => { upsertProfileMapping( input: { advertiserId: 23, - mappingSchema: \\"[{\\\\\\"incoming_key\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"is_pii\\\\\\":false}]\\", + mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"isPii\\\\\\":false,\\\\\\"label\\\\\\":\\\\\\"External Profile ID\\\\\\"}], mappableType: \\"segmentio\\", } ) { @@ -180,7 +180,7 @@ describe('forwardAudienceEvent', () => { upsertExternalAudienceMapping( input: { advertiserId: 23, - mappingSchema: \\"[{\\\\\\"incoming_key\\\\\\":\\\\\\"audienceId\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\"},{\\\\\\"incoming_key\\\\\\":\\\\\\"audienceName\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"name\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\"}]\\", + mappingSchema: \\"[{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"label\\\\\\":\\\\\\"External Audience ID\\\\\\"},{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceName\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"name\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"label\\\\\\":\\\\\\"External Audience Name\\\\\\"}]\\", mappableType: \\"segmentio\\" } ) { @@ -228,7 +228,7 @@ describe('forwardAudienceEvent', () => { upsertProfileMapping( input: { advertiserId: 23, - mappingSchema: \\"[{\\\\\\"incoming_key\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"is_pii\\\\\\":false}]\\", + mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"isPii\\\\\\":false,\\\\\\"label\\\\\\":\\\\\\"External Profile ID\\\\\\"}], mappableType: \\"segmentio\\", } ) { @@ -239,7 +239,7 @@ describe('forwardAudienceEvent', () => { upsertExternalAudienceMapping( input: { advertiserId: 23, - mappingSchema: \\"[{\\\\\\"incoming_key\\\\\\":\\\\\\"audienceId\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\"},{\\\\\\"incoming_key\\\\\\":\\\\\\"audienceName\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"name\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\"}]\\", + mappingSchema: \\"[{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"label\\\\\\":\\\\\\"External Audience ID\\\\\\"},{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceName\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"name\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"label\\\\\\":\\\\\\"External Audience Name\\\\\\"}]\\", mappableType: \\"segmentio\\" } ) { diff --git a/packages/destination-actions/src/destinations/stackadapt-audiences/forwardAudienceEvent/functions.ts b/packages/destination-actions/src/destinations/stackadapt-audiences/forwardAudienceEvent/functions.ts index 6db62d68959..a6ed7dc0e27 100644 --- a/packages/destination-actions/src/destinations/stackadapt-audiences/forwardAudienceEvent/functions.ts +++ b/packages/destination-actions/src/destinations/stackadapt-audiences/forwardAudienceEvent/functions.ts @@ -6,23 +6,26 @@ const EXTERNAL_PROVIDER = 'segmentio' const audienceMapping = stringifyJsonWithEscapedQuotes([ { - incoming_key: 'audienceId', - destination_key: 'external_id', - type: 'string' + incomingKey: 'audienceId', + destinationKey: 'external_id', + type: 'string', + label: 'External Audience ID' }, { - incoming_key: 'audienceName', - destination_key: 'name', - type: 'string' + incomingKey: 'audienceName', + destinationKey: 'name', + type: 'string', + label: 'External Audience Name' } ]) const profileMapping = stringifyJsonWithEscapedQuotes([ { - incoming_key: 'userId', - destination_key: 'external_id', + incomingKey: 'userId', + destinationKey: 'external_id', type: 'string', - is_pii: false + isPii: false, + label: 'External Profile ID' } ]) @@ -57,7 +60,7 @@ export async function performForwardAudienceEvents(request: RequestClient, event upsertProfileMapping( input: { advertiserId: ${advertiserId}, - mappingSchema: "${profileMapping}", + mappingSchemaV2: ${profileMapping}, mappableType: "${EXTERNAL_PROVIDER}", } ) { diff --git a/packages/destination-actions/src/destinations/stackadapt-audiences/forwardProfile/__tests__/index.test.ts b/packages/destination-actions/src/destinations/stackadapt-audiences/forwardProfile/__tests__/index.test.ts index 34354f147f8..04c48ee0319 100644 --- a/packages/destination-actions/src/destinations/stackadapt-audiences/forwardProfile/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/stackadapt-audiences/forwardProfile/__tests__/index.test.ts @@ -131,7 +131,7 @@ describe('forwardProfile', () => { upsertProfileMapping( input: { advertiserId: 23, - mappingSchema: \\"[{\\\\\\"incoming_key\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"is_pii\\\\\\":false}]\\", + mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"label\\\\\\":\\\\\\"User Id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"isPii\\\\\\":false}], mappableType: \\"segmentio\\", } ) { @@ -194,7 +194,7 @@ describe('forwardProfile', () => { upsertProfileMapping( input: { advertiserId: 23, - mappingSchema: \\"[{\\\\\\"incoming_key\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"is_pii\\\\\\":false}]\\", + mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"label\\\\\\":\\\\\\"User Id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"isPii\\\\\\":false}], mappableType: \\"segmentio\\", } ) { @@ -242,7 +242,7 @@ describe('forwardProfile', () => { upsertProfileMapping( input: { advertiserId: 23, - mappingSchema: \\"[{\\\\\\"incoming_key\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"is_pii\\\\\\":false},{\\\\\\"incoming_key\\\\\\":\\\\\\"customField\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"customField\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"is_pii\\\\\\":false},{\\\\\\"incoming_key\\\\\\":\\\\\\"numberCustomField\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"numberCustomField\\\\\\",\\\\\\"type\\\\\\":\\\\\\"number\\\\\\",\\\\\\"is_pii\\\\\\":false}]\\", + mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"label\\\\\\":\\\\\\"User Id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"isPii\\\\\\":false},{\\\\\\"incomingKey\\\\\\":\\\\\\"customField\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"customField\\\\\\",\\\\\\"label\\\\\\":\\\\\\"Custom Field\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"isPii\\\\\\":false},{\\\\\\"incomingKey\\\\\\":\\\\\\"numberCustomField\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"numberCustomField\\\\\\",\\\\\\"label\\\\\\":\\\\\\"Number Custom Field\\\\\\",\\\\\\"type\\\\\\":\\\\\\"number\\\\\\",\\\\\\"isPii\\\\\\":false}], mappableType: \\"segmentio\\", } ) { @@ -290,7 +290,7 @@ describe('forwardProfile', () => { upsertProfileMapping( input: { advertiserId: 23, - mappingSchema: \\"[{\\\\\\"incoming_key\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destination_key\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"is_pii\\\\\\":false}]\\", + mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"label\\\\\\":\\\\\\"User Id\\\\\\",\\\\\\"type\\\\\\":\\\\\\"string\\\\\\",\\\\\\"isPii\\\\\\":false}], mappableType: \\"segmentio\\", } ) { diff --git a/packages/destination-actions/src/destinations/stackadapt-audiences/forwardProfile/functions.ts b/packages/destination-actions/src/destinations/stackadapt-audiences/forwardProfile/functions.ts index f20d8144c62..5b5a68fb4b2 100644 --- a/packages/destination-actions/src/destinations/stackadapt-audiences/forwardProfile/functions.ts +++ b/packages/destination-actions/src/destinations/stackadapt-audiences/forwardProfile/functions.ts @@ -24,10 +24,11 @@ const standardFields = new Set([ ]) interface Mapping { - incoming_key: string - destination_key: string + incomingKey: string + destinationKey: string + label: string type: string - is_pii: boolean + isPii: boolean } export async function performForwardProfiles(request: RequestClient, events: Payload[]) { @@ -72,7 +73,7 @@ export async function performForwardProfiles(request: RequestClient, events: Pay upsertProfileMapping( input: { advertiserId: ${advertiserId}, - mappingSchema: "${getProfileMappings(Array.from(fieldsToMap), fieldTypes)}", + mappingSchemaV2: ${getProfileMappings(Array.from(fieldsToMap), fieldTypes)}, mappableType: "${EXTERNAL_PROVIDER}", } ) { @@ -111,15 +112,31 @@ function getProfileMappings(customFields: string[], fieldTypes: Record str.toUpperCase()) + + // Check if the input starts with "audience" and attach "External" if true + if (field.startsWith('audience')) { + label = `External ${label}` + } + + return label +} + function getType(value: unknown) { if (isDateStr(value)) return 'date' return typeof value