Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use custom screen name amplitude #2823

Merged
merged 5 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions src/v0/destinations/am/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,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 All @@ -601,17 +602,17 @@ const processSingleMessage = (message, destination) => {
case EventType.PAGE:
if (useUserDefinedPageEventName) {
const getMessagePath = userProvidedPageEventString
.substring(
userProvidedPageEventString.indexOf('{') + 2,
userProvidedPageEventString.indexOf('}'),
)
.trim();
.substring(
userProvidedPageEventString.indexOf('{') + 2,
userProvidedPageEventString.indexOf('}'),
)
.trim();
evType =
userProvidedPageEventString.trim() === ''
? name
: userProvidedPageEventString
.trim()
.replaceAll(/{{([^{}]+)}}/g, get(message, getMessagePath));
userProvidedPageEventString.trim() === ''
? name
: userProvidedPageEventString
.trim()
.replaceAll(/{{([^{}]+)}}/g, get(message, getMessagePath));
} else {
evType = `Viewed ${name || get(message, CATEGORY_KEY) || ''} Page`;
}
Expand All @@ -624,10 +625,25 @@ const processSingleMessage = (message, destination) => {
case EventType.SCREEN:
{
const { eventType, updatedProperties } = getScreenevTypeAndUpdatedProperties(
message,
CATEGORY_KEY,
message,
CATEGORY_KEY,
);
evType = eventType;
let customScreenEv = '';
if (useUserDefinedScreenEventName) {
const getMessagePath = userProvidedScreenEventString
.substring(
userProvidedScreenEventString.indexOf('{') + 2,
userProvidedScreenEventString.indexOf('}'),
)
.trim();
customScreenEv =
userProvidedScreenEventString.trim() === ''
? name
: userProvidedScreenEventString
.trim()
.replaceAll(/{{([^{}]+)}}/g, get(message, getMessagePath));
}
evType =useUserDefinedScreenEventName ? customScreenEv : eventType;
message.properties = updatedProperties;
category = ConfigCategory.SCREEN;
}
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": "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"
}
]
Loading