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(klaviyo): add all traits to profile properties in track call #2572

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
26 changes: 11 additions & 15 deletions src/v0/destinations/klaviyo/transform.js
krishna2020 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ const { JSON_MIME_TYPE } = require('../../util/constant');
/**
* Main Identify request handler func
* The function is used to create/update new users and also for adding/subscribing
* members to the list depending on conditons.If listId is there member is added to that list &
* if subscribe is true member is subscribed to that list else not.
* DOCS: https://www.klaviyo.com/docs/http-api
* users to the list.
* DOCS: 1. https://developers.klaviyo.com/en/v2023-02-22/reference/create_profile
* 2. https://developers.klaviyo.com/en/v2023-02-22/reference/update_profile
* 3. https://developers.klaviyo.com/en/v2023-02-22/reference/subscribe_profiles
* @param {*} message
* @param {*} category
* @param {*} destination
Expand Down Expand Up @@ -123,7 +124,7 @@ const identifyRequestHandler = async (message, category, destination) => {
// ----------------------
// Main handler func for track request/screen request
// User info needs to be mapped to a track event (mandatory)
// DOCS: https://www.klaviyo.com/docs/http-api
// DOCS: https://developers.klaviyo.com/en/v2023-02-22/reference/create_event
// ----------------------

const trackRequestHandler = (message, category, destination) => {
Expand All @@ -138,10 +139,6 @@ const trackRequestHandler = (message, category, destination) => {
attributes.metric = { name: eventName };
const categ = CONFIG_CATEGORIES[eventMap];
attributes.properties = constructPayload(message.properties, MAPPING_CONFIG[categ.name]);
attributes.properties = {
...attributes.properties,
...populateCustomFieldsFromTraits(message),
};

// products mapping using Items.json
// mapping properties.items to payload.properties.items and using properties.products as a fallback to properties.items
Expand Down Expand Up @@ -191,17 +188,16 @@ const trackRequestHandler = (message, category, destination) => {
if (value) {
attributes.value = value;
}
attributes.properties = {
...attributes.properties,
...populateCustomFieldsFromTraits(message),
};
}
// if flattenProperties is enabled from UI, flatten the event properties
attributes.properties = flattenProperties
? flattenJson(attributes.properties, '.', 'normal', false)
: attributes.properties;
// Map user properties to profile object
attributes.profile = createCustomerProperties(message, destination.Config);
attributes.profile = {
...createCustomerProperties(message, destination.Config),
...flattenJson(populateCustomFieldsFromTraits(message)),
krishna2020 marked this conversation as resolved.
Show resolved Hide resolved
};
if (message.timestamp) {
attributes.time = message.timestamp;
}
Expand All @@ -222,9 +218,9 @@ const trackRequestHandler = (message, category, destination) => {

// ----------------------
// Main handlerfunc for group request
// we will map user to list (subscribe and/or member)
// we will add/subscribe users to the list
// based on property sent
// DOCS: https://www.klaviyo.com/docs/api/v2/lists
// DOCS: https://developers.klaviyo.com/en/v2023-02-22/reference/subscribe_profiles
// ----------------------
const groupRequestHandler = (message, category, destination) => {
if (!message.groupId) {
Expand Down
2 changes: 1 addition & 1 deletion src/v0/destinations/klaviyo/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const profileUpdateResponseBuilder = (payload, profileId, category, privateApiKe

/**
* This function is used for creating response for subscribing users to a particular list.
* DOCS: https://www.klaviyo.com/docs/api/v2/lists
* DOCS: https://developers.klaviyo.com/en/v2023-02-22/reference/subscribe_profiles
*/
const subscribeUserToList = (message, traitsInfo, destination) => {
// listId from message properties are preferred over Config listId
Expand Down
62 changes: 34 additions & 28 deletions test/__tests__/data/klaviyo.json
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@
}
},
{
"description": "Track event call",
"description": "Screen event call",
"input": {
"destination": {
"Config": {
Expand Down Expand Up @@ -800,13 +800,13 @@
"properties": {
"PreviouslyVicePresident": true,
"YearElected": 1801,
"VicePresidents": ["Aaron Burr", "George Clinton"],
"age": "22"
"VicePresidents": ["Aaron Burr", "George Clinton"]
},
"profile": {
"$email": "[email protected]",
"$phone_number": "9112340375",
"$id": "sajal12"
"$id": "sajal12",
"age": "22"
}
}
}
Expand Down Expand Up @@ -863,7 +863,11 @@
"age": "22",
"email": "[email protected]",
"phone": "9112340375",
"anonymousId": "9c6bd77ea9da3e68"
"anonymousId": "9c6bd77ea9da3e68",
"plan_details": {
"plan_type": "gold",
"duration": "3 months"
}
},
"library": {
"name": "com.rudderstack.android.sdk.core",
Expand Down Expand Up @@ -917,13 +921,15 @@
"properties": {
"vicePresdentInfo.PreviouslVicePresident": true,
"vicePresdentInfo.VicePresidents": ["AaronBurr", "GeorgeClinton"],
"vicePresdentInfo.YearElected": 1801,
"age": "22"
"vicePresdentInfo.YearElected": 1801
},
"profile": {
"$email": "[email protected]",
"$phone_number": "9112340375",
"$id": "sajal12"
"$id": "sajal12",
"age": "22",
"plan_details.plan_type": "gold",
"plan_details.duration": "3 months"
}
}
}
Expand Down Expand Up @@ -1034,15 +1040,15 @@
"properties": {
"PreviouslyVicePresident": true,
"YearElected": 1801,
"age": "22",
"VicePresidents": ["Aaron Burr", "George Clinton"],
"description": "Sample description",
"name": "Test"
"VicePresidents": ["Aaron Burr", "George Clinton"]
},
"profile": {
"$email": "[email protected]",
"$phone_number": "9112340375",
"$id": "sajal12"
"$id": "sajal12",
"age": "22",
"name": "Test",
"description": "Sample description"
},
"value": 3000
}
Expand Down Expand Up @@ -1152,12 +1158,12 @@
"properties": {
"PreviouslyVicePresident": true,
"YearElected": 1801,
"VicePresidents": ["Aaron Burr", "George Clinton"],
"age": "22"
"VicePresidents": ["Aaron Burr", "George Clinton"]
},
"profile": {
"$email": "[email protected]",
"$phone_number": "9112340375",
"age": "22",
"_id": "sajal12"
}
}
Expand Down Expand Up @@ -1483,7 +1489,10 @@
"profile": {
"$email": "[email protected]",
"$phone_number": "9112340375",
"$id": "sajal12"
"$id": "sajal12",
"age": "22",
"name": "Test",
"description": "Sample description"
},
"properties": {
"ProductName": "test product",
Expand All @@ -1493,10 +1502,7 @@
"URL": "http://www.example.com/path/to/product",
"Brand": "Not for Kids",
"Price": 9.9,
"Categories": ["Fiction", "Children"],
"age": "22",
"name": "Test",
"description": "Sample description"
"Categories": ["Fiction", "Children"]
}
}
}
Expand Down Expand Up @@ -1633,9 +1639,6 @@
"properties": {
"$event_id": "1234",
"$value": 20,
"age": "22",
"name": "Test",
"description": "Sample description",
"items[0].ProductID": "123",
"items[0].SKU": "G-32",
"items[0].ProductName": "Monopoly",
Expand All @@ -1652,7 +1655,10 @@
"profile": {
"$email": "[email protected]",
"$phone_number": "9112340375",
"$id": "sajal12"
"$id": "sajal12",
"age": "22",
"name": "Test",
"description": "Sample description"
}
}
}
Expand Down Expand Up @@ -1780,16 +1786,16 @@
"profile": {
"$email": "[email protected]",
"$phone_number": "9112340375",
"$id": "sajal12"
"$id": "sajal12",
"age": "22",
"name": "Test",
"description": "Sample description"
},
"properties": {
"$value": 12.12,
"AddedItemCategories": ["Fiction3", "Children3"],
"ItemNames": ["book1", "book2"],
"CheckoutURL": "http://www.heythere.com",
"age": "22",
"name": "Test",
"description": "Sample description",
"items": [
{
"ProductID": "b1pid",
Expand Down