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..6e39af0ee25 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,101 @@ 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' } + } + } + + 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 responses = await testDestination.testAction('logPurchase', { event, 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 +272,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 +469,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 +517,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 +574,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 +692,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 +745,8 @@ describe('Amplitude', () => { }) const mapping = { - trackRevenuePerProduct: true + trackRevenuePerProduct: true, + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) @@ -690,7 +803,8 @@ describe('Amplitude', () => { }) const mapping = { - trackRevenuePerProduct: true + trackRevenuePerProduct: true, + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) @@ -744,7 +858,8 @@ describe('Amplitude', () => { }) const mapping = { - trackRevenuePerProduct: true + trackRevenuePerProduct: true, + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) @@ -842,6 +957,101 @@ 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' } + } + } + + 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 responses = await testDestination.testAction('logEvent', { event, 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 +1139,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 +1174,8 @@ describe('Amplitude', () => { const mapping = { revenue: { '@path': '$.properties.bitcoin_rev' - } + }, + library2: {} } const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) @@ -1074,7 +1288,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 +1335,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 +1392,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 +1512,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 +1568,101 @@ 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' } + } + } + + 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 responses = await testDestination.testAction('logEventV2', { event, 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 +1751,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 +1786,8 @@ describe('Amplitude', () => { const mapping = { revenue: { '@path': '$.properties.bitcoin_rev' - } + }, + library2: {} } const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) @@ -1578,7 +1900,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 +1948,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 +2005,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 +2221,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 +2268,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 +2393,8 @@ describe('Amplitude', () => { }) const mapping = { - userAgentParsing: true + userAgentParsing: true, + library2: {} } nock('https://api2.amplitude.com').post('/identify').reply(200, {}) @@ -2203,7 +2535,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..c34c2c7eb13 100644 --- a/packages/destination-actions/src/destinations/amplitude/event-schema.ts +++ b/packages/destination-actions/src/destinations/amplitude/event-schema.ts @@ -299,11 +299,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..62d045ef216 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEvent/generated-types.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEvent/generated-types.ts @@ -148,9 +148,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..abf6237b2ed 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEvent/index.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEvent/index.ts @@ -182,6 +182,7 @@ const action: ActionDefinition = { referrer, min_id_length, library, + library2, ...rest } = omit(payload, revenueKeys) const properties = rest as AmplitudeEvent @@ -194,7 +195,7 @@ const action: ActionDefinition = { if (library === 'analytics.js' && !properties.platform) { properties.platform = 'Web' } - + if (time && dayjs.utc(time).isValid()) { properties.time = dayjs.utc(time).valueOf() } @@ -222,7 +223,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..b9407931c42 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEventV2/generated-types.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEventV2/generated-types.ts @@ -148,9 +148,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..6db5fd34921 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEventV2/index.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEventV2/index.ts @@ -223,6 +223,7 @@ const action: ActionDefinition = { userAgentData, min_id_length, library, + library2, setOnce, setAlways, add, @@ -271,7 +272,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..bac89df053b 100644 --- a/packages/destination-actions/src/destinations/amplitude/logPurchase/generated-types.ts +++ b/packages/destination-actions/src/destinations/amplitude/logPurchase/generated-types.ts @@ -152,9 +152,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..9227f9ca4f7 100644 --- a/packages/destination-actions/src/destinations/amplitude/logPurchase/index.ts +++ b/packages/destination-actions/src/destinations/amplitude/logPurchase/index.ts @@ -234,6 +234,7 @@ const action: ActionDefinition = { referrer, min_id_length, library, + library2, ...rest } = omit(payload, revenueKeys) const properties = rest as AmplitudeEvent @@ -276,7 +277,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 +289,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' }) }