diff --git a/src/v0/destinations/am/transform.js b/src/v0/destinations/am/transform.js index e834f71b7e..5fcfcb3669 100644 --- a/src/v0/destinations/am/transform.js +++ b/src/v0/destinations/am/transform.js @@ -195,7 +195,7 @@ const handleTraits = (messageTrait, destination) => { const getScreenevTypeAndUpdatedProperties = (message, CATEGORY_KEY) => { const name = message.name || message.event || get(message, CATEGORY_KEY); return { - evType: `Viewed ${name || ''} Screen`, + evType: `Viewed ${name ? `${name} ` : ''}Screen`, updatedProperties: { ...message.properties, name, @@ -322,7 +322,7 @@ const getDefaultResponseData = (message, rawPayload, evType, groupInfo) => { delete rawPayload.event_properties.revenue; } } - const groups = groupInfo && Object.assign(groupInfo); + const groups = groupInfo && cloneDeep(groupInfo); return { groups, rawPayload }; }; const getResponseData = (evType, destination, rawPayload, message, groupInfo) => { @@ -389,12 +389,7 @@ const nonAliasResponsebuilder = ( payload.time = new Date(getFieldValueFromMessage(message, 'timestamp')).getTime(); // send user_id only when present, for anonymous users not required - if ( - message.userId && - message.userId !== '' && - message.userId !== 'null' && - message.userId !== null - ) { + if (message.userId && message.userId !== null) { payload.user_id = message.userId; } payload.session_id = getSessionId(message); @@ -554,10 +549,9 @@ const responseBuilderSimple = ( }; const getGroupInfo = (destination, groupInfo, groupTraits) => { - let updatedGroupInfo = { ...groupInfo }; - const groupTypeTrait = get(destination, 'Config.groupTypeTrait'); - const groupValueTrait = get(destination, 'Config.groupValueTrait'); + const { groupTypeTrait, groupValueTrait } = destination.Config; if (groupTypeTrait && groupValueTrait) { + let updatedGroupInfo = { ...groupInfo }; const groupTypeValue = get(groupTraits, groupTypeTrait); const groupNameValue = get(groupTraits, groupValueTrait); // since the property updates on group at https://api2.amplitude.com/groupidentify @@ -730,7 +724,7 @@ const getProductPurchasedEvents = (message, destination) => { const trackRevenueEvent = (message, destination) => { let sendEvents = []; - const originalEvent = JSON.parse(JSON.stringify(message)); + const originalEvent = cloneDeep(message); if (destination.Config.trackProductsOnce === false) { if (isProductArrayInPayload(message)) { @@ -830,10 +824,7 @@ const getBatchEvents = (message, destination, metadata, batchEventResponse) => { if (batchEventArray.length === 0) { if (JSON.stringify(incomingMessageJSON).length < AMBatchSizeLimit) { delete message.body.JSON.options; - Object.assign(batchEventResponse, { - batchedRequest: message, - }); - + batchEventResponse.batchedRequest = message; set(batchEventResponse, 'batchedRequest.endpoint', BATCH_ENDPOINT); batchEventResponse.metadata = [metadata]; } diff --git a/test/__tests__/data/am_input.json b/test/__tests__/data/am_input.json index aa07cdb566..01cd5d0a92 100644 --- a/test/__tests__/data/am_input.json +++ b/test/__tests__/data/am_input.json @@ -4262,6 +4262,69 @@ } } }, + { + "message": { + "anonymousId": "5d205961641ee6c5", + "channel": "mobile", + "context": { + "app": { + "build": "6", + "name": "Sample Kotlin", + "namespace": "com.example.testapp1mg", + "version": "1.2" + }, + "device": { + "id": "5d205961641ee6c5", + "manufacturer": "Google", + "model": "Android SDK built for x86", + "name": "generic_x86", + "type": "Android" + }, + "library": { + "name": "com.rudderstack.android.sdk.core", + "version": "1.7.0" + }, + "locale": "en-US", + "network": { + "carrier": "Android", + "bluetooth": false, + "cellular": true, + "wifi": true + }, + "os": { + "name": "Android", + "version": "7.1.1" + }, + "screen": { + "density": 440, + "height": 2148, + "width": 1080 + }, + "sessionId": "1662393792", + "timezone": "Asia/Kolkata", + "traits": { + "anonymousId": "5d205961641ee6c5", + "id": "User Android", + "userId": "User Android" + }, + "userAgent": "Dalvik/2.1.0 (Linux; U; Android 7.1.1; Android SDK built for x86 Build/NYC)" + }, + "integrations": { + "All": true + }, + "messageId": "1662393883248-509420bf-b812-4f8d-bdb2-8c811bfde87f", + "properties": { + }, + "originalTimestamp": "2022-09-05T16:04:43.250Z", + "type": "screen", + "userId": "User Android" + }, + "destination": { + "Config": { + "apiKey": "abcde" + } + } + }, { "message": { "channel": "web", diff --git a/test/__tests__/data/am_output.json b/test/__tests__/data/am_output.json index 8b71a59445..de2709f150 100644 --- a/test/__tests__/data/am_output.json +++ b/test/__tests__/data/am_output.json @@ -3913,6 +3913,57 @@ "files": {}, "userId": "5d205961641ee6c5" }, + { + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://api2.amplitude.com/2/httpapi", + "headers": { + "Content-Type": "application/json" + }, + "params": {}, + "body": { + "JSON": { + "api_key": "abcde", + "events": [ + { + "os_name": "Android", + "os_version": "7.1.1", + "device_model": "Android SDK built for x86", + "device_manufacturer": "Google", + "device_id": "5d205961641ee6c5", + "carrier": "Android", + "app_name": "Sample Kotlin", + "app_version": "1.2", + "platform": "Android", + "language": "en-US", + "event_properties": { + }, + "insert_id": "1662393883248-509420bf-b812-4f8d-bdb2-8c811bfde87f", + "user_properties": { + "anonymousId": "5d205961641ee6c5", + "id": "User Android", + "userId": "User Android" + }, + "event_type": "Viewed Screen", + "user_id": "User Android", + "device_brand": "Google", + "time": 1662393883250, + "session_id": 1662393792, + "library": "rudderstack" + } + ], + "options": { + "min_id_length": 1 + } + }, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": {} + }, + "files": {}, + "userId": "5d205961641ee6c5" + }, { "version": "1", "type": "REST",