Skip to content

Commit

Permalink
feat: use custom screen name amplitude
Browse files Browse the repository at this point in the history
  • Loading branch information
aashishmalik committed Nov 12, 2023
1 parent 195b48a commit cdc89d3
Show file tree
Hide file tree
Showing 3 changed files with 276 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/v0/destinations/am/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -629,15 +630,27 @@ const processSingleMessage = (message, destination) => {
category = ConfigCategory.PAGE;
break;
case EventType.SCREEN:
{
const { eventType, updatedProperties } = getScreenevTypeAndUpdatedProperties(
let { eventType, updatedProperties } = getScreenevTypeAndUpdatedProperties(

Check failure on line 633 in src/v0/destinations/am/transform.js

View workflow job for this annotation

GitHub Actions / Code Coverage

Unexpected lexical declaration in case block

Check failure on line 633 in src/v0/destinations/am/transform.js

View workflow job for this annotation

GitHub Actions / Code Coverage

'updatedProperties' is never reassigned. Use 'const' instead
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';
Expand Down
100 changes: 100 additions & 0 deletions test/__tests__/data/am_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": ""
}
}
}
]
156 changes: 156 additions & 0 deletions test/__tests__/data/am_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]

0 comments on commit cdc89d3

Please sign in to comment.