diff --git a/packages/destination-actions/src/destinations/amplitude/__tests__/amplitude.test.ts b/packages/destination-actions/src/destinations/amplitude/__tests__/amplitude.test.ts index 374c9490bd0..1c9877800bd 100644 --- a/packages/destination-actions/src/destinations/amplitude/__tests__/amplitude.test.ts +++ b/packages/destination-actions/src/destinations/amplitude/__tests__/amplitude.test.ts @@ -13,7 +13,11 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const responses = await testDestination.testAction('logPurchase', { event, useDefaultMappings: true }) + const mapping = { + library2: {} + } + + const responses = await testDestination.testAction('logPurchase', { event, mapping, useDefaultMappings: true }) expect(responses.length).toBe(1) expect(responses[0].status).toBe(200) expect(responses[0].data).toMatchObject({}) @@ -29,6 +33,109 @@ describe('Amplitude', () => { }) }) + it('should work with library2.behavior and platform.behavior fields set to use_mapping', async () => { + const event = createTestEvent({ timestamp, event: 'Test Event' }) + + event.context = event.context || {} + event.context.library = { name: 'custom-library-name', version: '1.0.0'} + event.context.device = event.context.device || {} + event.context.device.type = 'custom-device-type' + + nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) + + const mapping = { + library2: { + behavior: 'use_mapping', + mapping: { '@path': '$.context.library.name' } + }, + platform2: { + behavior: 'use_mapping', + mapping: { '@path': '$.context.device.type' } + } + } + + const responses = await testDestination.testAction('logPurchase', { event, mapping, useDefaultMappings: true }) + expect(responses.length).toBe(1) + expect(responses[0].status).toBe(200) + expect(responses[0].data).toMatchObject({}) + expect(responses[0].options.json).toEqual({ + api_key: undefined, + events: [ + { + city: "San Francisco", + country: "United States", + device_id: "anonId1234", + device_manufacturer: "Apple", + device_model: "iPhone", + device_type: "mobile", + event_properties: {}, + event_type: "Test Event", + ip: "8.8.8.8", + language: "en-US", + library: "custom-library-name", + location_lat: 40.2964197, + location_lng: -76.9411617, + os_name: "iOS", + os_version: "9", + platform: "custom-device-type", + time: 1629213675449, + use_batch_endpoint: false, + user_id: "user1234", + user_properties: {} + } + ], + options: undefined + }) + }) + + it('should work with platform.behavior field not set', async () => { + const event = createTestEvent({ timestamp, event: 'Test Event' }) + + event.context = event.context || {} + event.context.library = { name: 'custom-library-name', version: '1.0.0'} + event.context.device = event.context.device || {} + event.context.device.type = 'ios' + + nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) + + const mapping = { + platform2: {} + } + + const responses = await testDestination.testAction('logPurchase', { event, mapping, useDefaultMappings: true }) + expect(responses.length).toBe(1) + expect(responses[0].status).toBe(200) + expect(responses[0].data).toMatchObject({}) + expect(responses[0].options.json).toEqual({ + api_key: undefined, + events: [ + { + city: "San Francisco", + country: "United States", + device_id: "anonId1234", + device_manufacturer: "Apple", + device_model: "iPhone", + device_type: "mobile", + event_properties: {}, + event_type: "Test Event", + ip: "8.8.8.8", + language: "en-US", + library: "custom-library-name", + location_lat: 40.2964197, + location_lng: -76.9411617, + os_name: "iOS", + os_version: "9", + platform: "iOS", + time: 1629213675449, + use_batch_endpoint: false, + user_id: "user1234", + user_properties: {} + } + ], + options: undefined + }) + }) + it('should change casing for device type when value is ios', async () => { const event = createTestEvent({ event: 'Test Event', @@ -173,7 +280,10 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const responses = await testDestination.testAction('logPurchase', { event, useDefaultMappings: true }) + const mapping = { + library2: {} + } + const responses = await testDestination.testAction('logPurchase', { event, mapping, useDefaultMappings: true }) expect(responses.length).toBe(1) expect(responses[0].status).toBe(200) expect(responses[0].options.json).toMatchObject({ @@ -367,7 +477,8 @@ describe('Amplitude', () => { } }) const mapping = { - userAgentParsing: true + userAgentParsing: true, + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logPurchase', { event, mapping, useDefaultMappings: true }) @@ -414,7 +525,10 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const responses = await testDestination.testAction('logPurchase', { event, useDefaultMappings: true }) + const mapping = { + library2: {} + } + const responses = await testDestination.testAction('logPurchase', { event, mapping, useDefaultMappings: true }) expect(responses.length).toBe(1) expect(responses[0].status).toBe(200) @@ -468,7 +582,10 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const responses = await testDestination.testAction('logPurchase', { event, useDefaultMappings: true }) + const mapping = { + library2: {} + } + const responses = await testDestination.testAction('logPurchase', { event, mapping, useDefaultMappings: true }) expect(responses.length).toBe(1) expect(responses[0].status).toBe(200) @@ -583,9 +700,12 @@ describe('Amplitude', () => { 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36' } }) + const mapping = { - userAgentParsing: true + userAgentParsing: true, + library2: {} } + nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logPurchase', { event, mapping, useDefaultMappings: true }) expect(responses.length).toBe(1) @@ -633,7 +753,8 @@ describe('Amplitude', () => { }) const mapping = { - trackRevenuePerProduct: true + trackRevenuePerProduct: true, + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) @@ -690,7 +811,8 @@ describe('Amplitude', () => { }) const mapping = { - trackRevenuePerProduct: true + trackRevenuePerProduct: true, + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) @@ -744,7 +866,8 @@ describe('Amplitude', () => { }) const mapping = { - trackRevenuePerProduct: true + trackRevenuePerProduct: true, + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) @@ -842,6 +965,109 @@ describe('Amplitude', () => { }) }) + it('should work with library2.behavior and platform.behavior fields set to use_mapping', async () => { + const event = createTestEvent({ timestamp, event: 'Test Event' }) + + event.context = event.context || {} + event.context.library = { name: 'custom-library-name', version: '1.0.0'} + event.context.device = event.context.device || {} + event.context.device.type = 'custom-device-type' + + nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) + + const mapping = { + library2: { + behavior: 'use_mapping', + mapping: { '@path': '$.context.library.name' } + }, + platform2: { + behavior: 'use_mapping', + mapping: { '@path': '$.context.device.type' } + } + } + + const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) + expect(responses.length).toBe(1) + expect(responses[0].status).toBe(200) + expect(responses[0].data).toMatchObject({}) + expect(responses[0].options.json).toEqual({ + api_key: undefined, + events: [ + { + city: "San Francisco", + country: "United States", + device_id: "anonId1234", + device_manufacturer: "Apple", + device_model: "iPhone", + device_type: "mobile", + event_properties: {}, + event_type: "Test Event", + ip: "8.8.8.8", + language: "en-US", + library: "custom-library-name", + location_lat: 40.2964197, + location_lng: -76.9411617, + os_name: "iOS", + os_version: "9", + platform: "custom-device-type", + time: 1629213675449, + use_batch_endpoint: false, + user_id: "user1234", + user_properties: {} + } + ], + options: undefined + }) + }) + + it('should work with platform.behavior field not set', async () => { + const event = createTestEvent({ timestamp, event: 'Test Event' }) + + event.context = event.context || {} + event.context.library = { name: 'custom-library-name', version: '1.0.0'} + event.context.device = event.context.device || {} + event.context.device.type = 'ios' + + nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) + + const mapping = { + platform2: {} + } + + const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) + expect(responses.length).toBe(1) + expect(responses[0].status).toBe(200) + expect(responses[0].data).toMatchObject({}) + expect(responses[0].options.json).toEqual({ + api_key: undefined, + events: [ + { + city: "San Francisco", + country: "United States", + device_id: "anonId1234", + device_manufacturer: "Apple", + device_model: "iPhone", + device_type: "mobile", + event_properties: {}, + event_type: "Test Event", + ip: "8.8.8.8", + language: "en-US", + library: "custom-library-name", + location_lat: 40.2964197, + location_lng: -76.9411617, + os_name: "iOS", + os_version: "9", + platform: "iOS", + time: 1629213675449, + use_batch_endpoint: false, + user_id: "user1234", + user_properties: {} + } + ], + options: undefined + }) + }) + it('should change casing for device type when value is ios', async () => { const event = createTestEvent({ event: 'Test Event', @@ -929,8 +1155,11 @@ describe('Amplitude', () => { }) nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - - const responses = await testDestination.testAction('logEvent', { event, useDefaultMappings: true }) + + const mapping = { + library2: {} + } + const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) expect(responses.length).toBe(1) expect(responses[0].status).toBe(200) expect(responses[0].options.json).toMatchObject({ @@ -961,7 +1190,8 @@ describe('Amplitude', () => { const mapping = { revenue: { '@path': '$.properties.bitcoin_rev' - } + }, + library2: {} } const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) @@ -1074,7 +1304,8 @@ describe('Amplitude', () => { } }) const mapping = { - userAgentParsing: true + userAgentParsing: true, + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) @@ -1120,8 +1351,10 @@ describe('Amplitude', () => { }) nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - - const responses = await testDestination.testAction('logEvent', { event, useDefaultMappings: true }) + const mapping = { + library2: {} + } + const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) expect(responses.length).toBe(1) expect(responses[0].status).toBe(200) @@ -1175,7 +1408,11 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const responses = await testDestination.testAction('logEvent', { event, useDefaultMappings: true }) + const mapping = { + library2: {} + } + + const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) expect(responses.length).toBe(1) expect(responses[0].status).toBe(200) @@ -1291,7 +1528,8 @@ describe('Amplitude', () => { } }) const mapping = { - userAgentParsing: true + userAgentParsing: true, + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) @@ -1346,6 +1584,109 @@ describe('Amplitude', () => { }) }) + it('should work with library2.behavior and platform.behavior fields set to use_mapping', async () => { + const event = createTestEvent({ timestamp, event: 'Test Event' }) + + event.context = event.context || {} + event.context.library = { name: 'custom-library-name', version: '1.0.0'} + event.context.device = event.context.device || {} + event.context.device.type = 'custom-device-type' + + nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) + + const mapping = { + library2: { + behavior: 'use_mapping', + mapping: { '@path': '$.context.library.name' } + }, + platform2: { + behavior: 'use_mapping', + mapping: { '@path': '$.context.device.type' } + } + } + + const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) + expect(responses.length).toBe(1) + expect(responses[0].status).toBe(200) + expect(responses[0].data).toMatchObject({}) + expect(responses[0].options.json).toEqual({ + api_key: undefined, + events: [ + { + city: "San Francisco", + country: "United States", + device_id: "anonId1234", + device_manufacturer: "Apple", + device_model: "iPhone", + device_type: "mobile", + event_properties: {}, + event_type: "Test Event", + ip: "8.8.8.8", + language: "en-US", + library: "custom-library-name", + location_lat: 40.2964197, + location_lng: -76.9411617, + os_name: "iOS", + os_version: "9", + platform: "custom-device-type", + time: 1629213675449, + use_batch_endpoint: false, + user_id: "user1234", + user_properties: {} + } + ], + options: undefined + }) + }) + + it('should work with platform.behavior field not set', async () => { + const event = createTestEvent({ timestamp, event: 'Test Event' }) + + event.context = event.context || {} + event.context.library = { name: 'custom-library-name', version: '1.0.0'} + event.context.device = event.context.device || {} + event.context.device.type = 'ios' + + nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) + + const mapping = { + platform2: {} + } + + const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) + expect(responses.length).toBe(1) + expect(responses[0].status).toBe(200) + expect(responses[0].data).toMatchObject({}) + expect(responses[0].options.json).toEqual({ + api_key: undefined, + events: [ + { + city: "San Francisco", + country: "United States", + device_id: "anonId1234", + device_manufacturer: "Apple", + device_model: "iPhone", + device_type: "mobile", + event_properties: {}, + event_type: "Test Event", + ip: "8.8.8.8", + language: "en-US", + library: "custom-library-name", + location_lat: 40.2964197, + location_lng: -76.9411617, + os_name: "iOS", + os_version: "9", + platform: "iOS", + time: 1629213675449, + use_batch_endpoint: false, + user_id: "user1234", + user_properties: {} + } + ], + options: undefined + }) + }) + it('changes casing for device type when value is ios', async () => { const event = createTestEvent({ event: 'Test Event', @@ -1434,7 +1775,11 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const responses = await testDestination.testAction('logEventV2', { event, useDefaultMappings: true }) + const mapping = { + library2: {} + } + + const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) expect(responses.length).toBe(1) expect(responses[0].status).toBe(200) expect(responses[0].options.json).toMatchObject({ @@ -1465,7 +1810,8 @@ describe('Amplitude', () => { const mapping = { revenue: { '@path': '$.properties.bitcoin_rev' - } + }, + library2: {} } const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) @@ -1578,7 +1924,8 @@ describe('Amplitude', () => { } }) const mapping = { - userAgentParsing: true + userAgentParsing: true, + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) @@ -1625,8 +1972,11 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const responses = await testDestination.testAction('logEventV2', { event, useDefaultMappings: true }) + const mapping = { + library2: {} + } + const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) expect(responses.length).toBe(1) expect(responses[0].status).toBe(200) expect(responses[0].data).toMatchObject({}) @@ -1679,7 +2029,10 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const responses = await testDestination.testAction('logEventV2', { event, useDefaultMappings: true }) + const mapping = { + library2: {} + } + const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) expect(responses.length).toBe(1) expect(responses[0].status).toBe(200) @@ -1892,7 +2245,8 @@ describe('Amplitude', () => { } }) const mapping = { - userAgentParsing: true + userAgentParsing: true, + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) @@ -1938,7 +2292,8 @@ describe('Amplitude', () => { } }) const mapping = { - userAgentParsing: false + userAgentParsing: false, + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) @@ -2062,7 +2417,8 @@ describe('Amplitude', () => { }) const mapping = { - userAgentParsing: true + userAgentParsing: true, + library2: {} } nock('https://api2.amplitude.com').post('/identify').reply(200, {}) @@ -2203,7 +2559,8 @@ describe('Amplitude', () => { }) const mapping = { - userAgentParsing: true + userAgentParsing: true, + library2: {} } nock('https://api2.amplitude.com').post('/identify').reply(200, {}) diff --git a/packages/destination-actions/src/destinations/amplitude/event-schema.ts b/packages/destination-actions/src/destinations/amplitude/event-schema.ts index 2d2c8fac566..1c595be63f9 100644 --- a/packages/destination-actions/src/destinations/amplitude/event-schema.ts +++ b/packages/destination-actions/src/destinations/amplitude/event-schema.ts @@ -88,14 +88,41 @@ export const eventSchema: Record = { } }, platform: { - label: 'Platform', + label: 'HIDDEN: Platform', type: 'string', + unsafe_hidden: true, description: - 'Platform of the device. If using analytics.js to send events from a Browser and no if no Platform value is provided, the value "Web" will be sent.', + 'Hidden: Platform of the device. If using analytics.js to send events from a Browser and no if no Platform value is provided, the value "Web" will be sent.', default: { '@path': '$.context.device.type' } }, + platform2: { + label: 'Platform Settings', + type: 'object', + description: 'Specifies the "platform" value to send to Amplitude. Select "Use Mapping" to set the value using the "Platform Mapping" field. "Legacy Behaviour" sets the value to "iOS", "Android" or "Web" based on values in the Segment event payload.', + defaultObjectUI: 'keyvalue', + properties: { + behavior: { + label: 'Behavior', + description: 'Configure how to set the platform value.', + type: 'string', + choices: [ + { label: 'Auto', value: 'auto' }, + { label: 'Use Mapping', value: 'use_mapping' } + ] + }, + mapping: { + label: 'Platform Mapping', + description: 'The platform value to send to Amplitude. Only used when the "Behavior" field is set to "Use Mapping".', + type: 'string' + } + }, + default: { + behavior: 'auto', + mapping: { '@path': '$.context.device.type' } + } + }, os_name: { label: 'OS Name', type: 'string', @@ -299,11 +326,39 @@ export const eventSchema: Record = { 'Amplitude will deduplicate subsequent events sent with this ID we have already seen before within the past 7 days. Amplitude recommends generating a UUID or using some combination of device ID, user ID, event type, event ID, and time.' }, library: { - label: 'Library', + // hiding this field as it was the value from the field was never used correctly and has created confusion with users. + label: 'HIDDEN: Library', type: 'string', - description: 'The name of the library that generated the event.', + description: 'HIDDEN: The name of the library that generated the event.', + unsafe_hidden: true, default: { '@path': '$.context.library.name' } + }, + library2: { + label: 'Library Settings', + type: 'object', + description: 'Specifies the "library" value to send to Amplitude. Select "Use Mapping" to set the value from the "Library Mapping" field. "Legacy Behaviour" sets the value to "segment".', + defaultObjectUI: 'keyvalue', + properties: { + behavior: { + label: 'Behavior', + description: 'Configure how to set the library value.', + type: 'string', + choices: [ + { label: 'Auto', value: 'auto' }, + { label: 'Use Mapping', value: 'use_mapping' } + ], + }, + mapping: { + label: 'Library Mapping', + description: 'The library value to send to Amplitude. Only used when the "Behavior" field is set to "Use Mapping".', + type: 'string' + } + }, + default: { + behavior: 'use_mapping', + mapping: { '@path': '$.context.library.name' } + } } } diff --git a/packages/destination-actions/src/destinations/amplitude/logEvent/generated-types.ts b/packages/destination-actions/src/destinations/amplitude/logEvent/generated-types.ts index dd60578bfa2..f9567728c14 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEvent/generated-types.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEvent/generated-types.ts @@ -44,9 +44,22 @@ export interface Payload { */ app_version?: string /** - * Platform of the device. If using analytics.js to send events from a Browser and no if no Platform value is provided, the value "Web" will be sent. + * Hidden: Platform of the device. If using analytics.js to send events from a Browser and no if no Platform value is provided, the value "Web" will be sent. */ platform?: string + /** + * Specifies the "platform" value to send to Amplitude. Select "Use Mapping" to set the value using the "Platform Mapping" field. "Legacy Behaviour" sets the value to "iOS", "Android" or "Web" based on values in the Segment event payload. + */ + platform2?: { + /** + * Configure how to set the platform value. + */ + behavior?: string + /** + * The platform value to send to Amplitude. Only used when the "Behavior" field is set to "Use Mapping". + */ + mapping?: string + } /** * The name of the mobile operating system or browser that the user is using. */ @@ -148,9 +161,22 @@ export interface Payload { */ insert_id?: string /** - * The name of the library that generated the event. + * HIDDEN: The name of the library that generated the event. */ library?: string + /** + * Specifies the "library" value to send to Amplitude. Select "Use Mapping" to set the value from the "Library Mapping" field. "Legacy Behaviour" sets the value to "segment". + */ + library2?: { + /** + * Configure how to set the library value. + */ + behavior?: string + /** + * The library value to send to Amplitude. Only used when the "Behavior" field is set to "Use Mapping". + */ + mapping?: string + } /** * The list of products purchased. */ diff --git a/packages/destination-actions/src/destinations/amplitude/logEvent/index.ts b/packages/destination-actions/src/destinations/amplitude/logEvent/index.ts index aa10e91d9d6..9238cac59aa 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEvent/index.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEvent/index.ts @@ -182,17 +182,25 @@ const action: ActionDefinition = { referrer, min_id_length, library, + library2, + platform2, ...rest } = omit(payload, revenueKeys) const properties = rest as AmplitudeEvent let options - if (properties.platform) { - properties.platform = properties.platform.replace(/ios/i, 'iOS').replace(/android/i, 'Android') - } + if(platform2?.behavior !== 'use_mapping') { + // auto behavior + if (properties.platform) { + properties.platform = properties.platform.replace(/ios/i, 'iOS').replace(/android/i, 'Android') + } - if (library === 'analytics.js' && !properties.platform) { - properties.platform = 'Web' + if (library === 'analytics.js' && !properties.platform) { + properties.platform = 'Web' + } + } + else { + properties.platform = platform2?.mapping } if (time && dayjs.utc(time).isValid()) { @@ -222,7 +230,7 @@ const action: ActionDefinition = { ...(includeRawUserAgent && { user_agent: userAgent }), // Make sure any top-level properties take precedence over user-agent properties ...removeUndefined(properties), - library: 'segment' + library: library2?.behavior === 'use_mapping' ? library2.mapping : 'segment' } ] diff --git a/packages/destination-actions/src/destinations/amplitude/logEventV2/generated-types.ts b/packages/destination-actions/src/destinations/amplitude/logEventV2/generated-types.ts index 787b698616a..285ed081f35 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEventV2/generated-types.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEventV2/generated-types.ts @@ -44,9 +44,22 @@ export interface Payload { */ app_version?: string /** - * Platform of the device. If using analytics.js to send events from a Browser and no if no Platform value is provided, the value "Web" will be sent. + * Hidden: Platform of the device. If using analytics.js to send events from a Browser and no if no Platform value is provided, the value "Web" will be sent. */ platform?: string + /** + * Specifies the "platform" value to send to Amplitude. Select "Use Mapping" to set the value using the "Platform Mapping" field. "Legacy Behaviour" sets the value to "iOS", "Android" or "Web" based on values in the Segment event payload. + */ + platform2?: { + /** + * Configure how to set the platform value. + */ + behavior?: string + /** + * The platform value to send to Amplitude. Only used when the "Behavior" field is set to "Use Mapping". + */ + mapping?: string + } /** * The name of the mobile operating system or browser that the user is using. */ @@ -148,9 +161,22 @@ export interface Payload { */ insert_id?: string /** - * The name of the library that generated the event. + * HIDDEN: The name of the library that generated the event. */ library?: string + /** + * Specifies the "library" value to send to Amplitude. Select "Use Mapping" to set the value from the "Library Mapping" field. "Legacy Behaviour" sets the value to "segment". + */ + library2?: { + /** + * Configure how to set the library value. + */ + behavior?: string + /** + * The library value to send to Amplitude. Only used when the "Behavior" field is set to "Use Mapping". + */ + mapping?: string + } /** * The list of products purchased. */ diff --git a/packages/destination-actions/src/destinations/amplitude/logEventV2/index.ts b/packages/destination-actions/src/destinations/amplitude/logEventV2/index.ts index ef20b455231..b86aac772af 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEventV2/index.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEventV2/index.ts @@ -223,20 +223,28 @@ const action: ActionDefinition = { userAgentData, min_id_length, library, + library2, setOnce, setAlways, add, + platform2, ...rest } = omit(payload, revenueKeys) const properties = rest as AmplitudeEvent let options - if (properties.platform) { - properties.platform = properties.platform.replace(/ios/i, 'iOS').replace(/android/i, 'Android') - } + if(platform2?.behavior !== 'use_mapping') { + // auto behavior + if (properties.platform) { + properties.platform = properties.platform.replace(/ios/i, 'iOS').replace(/android/i, 'Android') + } - if (library === 'analytics.js' && !properties.platform) { - properties.platform = 'Web' + if (library === 'analytics.js' && !properties.platform) { + properties.platform = 'Web' + } + } + else { + properties.platform = platform2?.mapping } if (time && dayjs.utc(time).isValid()) { @@ -271,7 +279,7 @@ const action: ActionDefinition = { ...(includeRawUserAgent && { user_agent: userAgent }), // Make sure any top-level properties take precedence over user-agent properties ...removeUndefined(properties), - library: 'segment' + library: library2?.behavior === 'use_mapping' ? library2.mapping : 'segment' } ] diff --git a/packages/destination-actions/src/destinations/amplitude/logPurchase/generated-types.ts b/packages/destination-actions/src/destinations/amplitude/logPurchase/generated-types.ts index acc0a64d7c5..12bb6844c37 100644 --- a/packages/destination-actions/src/destinations/amplitude/logPurchase/generated-types.ts +++ b/packages/destination-actions/src/destinations/amplitude/logPurchase/generated-types.ts @@ -48,9 +48,22 @@ export interface Payload { */ app_version?: string /** - * Platform of the device. If using analytics.js to send events from a Browser and no if no Platform value is provided, the value "Web" will be sent. + * Hidden: Platform of the device. If using analytics.js to send events from a Browser and no if no Platform value is provided, the value "Web" will be sent. */ platform?: string + /** + * Specifies the "platform" value to send to Amplitude. Select "Use Mapping" to set the value using the "Platform Mapping" field. "Legacy Behaviour" sets the value to "iOS", "Android" or "Web" based on values in the Segment event payload. + */ + platform2?: { + /** + * Configure how to set the platform value. + */ + behavior?: string + /** + * The platform value to send to Amplitude. Only used when the "Behavior" field is set to "Use Mapping". + */ + mapping?: string + } /** * The name of the mobile operating system or browser that the user is using. */ @@ -152,9 +165,22 @@ export interface Payload { */ insert_id?: string /** - * The name of the library that generated the event. + * HIDDEN: The name of the library that generated the event. */ library?: string + /** + * Specifies the "library" value to send to Amplitude. Select "Use Mapping" to set the value from the "Library Mapping" field. "Legacy Behaviour" sets the value to "segment". + */ + library2?: { + /** + * Configure how to set the library value. + */ + behavior?: string + /** + * The library value to send to Amplitude. Only used when the "Behavior" field is set to "Use Mapping". + */ + mapping?: string + } /** * The list of products purchased. */ diff --git a/packages/destination-actions/src/destinations/amplitude/logPurchase/index.ts b/packages/destination-actions/src/destinations/amplitude/logPurchase/index.ts index 7db7dc8889e..0b2fb26b7c1 100644 --- a/packages/destination-actions/src/destinations/amplitude/logPurchase/index.ts +++ b/packages/destination-actions/src/destinations/amplitude/logPurchase/index.ts @@ -234,17 +234,25 @@ const action: ActionDefinition = { referrer, min_id_length, library, + library2, + platform2, ...rest } = omit(payload, revenueKeys) const properties = rest as AmplitudeEvent let options - if (properties.platform) { - properties.platform = properties.platform.replace(/ios/i, 'iOS').replace(/android/i, 'Android') - } + if(platform2?.behavior !== 'use_mapping') { + // auto behavior + if (properties.platform) { + properties.platform = properties.platform.replace(/ios/i, 'iOS').replace(/android/i, 'Android') + } - if (library === 'analytics.js' && !properties.platform) { - properties.platform = 'Web' + if (library === 'analytics.js' && !properties.platform) { + properties.platform = 'Web' + } + } + else { + properties.platform = platform2?.mapping } if (time && dayjs.utc(time).isValid()) { @@ -276,7 +284,7 @@ const action: ActionDefinition = { ...removeUndefined(properties), // Conditionally track revenue with main event ...(products.length && trackRevenuePerProduct ? {} : getRevenueProperties(payload)), - library: 'segment' + library: library2?.behavior === 'use_mapping' ? library2.mapping : 'segment' } ] @@ -288,7 +296,7 @@ const action: ActionDefinition = { event_properties: product, event_type: 'Product Purchased', insert_id: properties.insert_id ? `${properties.insert_id}-${events.length + 1}` : undefined, - library: 'segment' + library: library2?.behavior === 'use_mapping' ? library2.mapping : 'segment' }) }