diff --git a/src/v0/destinations/am/transform.js b/src/v0/destinations/am/transform.js index d7101982a7..ccd1cf6ef0 100644 --- a/src/v0/destinations/am/transform.js +++ b/src/v0/destinations/am/transform.js @@ -593,7 +593,8 @@ const processSingleMessage = (message, destination) => { const { name, event, properties } = message; const messageType = message.type.toLowerCase(); const CATEGORY_KEY = 'properties.category'; - const { useUserDefinedPageEventName, userProvidedPageEventString } = destination.Config; + const { useUserDefinedPageEventName, userProvidedPageEventString, + useUserDefinedScreenEventName, userProvidedScreenEventString } = destination.Config; switch (messageType) { case EventType.IDENTIFY: payloadObjectName = 'events'; // identify same as events @@ -629,15 +630,27 @@ const processSingleMessage = (message, destination) => { category = ConfigCategory.PAGE; break; case EventType.SCREEN: - { - const { eventType, updatedProperties } = getScreenevTypeAndUpdatedProperties( + let { eventType, updatedProperties } = getScreenevTypeAndUpdatedProperties( message, CATEGORY_KEY, - ); - evType = eventType; - message.properties = updatedProperties; - category = ConfigCategory.SCREEN; + ); + if (useUserDefinedScreenEventName) { + const getMessagePath = userProvidedScreenEventString + .substring( + userProvidedScreenEventString.indexOf('{') + 2, + userProvidedScreenEventString.indexOf('}'), + ) + .trim(); + eventType = + userProvidedScreenEventString.trim() === '' + ? eventType + : userProvidedScreenEventString + .trim() + .replaceAll(/{{([^{}]+)}}/g, get(message, getMessagePath)); } + evType = eventType; + message.properties = updatedProperties; + category = ConfigCategory.SCREEN; break; case EventType.GROUP: evType = 'group'; diff --git a/test/__tests__/data/am_input.json b/test/__tests__/data/am_input.json index 3e5cde2cca..126d235787 100644 --- a/test/__tests__/data/am_input.json +++ b/test/__tests__/data/am_input.json @@ -4842,5 +4842,105 @@ "userProvidedPageEventString": "Viewed {{context.page.title}} event." } } + }, + { + "message": { + "type": "screen", + "userId": "identified user id", + "anonymousId": "anon-id-new", + "event": "Screen View", + "properties": { + "prop1": "5" + }, + "context": { + "ip": "14.5.67.21", + "library": { + "name": "http" + } + }, + "timestamp": "2020-02-02T00:23:09.544Z" + }, + "destination": { + "Config": { + "apiKey": "abcde", + "useUserDefinedScreenEventName": true, + "userProvidedScreenEventString": "My {{ event }} event." + } + } + }, + { + "message": { + "type": "screen", + "userId": "identified user id", + "anonymousId": "anon-id-new", + "event": "Screen View", + "properties": { + "prop1": "5" + }, + "context": { + "ip": "14.5.67.21", + "library": { + "name": "http" + } + }, + "timestamp": "2020-02-02T00:23:09.544Z" + }, + "destination": { + "Config": { + "apiKey": "abcde", + "useUserDefinedScreenEventName": false, + "userProvidedScreenEventString": "My {{ event }} event." + } + } + }, + { + "message": { + "type": "screen", + "userId": "identified user id", + "anonymousId": "anon-id-new", + "event": "Screen same as event", + "properties": { + "prop1": "5" + }, + "context": { + "ip": "14.5.67.21", + "library": { + "name": "http" + } + }, + "timestamp": "2020-02-02T00:23:09.544Z" + }, + "destination": { + "Config": { + "apiKey": "abcde", + "useUserDefinedScreenEventName": true, + "userProvidedScreenEventString": "{{ event }}" + } + } + }, + { + "message": { + "type": "screen", + "userId": "identified user id", + "anonymousId": "anon-id-new", + "name": "Screen", + "properties": { + "prop1": "5" + }, + "context": { + "ip": "14.5.67.21", + "library": { + "name": "http" + } + }, + "timestamp": "2020-02-02T00:23:09.544Z" + }, + "destination": { + "Config": { + "apiKey": "abcde", + "useUserDefinedScreenEventName": true, + "userProvidedScreenEventString": "" + } + } } ] \ No newline at end of file diff --git a/test/__tests__/data/am_output.json b/test/__tests__/data/am_output.json index 34471f4922..303f1ee090 100644 --- a/test/__tests__/data/am_output.json +++ b/test/__tests__/data/am_output.json @@ -4311,5 +4311,161 @@ }, "files": {}, "userId": "00000000000000000000000000" + }, + { + "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": [ + { + "device_id": "anon-id-new", + "library": "rudderstack", + "event_properties": { + "prop1": "5", + "name": "Screen View" + }, + "event_type": "My Screen View event.", + "time": 1580602989544, + "user_id": "identified user id", + "user_properties": {}, + "session_id": -1, + "ip": "14.5.67.21" + } + ], + "options": { + "min_id_length": 1 + } + }, + "XML": {}, + "JSON_ARRAY": {}, + "FORM": {} + }, + "files": {}, + "userId": "anon-id-new" + }, + { + "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": [ + { + "device_id": "anon-id-new", + "library": "rudderstack", + "event_properties": { + "prop1": "5", + "name": "Screen View" + }, + "event_type": "Viewed Screen View Screen", + "time": 1580602989544, + "user_id": "identified user id", + "user_properties": {}, + "session_id": -1, + "ip": "14.5.67.21" + } + ], + "options": { + "min_id_length": 1 + } + }, + "XML": {}, + "JSON_ARRAY": {}, + "FORM": {} + }, + "files": {}, + "userId": "anon-id-new" + }, + { + "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": [ + { + "device_id": "anon-id-new", + "library": "rudderstack", + "event_properties": { + "prop1": "5", + "name": "Screen same as event" + }, + "event_type": "Screen same as event", + "time": 1580602989544, + "user_id": "identified user id", + "user_properties": {}, + "session_id": -1, + "ip": "14.5.67.21" + } + ], + "options": { + "min_id_length": 1 + } + }, + "XML": {}, + "JSON_ARRAY": {}, + "FORM": {} + }, + "files": {}, + "userId": "anon-id-new" + }, + { + "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": [ + { + "device_id": "anon-id-new", + "library": "rudderstack", + "event_properties": { + "prop1": "5", + "name": "Screen" + }, + "event_type": "Viewed Screen Screen", + "time": 1580602989544, + "user_id": "identified user id", + "user_properties": {}, + "session_id": -1, + "ip": "14.5.67.21" + } + ], + "options": { + "min_id_length": 1 + } + }, + "XML": {}, + "JSON_ARRAY": {}, + "FORM": {} + }, + "files": {}, + "userId": "anon-id-new" } ] \ No newline at end of file