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(new integration): onboard optimizely fullstack cloud mode #1805

Merged
merged 7 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 16 additions & 11 deletions src/v0/destinations/optimizely_fullstack/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,35 @@ const responseBuilder = (payload, endpoint, destination) => {
};

const trackResponseBuilder = (message, destination) => {
shrouti1507 marked this conversation as resolved.
Show resolved Hide resolved
const { event } = message;
const { event, anonymousId } = message;
if (!event) {
throw new InstrumentationError('Event name is required');
}
const { baseUrl } = destination.Config;
const { baseUrl, trackKnownUsers } = destination.Config;
const endpoint = getTrackEndPoint(baseUrl, event);
const { name } = CONFIG_CATEGORIES.TRACK;
const payload = constructPayload(message, MAPPING_CONFIG[name]);
if (!trackKnownUsers) {
payload.userId = anonymousId;
ItsSudip marked this conversation as resolved.
Show resolved Hide resolved
}
return responseBuilder(payload, endpoint, destination);
};

const pageResponseBuilder = (message, destination) => {
let event;
if (message.category && destination.Config.trackCategorizedPages) {
event = `Viewed ${message.category} page`;
const { trackCategorizedPages, trackNamedPages } = destination.Config;
const newMessage = { ...message };
const returnValue = [];

if (message.category && trackCategorizedPages) {
newMessage.event = `Viewed ${message.category} page`;
returnValue.push(trackResponseBuilder(newMessage, destination));
}
if (message.name && destination.Config.trackNamedPages) {
event = `Viewed ${message.name} page`;
if (message.name && trackNamedPages) {
shrouti1507 marked this conversation as resolved.
Show resolved Hide resolved
newMessage.event = `Viewed ${message.name} page`;
returnValue.push(trackResponseBuilder(newMessage, destination));
}

const newMessage = { ...message };
newMessage.event = event;

return trackResponseBuilder(newMessage, destination);
return returnValue;
};

const processEvent = (message, destination) => {
Expand Down
183 changes: 121 additions & 62 deletions test/__tests__/data/optimizely_fullstack.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"Config": {
"sdkKey": "test-sdk-key",
"baseUrl": "https://example.com",
"trackKnownUsers": false,
"trackKnownUsers": true,
"nonInteraction": false,
"listen": false,
"trackCategorizedPages": true,
Expand Down Expand Up @@ -181,40 +181,69 @@
}
},
{
"description": "Page call without category and name",
"description": "Page call with Track Categorized Pages is enabled",
"input": {
"message": {
"type": "page",
"channel": "web",
"userId": "test123",
"context": {},
"category": "food",
"properties": {
"url": "https://www.google.com/",
"title": "Google home"
},
"context": { "traits": { "firstName": "John", "age": 27 } },
"messageId": "2116ef8c-efc3-4ca4-851b-02ee60dad6ff",
"anonymousId": "97c46c81-3140-456d-b2a9-690d70aaca35"
},
"destination": {
"Config": {
"sdkKey": "test-sdk-key",
"baseUrl": "https://example.com",
"trackKnownUsers": false,
"trackKnownUsers": true,
"nonInteraction": false,
"listen": false,
"trackCategorizedPages": true,
"trackNamedPages": true
}
}
},
"output": {
"error": "Event name is required"
}
"output": [
{
"body": {
"FORM": {},
"JSON": {
"userId": "test123",
"userAttributes": { "firstName": "John", "age": 27 },
"eventTags": {
"url": "https://www.google.com/",
"title": "Google home"
}
},
"JSON_ARRAY": {},
"XML": {}
},
"endpoint": "https://example.com/v1/track?eventKey=Viewed%20food%20page",
"files": {},
"headers": {
"Content-Type": "application/json",
"X-Optimizely-SDK-Key": "test-sdk-key"
},
"method": "POST",
"params": {},
"type": "REST",
"version": "1"
}
]
},
{
"description": "Page call with Track Categorized Pages is enabled",
"description": "Page call with Track Named Pages is enabled",
"input": {
"message": {
"type": "page",
"channel": "web",
"userId": "test123",
"category": "food",
"name": "Thank You",
"properties": {
"url": "https://www.google.com/",
"title": "Google home"
Expand All @@ -227,48 +256,51 @@
"Config": {
"sdkKey": "test-sdk-key",
"baseUrl": "https://example.com",
"trackKnownUsers": false,
"trackKnownUsers": true,
"nonInteraction": false,
"listen": false,
"trackCategorizedPages": true,
"trackCategorizedPages": false,
"trackNamedPages": true
}
}
},
"output": {
"body": {
"FORM": {},
"JSON": {
"userId": "test123",
"userAttributes": { "firstName": "John", "age": 27 },
"eventTags": {
"url": "https://www.google.com/",
"title": "Google home"
}
"output": [
{
"body": {
"FORM": {},
"JSON": {
"userId": "test123",
"userAttributes": { "firstName": "John", "age": 27 },
"eventTags": {
"url": "https://www.google.com/",
"title": "Google home"
}
},
"JSON_ARRAY": {},
"XML": {}
},
"JSON_ARRAY": {},
"XML": {}
},
"endpoint": "https://example.com/v1/track?eventKey=Viewed%20food%20page",
"files": {},
"headers": {
"Content-Type": "application/json",
"X-Optimizely-SDK-Key": "test-sdk-key"
},
"method": "POST",
"params": {},
"type": "REST",
"version": "1"
}
"endpoint": "https://example.com/v1/track?eventKey=Viewed%20Thank%20You%20page",
"files": {},
"headers": {
"Content-Type": "application/json",
"X-Optimizely-SDK-Key": "test-sdk-key"
},
"method": "POST",
"params": {},
"type": "REST",
"version": "1"
}
]
},
{
"description": "Page call with Track Named Pages is enabled",
"description": "Page call with both Track Categorized Pages and Track Named Pages toggles are enabled",
"input": {
"message": {
"type": "page",
"channel": "web",
"userId": "test123",
"name": "Thank You",
"category": "Docs",
"name": "Index",
"properties": {
"url": "https://www.google.com/",
"title": "Google home"
Expand All @@ -281,38 +313,65 @@
"Config": {
"sdkKey": "test-sdk-key",
"baseUrl": "https://example.com",
"trackKnownUsers": false,
"trackKnownUsers": true,
"nonInteraction": false,
"listen": false,
"trackCategorizedPages": false,
"trackCategorizedPages": true,
"trackNamedPages": true
}
}
},
"output": {
"body": {
"FORM": {},
"JSON": {
"userId": "test123",
"userAttributes": { "firstName": "John", "age": 27 },
"eventTags": {
"url": "https://www.google.com/",
"title": "Google home"
}
"output": [
{
"body": {
"FORM": {},
"JSON": {
"userId": "test123",
"userAttributes": { "firstName": "John", "age": 27 },
"eventTags": {
"url": "https://www.google.com/",
"title": "Google home"
}
},
"JSON_ARRAY": {},
"XML": {}
},
"JSON_ARRAY": {},
"XML": {}
},
"endpoint": "https://example.com/v1/track?eventKey=Viewed%20Thank%20You%20page",
"files": {},
"headers": {
"Content-Type": "application/json",
"X-Optimizely-SDK-Key": "test-sdk-key"
"endpoint": "https://example.com/v1/track?eventKey=Viewed%20Docs%20page",
"files": {},
"headers": {
"Content-Type": "application/json",
"X-Optimizely-SDK-Key": "test-sdk-key"
},
"method": "POST",
"params": {},
"type": "REST",
"version": "1"
},
"method": "POST",
"params": {},
"type": "REST",
"version": "1"
}
{
"body": {
"FORM": {},
"JSON": {
"userId": "test123",
"userAttributes": { "firstName": "John", "age": 27 },
"eventTags": {
"url": "https://www.google.com/",
"title": "Google home"
}
},
"JSON_ARRAY": {},
"XML": {}
},
"endpoint": "https://example.com/v1/track?eventKey=Viewed%20Index%20page",
"files": {},
"headers": {
"Content-Type": "application/json",
"X-Optimizely-SDK-Key": "test-sdk-key"
},
"method": "POST",
"params": {},
"type": "REST",
"version": "1"
}
]
}
]