Skip to content

Commit

Permalink
add all traits to profile properties in track call
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwal-ab committed Sep 8, 2023
1 parent b3c328e commit e3d9335
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 37 deletions.
13 changes: 4 additions & 9 deletions src/v0/destinations/klaviyo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,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 +187,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)),
};
if (message.timestamp) {
attributes.time = message.timestamp;
}
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

0 comments on commit e3d9335

Please sign in to comment.