Skip to content

Commit

Permalink
Merge branch 'feat.mp_set_once' of github.com:rudderlabs/rudder-trans…
Browse files Browse the repository at this point in the history
…former into feat.mp_set_once
  • Loading branch information
shrouti1507 committed Nov 14, 2023
2 parents 1dafad7 + 2682a5d commit 13edf54
Show file tree
Hide file tree
Showing 3 changed files with 286 additions and 14 deletions.
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"
}
]

0 comments on commit 13edf54

Please sign in to comment.