From 32a1613c3677fa8812db698d28deacf625a1c223 Mon Sep 17 00:00:00 2001 From: Joe Ayoub Date: Fri, 21 Nov 2025 12:37:18 +0000 Subject: [PATCH 1/6] fixed unit tests --- .../amplitude/__tests__/amplitude.test.ts | 168 +++++++++++++++--- .../destinations/amplitude/event-schema.ts | 63 ++++++- .../amplitude/logEvent/generated-types.ts | 30 +++- .../destinations/amplitude/logEvent/index.ts | 20 ++- .../amplitude/logEventV2/generated-types.ts | 30 +++- .../amplitude/logEventV2/index.ts | 20 ++- .../amplitude/logPurchase/generated-types.ts | 30 +++- .../amplitude/logPurchase/index.ts | 22 ++- 8 files changed, 330 insertions(+), 53 deletions(-) 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..f3c09e00e09 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,14 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const responses = await testDestination.testAction('logPurchase', { event, useDefaultMappings: true }) + const mapping = { + library2: { + behavior: 'legacy', + 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({}) @@ -173,7 +180,13 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const responses = await testDestination.testAction('logPurchase', { event, useDefaultMappings: true }) + const mapping = { + library2: { + behavior: 'legacy', + 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].options.json).toMatchObject({ @@ -367,7 +380,11 @@ describe('Amplitude', () => { } }) const mapping = { - userAgentParsing: true + userAgentParsing: true, + library2: { + behavior: 'legacy', + mapping: { '@path': '$.context.library.name'} + } } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logPurchase', { event, mapping, useDefaultMappings: true }) @@ -414,7 +431,13 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const responses = await testDestination.testAction('logPurchase', { event, useDefaultMappings: true }) + const mapping = { + library2: { + behavior: 'legacy', + 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) @@ -468,7 +491,13 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const responses = await testDestination.testAction('logPurchase', { event, useDefaultMappings: true }) + const mapping = { + library2: { + behavior: 'legacy', + 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) @@ -583,9 +612,15 @@ 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: { + behavior: 'legacy', + mapping: { '@path': '$.context.library.name'} + } } + 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 +668,11 @@ describe('Amplitude', () => { }) const mapping = { - trackRevenuePerProduct: true + trackRevenuePerProduct: true, + library2: { + behavior: 'legacy', + mapping: { '@path': '$.context.library.name'} + } } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) @@ -690,7 +729,11 @@ describe('Amplitude', () => { }) const mapping = { - trackRevenuePerProduct: true + trackRevenuePerProduct: true, + library2: { + behavior: 'legacy', + mapping: { '@path': '$.context.library.name'} + } } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) @@ -744,7 +787,11 @@ describe('Amplitude', () => { }) const mapping = { - trackRevenuePerProduct: true + trackRevenuePerProduct: true, + library2: { + behavior: 'legacy', + mapping: { '@path': '$.context.library.name'} + } } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) @@ -929,8 +976,14 @@ describe('Amplitude', () => { }) nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - - const responses = await testDestination.testAction('logEvent', { event, useDefaultMappings: true }) + + const mapping = { + library2: { + behavior: 'legacy', + 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].options.json).toMatchObject({ @@ -961,6 +1014,10 @@ describe('Amplitude', () => { const mapping = { revenue: { '@path': '$.properties.bitcoin_rev' + }, + library2: { + behavior: 'legacy', + mapping: { '@path': '$.context.library.name'} } } @@ -1074,7 +1131,11 @@ describe('Amplitude', () => { } }) const mapping = { - userAgentParsing: true + userAgentParsing: true, + library2: { + behavior: 'legacy', + mapping: { '@path': '$.context.library.name'} + } } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) @@ -1120,8 +1181,13 @@ describe('Amplitude', () => { }) nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - - const responses = await testDestination.testAction('logEvent', { event, useDefaultMappings: true }) + const mapping = { + library2: { + behavior: 'legacy', + 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) @@ -1175,7 +1241,14 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const responses = await testDestination.testAction('logEvent', { event, useDefaultMappings: true }) + const mapping = { + library2: { + behavior: 'legacy', + 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) @@ -1291,7 +1364,11 @@ describe('Amplitude', () => { } }) const mapping = { - userAgentParsing: true + userAgentParsing: true, + library2: { + behavior: 'legacy', + mapping: { '@path': '$.context.library.name'} + } } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) @@ -1434,7 +1511,14 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const responses = await testDestination.testAction('logEventV2', { event, useDefaultMappings: true }) + const mapping = { + library2: { + behavior: 'legacy', + 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].options.json).toMatchObject({ @@ -1465,6 +1549,10 @@ describe('Amplitude', () => { const mapping = { revenue: { '@path': '$.properties.bitcoin_rev' + }, + library2: { + behavior: 'legacy', + mapping: { '@path': '$.context.library.name'} } } @@ -1578,7 +1666,11 @@ describe('Amplitude', () => { } }) const mapping = { - userAgentParsing: true + userAgentParsing: true, + library2: { + behavior: 'legacy', + mapping: { '@path': '$.context.library.name'} + } } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) @@ -1625,8 +1717,14 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const responses = await testDestination.testAction('logEventV2', { event, useDefaultMappings: true }) + const mapping = { + library2: { + behavior: 'legacy', + 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({}) @@ -1679,7 +1777,13 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const responses = await testDestination.testAction('logEventV2', { event, useDefaultMappings: true }) + const mapping = { + library2: { + behavior: 'legacy', + 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) @@ -1892,7 +1996,11 @@ describe('Amplitude', () => { } }) const mapping = { - userAgentParsing: true + userAgentParsing: true, + library2: { + behavior: 'legacy', + mapping: { '@path': '$.context.library.name' } + } } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) @@ -1938,7 +2046,11 @@ describe('Amplitude', () => { } }) const mapping = { - userAgentParsing: false + userAgentParsing: false, + library2: { + behavior: 'legacy', + mapping: { '@path': '$.context.library.name' } + } } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) @@ -2062,7 +2174,11 @@ describe('Amplitude', () => { }) const mapping = { - userAgentParsing: true + userAgentParsing: true, + library2: { + behavior: 'legacy', + mapping: { '@path': '$.context.library.name'} + } } nock('https://api2.amplitude.com').post('/identify').reply(200, {}) @@ -2203,7 +2319,11 @@ describe('Amplitude', () => { }) const mapping = { - userAgentParsing: true + userAgentParsing: true, + library2: { + behavior: 'legacy', + mapping: { '@path': '$.context.library.name' } + } } 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..0e96359710f 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 from the "Platform Mapping" field. "Legacy Behaviour" sets 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: 'Legacy Behaviour', value: 'legacy' }, + { 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: 'legacy', + 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: 'Legacy Behaviour', value: 'legacy' }, + { 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..c36cb6a32fd 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 from the "Platform Mapping" field. "Legacy Behaviour" sets 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..12b23c58b47 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') { + // legacy 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..b72aaaacbe3 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 from the "Platform Mapping" field. "Legacy Behaviour" sets 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..0bd1af637d5 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') { + // legacy 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..4e47a03605a 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 from the "Platform Mapping" field. "Legacy Behaviour" sets 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..70dc6faa597 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') { + // legacy 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' }) } From 4617b2d1ba578bdaae63b52b931d19f54714ae4e Mon Sep 17 00:00:00 2001 From: Joe Ayoub Date: Fri, 21 Nov 2025 14:06:02 +0000 Subject: [PATCH 2/6] making existing tests pass --- .../amplitude/__tests__/amplitude.test.ts | 105 ++++-------------- 1 file changed, 21 insertions(+), 84 deletions(-) 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 f3c09e00e09..b867602a00e 100644 --- a/packages/destination-actions/src/destinations/amplitude/__tests__/amplitude.test.ts +++ b/packages/destination-actions/src/destinations/amplitude/__tests__/amplitude.test.ts @@ -14,10 +14,7 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const mapping = { - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } const responses = await testDestination.testAction('logPurchase', { event, mapping, useDefaultMappings: true }) @@ -181,10 +178,7 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const mapping = { - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } const responses = await testDestination.testAction('logPurchase', { event, mapping, useDefaultMappings: true }) expect(responses.length).toBe(1) @@ -381,10 +375,7 @@ describe('Amplitude', () => { }) const mapping = { userAgentParsing: true, - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logPurchase', { event, mapping, useDefaultMappings: true }) @@ -432,10 +423,7 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const mapping = { - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } const responses = await testDestination.testAction('logPurchase', { event, mapping, useDefaultMappings: true }) @@ -492,10 +480,7 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const mapping = { - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } const responses = await testDestination.testAction('logPurchase', { event, mapping, useDefaultMappings: true }) @@ -615,10 +600,7 @@ describe('Amplitude', () => { const mapping = { userAgentParsing: true, - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) @@ -669,10 +651,7 @@ describe('Amplitude', () => { const mapping = { trackRevenuePerProduct: true, - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) @@ -730,10 +709,7 @@ describe('Amplitude', () => { const mapping = { trackRevenuePerProduct: true, - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) @@ -788,10 +764,7 @@ describe('Amplitude', () => { const mapping = { trackRevenuePerProduct: true, - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) @@ -978,10 +951,7 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const mapping = { - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) expect(responses.length).toBe(1) @@ -1015,10 +985,7 @@ describe('Amplitude', () => { revenue: { '@path': '$.properties.bitcoin_rev' }, - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) @@ -1132,10 +1099,7 @@ describe('Amplitude', () => { }) const mapping = { userAgentParsing: true, - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) @@ -1182,10 +1146,7 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const mapping = { - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) @@ -1242,10 +1203,7 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const mapping = { - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) @@ -1365,10 +1323,7 @@ describe('Amplitude', () => { }) const mapping = { userAgentParsing: true, - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) @@ -1512,10 +1467,7 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const mapping = { - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) @@ -1550,10 +1502,7 @@ describe('Amplitude', () => { revenue: { '@path': '$.properties.bitcoin_rev' }, - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) @@ -1667,10 +1616,7 @@ describe('Amplitude', () => { }) const mapping = { userAgentParsing: true, - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) @@ -1718,10 +1664,7 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const mapping = { - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) @@ -1778,10 +1721,7 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const mapping = { - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) @@ -2175,10 +2115,7 @@ describe('Amplitude', () => { const mapping = { userAgentParsing: true, - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name'} - } + library2: {} } nock('https://api2.amplitude.com').post('/identify').reply(200, {}) From 79b075bff901cfbf94ccea6ea62b2d27e9b33d0a Mon Sep 17 00:00:00 2001 From: Joe Ayoub Date: Fri, 21 Nov 2025 14:40:22 +0000 Subject: [PATCH 3/6] adding more unit tests --- .../amplitude/__tests__/amplitude.test.ts | 324 +++++++++++++++++- .../destinations/amplitude/event-schema.ts | 8 +- .../destinations/amplitude/logEvent/index.ts | 2 +- .../amplitude/logEventV2/index.ts | 2 +- .../amplitude/logPurchase/index.ts | 2 +- 5 files changed, 319 insertions(+), 19 deletions(-) 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 b867602a00e..1c9877800bd 100644 --- a/packages/destination-actions/src/destinations/amplitude/__tests__/amplitude.test.ts +++ b/packages/destination-actions/src/destinations/amplitude/__tests__/amplitude.test.ts @@ -33,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', @@ -862,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', @@ -1378,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', @@ -1937,10 +2246,7 @@ describe('Amplitude', () => { }) const mapping = { userAgentParsing: true, - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name' } - } + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) @@ -1987,10 +2293,7 @@ describe('Amplitude', () => { }) const mapping = { userAgentParsing: false, - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name' } - } + library2: {} } nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) @@ -2257,10 +2560,7 @@ describe('Amplitude', () => { const mapping = { userAgentParsing: true, - library2: { - behavior: 'legacy', - mapping: { '@path': '$.context.library.name' } - } + 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 0e96359710f..1c595be63f9 100644 --- a/packages/destination-actions/src/destinations/amplitude/event-schema.ts +++ b/packages/destination-actions/src/destinations/amplitude/event-schema.ts @@ -100,7 +100,7 @@ export const eventSchema: Record = { platform2: { label: 'Platform Settings', type: 'object', - description: 'Specifies the "platform" value to send to Amplitude. Select "Use Mapping" to set the value from the "Platform Mapping" field. "Legacy Behaviour" sets to "iOS", "Android" or "Web" based on values in the Segment event payload.', + 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: { @@ -108,7 +108,7 @@ export const eventSchema: Record = { description: 'Configure how to set the platform value.', type: 'string', choices: [ - { label: 'Legacy Behaviour', value: 'legacy' }, + { label: 'Auto', value: 'auto' }, { label: 'Use Mapping', value: 'use_mapping' } ] }, @@ -119,7 +119,7 @@ export const eventSchema: Record = { } }, default: { - behavior: 'legacy', + behavior: 'auto', mapping: { '@path': '$.context.device.type' } } }, @@ -346,7 +346,7 @@ export const eventSchema: Record = { description: 'Configure how to set the library value.', type: 'string', choices: [ - { label: 'Legacy Behaviour', value: 'legacy' }, + { label: 'Auto', value: 'auto' }, { label: 'Use Mapping', value: 'use_mapping' } ], }, diff --git a/packages/destination-actions/src/destinations/amplitude/logEvent/index.ts b/packages/destination-actions/src/destinations/amplitude/logEvent/index.ts index 12b23c58b47..9238cac59aa 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEvent/index.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEvent/index.ts @@ -190,7 +190,7 @@ const action: ActionDefinition = { let options if(platform2?.behavior !== 'use_mapping') { - // legacy behavior + // auto behavior if (properties.platform) { properties.platform = properties.platform.replace(/ios/i, 'iOS').replace(/android/i, 'Android') } diff --git a/packages/destination-actions/src/destinations/amplitude/logEventV2/index.ts b/packages/destination-actions/src/destinations/amplitude/logEventV2/index.ts index 0bd1af637d5..b86aac772af 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEventV2/index.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEventV2/index.ts @@ -234,7 +234,7 @@ const action: ActionDefinition = { let options if(platform2?.behavior !== 'use_mapping') { - // legacy behavior + // auto behavior if (properties.platform) { properties.platform = properties.platform.replace(/ios/i, 'iOS').replace(/android/i, 'Android') } diff --git a/packages/destination-actions/src/destinations/amplitude/logPurchase/index.ts b/packages/destination-actions/src/destinations/amplitude/logPurchase/index.ts index 70dc6faa597..0b2fb26b7c1 100644 --- a/packages/destination-actions/src/destinations/amplitude/logPurchase/index.ts +++ b/packages/destination-actions/src/destinations/amplitude/logPurchase/index.ts @@ -242,7 +242,7 @@ const action: ActionDefinition = { let options if(platform2?.behavior !== 'use_mapping') { - // legacy behavior + // auto behavior if (properties.platform) { properties.platform = properties.platform.replace(/ios/i, 'iOS').replace(/android/i, 'Android') } From 4acf2cfd3546508d9380777d2b2708caa2b52b8c Mon Sep 17 00:00:00 2001 From: Joe Ayoub Date: Fri, 21 Nov 2025 15:09:43 +0000 Subject: [PATCH 4/6] types --- .../src/destinations/amplitude/logEvent/generated-types.ts | 2 +- .../src/destinations/amplitude/logEventV2/generated-types.ts | 2 +- .../src/destinations/amplitude/logPurchase/generated-types.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 c36cb6a32fd..f9567728c14 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEvent/generated-types.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEvent/generated-types.ts @@ -48,7 +48,7 @@ export interface Payload { */ platform?: string /** - * Specifies the "platform" value to send to Amplitude. Select "Use Mapping" to set the value from the "Platform Mapping" field. "Legacy Behaviour" sets to "iOS", "Android" or "Web" based on values in the Segment event payload. + * 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?: { /** 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 b72aaaacbe3..285ed081f35 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEventV2/generated-types.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEventV2/generated-types.ts @@ -48,7 +48,7 @@ export interface Payload { */ platform?: string /** - * Specifies the "platform" value to send to Amplitude. Select "Use Mapping" to set the value from the "Platform Mapping" field. "Legacy Behaviour" sets to "iOS", "Android" or "Web" based on values in the Segment event payload. + * 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?: { /** 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 4e47a03605a..12bb6844c37 100644 --- a/packages/destination-actions/src/destinations/amplitude/logPurchase/generated-types.ts +++ b/packages/destination-actions/src/destinations/amplitude/logPurchase/generated-types.ts @@ -52,7 +52,7 @@ export interface Payload { */ platform?: string /** - * Specifies the "platform" value to send to Amplitude. Select "Use Mapping" to set the value from the "Platform Mapping" field. "Legacy Behaviour" sets to "iOS", "Android" or "Web" based on values in the Segment event payload. + * 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?: { /** From 0e29f7381d23d6e51032d19d6c8bfeb815f3cddc Mon Sep 17 00:00:00 2001 From: Joe Ayoub Date: Mon, 24 Nov 2025 10:35:20 +0000 Subject: [PATCH 5/6] removing platform2 field as it is not needed --- .../amplitude/__tests__/amplitude.test.ts | 30 ++---------------- .../destinations/amplitude/event-schema.ts | 31 ++----------------- .../amplitude/logEvent/generated-types.ts | 13 -------- .../destinations/amplitude/logEvent/index.ts | 19 ++++-------- .../amplitude/logEventV2/generated-types.ts | 13 -------- .../amplitude/logEventV2/index.ts | 17 +++------- .../amplitude/logPurchase/generated-types.ts | 13 -------- .../amplitude/logPurchase/index.ts | 17 +++------- 8 files changed, 21 insertions(+), 132 deletions(-) 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 1c9877800bd..6e39af0ee25 100644 --- a/packages/destination-actions/src/destinations/amplitude/__tests__/amplitude.test.ts +++ b/packages/destination-actions/src/destinations/amplitude/__tests__/amplitude.test.ts @@ -47,10 +47,6 @@ describe('Amplitude', () => { library2: { behavior: 'use_mapping', mapping: { '@path': '$.context.library.name' } - }, - platform2: { - behavior: 'use_mapping', - mapping: { '@path': '$.context.device.type' } } } @@ -98,11 +94,7 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const mapping = { - platform2: {} - } - - const responses = await testDestination.testAction('logPurchase', { event, mapping, useDefaultMappings: true }) + 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({}) @@ -979,10 +971,6 @@ describe('Amplitude', () => { library2: { behavior: 'use_mapping', mapping: { '@path': '$.context.library.name' } - }, - platform2: { - behavior: 'use_mapping', - mapping: { '@path': '$.context.device.type' } } } @@ -1030,11 +1018,7 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const mapping = { - platform2: {} - } - - const responses = await testDestination.testAction('logEvent', { event, mapping, useDefaultMappings: true }) + 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({}) @@ -1598,10 +1582,6 @@ describe('Amplitude', () => { library2: { behavior: 'use_mapping', mapping: { '@path': '$.context.library.name' } - }, - platform2: { - behavior: 'use_mapping', - mapping: { '@path': '$.context.device.type' } } } @@ -1649,11 +1629,7 @@ describe('Amplitude', () => { nock('https://api2.amplitude.com/2').post('/httpapi').reply(200, {}) - const mapping = { - platform2: {} - } - - const responses = await testDestination.testAction('logEventV2', { event, mapping, useDefaultMappings: true }) + 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({}) diff --git a/packages/destination-actions/src/destinations/amplitude/event-schema.ts b/packages/destination-actions/src/destinations/amplitude/event-schema.ts index 1c595be63f9..c34c2c7eb13 100644 --- a/packages/destination-actions/src/destinations/amplitude/event-schema.ts +++ b/packages/destination-actions/src/destinations/amplitude/event-schema.ts @@ -88,41 +88,14 @@ export const eventSchema: Record = { } }, platform: { - label: 'HIDDEN: Platform', + label: 'Platform', type: 'string', - unsafe_hidden: true, description: - '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 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', 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 f9567728c14..6be3c50da55 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEvent/generated-types.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEvent/generated-types.ts @@ -47,19 +47,6 @@ export interface Payload { * 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. */ diff --git a/packages/destination-actions/src/destinations/amplitude/logEvent/index.ts b/packages/destination-actions/src/destinations/amplitude/logEvent/index.ts index 9238cac59aa..abf6237b2ed 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEvent/index.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEvent/index.ts @@ -183,26 +183,19 @@ const action: ActionDefinition = { min_id_length, library, library2, - platform2, ...rest } = omit(payload, revenueKeys) const properties = rest as AmplitudeEvent let options - 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' - } - } - else { - properties.platform = platform2?.mapping + 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 (time && dayjs.utc(time).isValid()) { properties.time = dayjs.utc(time).valueOf() } 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 285ed081f35..7a6e55c5f41 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEventV2/generated-types.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEventV2/generated-types.ts @@ -47,19 +47,6 @@ export interface Payload { * 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. */ diff --git a/packages/destination-actions/src/destinations/amplitude/logEventV2/index.ts b/packages/destination-actions/src/destinations/amplitude/logEventV2/index.ts index b86aac772af..6db5fd34921 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEventV2/index.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEventV2/index.ts @@ -227,24 +227,17 @@ const action: ActionDefinition = { setOnce, setAlways, add, - platform2, ...rest } = omit(payload, revenueKeys) const properties = rest as AmplitudeEvent let options - if(platform2?.behavior !== 'use_mapping') { - // auto behavior - if (properties.platform) { - properties.platform = properties.platform.replace(/ios/i, 'iOS').replace(/android/i, 'Android') - } + if (properties.platform) { + properties.platform = properties.platform.replace(/ios/i, 'iOS').replace(/android/i, 'Android') + } - if (library === 'analytics.js' && !properties.platform) { - properties.platform = 'Web' - } - } - else { - properties.platform = platform2?.mapping + if (library === 'analytics.js' && !properties.platform) { + properties.platform = 'Web' } if (time && dayjs.utc(time).isValid()) { 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 12bb6844c37..40ec5af2b94 100644 --- a/packages/destination-actions/src/destinations/amplitude/logPurchase/generated-types.ts +++ b/packages/destination-actions/src/destinations/amplitude/logPurchase/generated-types.ts @@ -51,19 +51,6 @@ export interface Payload { * 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. */ diff --git a/packages/destination-actions/src/destinations/amplitude/logPurchase/index.ts b/packages/destination-actions/src/destinations/amplitude/logPurchase/index.ts index 0b2fb26b7c1..9227f9ca4f7 100644 --- a/packages/destination-actions/src/destinations/amplitude/logPurchase/index.ts +++ b/packages/destination-actions/src/destinations/amplitude/logPurchase/index.ts @@ -235,24 +235,17 @@ const action: ActionDefinition = { min_id_length, library, library2, - platform2, ...rest } = omit(payload, revenueKeys) const properties = rest as AmplitudeEvent let options - if(platform2?.behavior !== 'use_mapping') { - // auto behavior - if (properties.platform) { - properties.platform = properties.platform.replace(/ios/i, 'iOS').replace(/android/i, 'Android') - } + if (properties.platform) { + properties.platform = properties.platform.replace(/ios/i, 'iOS').replace(/android/i, 'Android') + } - if (library === 'analytics.js' && !properties.platform) { - properties.platform = 'Web' - } - } - else { - properties.platform = platform2?.mapping + if (library === 'analytics.js' && !properties.platform) { + properties.platform = 'Web' } if (time && dayjs.utc(time).isValid()) { From 4fea6ec91323149cdbbab8f087e4678deb81b1e6 Mon Sep 17 00:00:00 2001 From: Joe Ayoub Date: Mon, 24 Nov 2025 10:36:52 +0000 Subject: [PATCH 6/6] yarn types --- .../src/destinations/amplitude/logEvent/generated-types.ts | 2 +- .../src/destinations/amplitude/logEventV2/generated-types.ts | 2 +- .../src/destinations/amplitude/logPurchase/generated-types.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 6be3c50da55..62d045ef216 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEvent/generated-types.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEvent/generated-types.ts @@ -44,7 +44,7 @@ export interface Payload { */ app_version?: string /** - * 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 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 /** 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 7a6e55c5f41..b9407931c42 100644 --- a/packages/destination-actions/src/destinations/amplitude/logEventV2/generated-types.ts +++ b/packages/destination-actions/src/destinations/amplitude/logEventV2/generated-types.ts @@ -44,7 +44,7 @@ export interface Payload { */ app_version?: string /** - * 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 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 /** 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 40ec5af2b94..bac89df053b 100644 --- a/packages/destination-actions/src/destinations/amplitude/logPurchase/generated-types.ts +++ b/packages/destination-actions/src/destinations/amplitude/logPurchase/generated-types.ts @@ -48,7 +48,7 @@ export interface Payload { */ app_version?: string /** - * 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 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 /**