From e3d9335eb859c4eeeb41094ad204ced413c7bb39 Mon Sep 17 00:00:00 2001 From: ujjwal-ab Date: Fri, 8 Sep 2023 16:58:47 +0530 Subject: [PATCH] add all traits to profile properties in track call --- src/v0/destinations/klaviyo/transform.js | 13 ++--- test/__tests__/data/klaviyo.json | 62 +++++++++++++----------- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/v0/destinations/klaviyo/transform.js b/src/v0/destinations/klaviyo/transform.js index d7170ce789..2bdb4cf957 100644 --- a/src/v0/destinations/klaviyo/transform.js +++ b/src/v0/destinations/klaviyo/transform.js @@ -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 @@ -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; } diff --git a/test/__tests__/data/klaviyo.json b/test/__tests__/data/klaviyo.json index e3ce30c792..1fc46a6e4c 100644 --- a/test/__tests__/data/klaviyo.json +++ b/test/__tests__/data/klaviyo.json @@ -705,7 +705,7 @@ } }, { - "description": "Track event call", + "description": "Screen event call", "input": { "destination": { "Config": { @@ -800,13 +800,13 @@ "properties": { "PreviouslyVicePresident": true, "YearElected": 1801, - "VicePresidents": ["Aaron Burr", "George Clinton"], - "age": "22" + "VicePresidents": ["Aaron Burr", "George Clinton"] }, "profile": { "$email": "test@rudderstack.com", "$phone_number": "9112340375", - "$id": "sajal12" + "$id": "sajal12", + "age": "22" } } } @@ -863,7 +863,11 @@ "age": "22", "email": "test@rudderstack.com", "phone": "9112340375", - "anonymousId": "9c6bd77ea9da3e68" + "anonymousId": "9c6bd77ea9da3e68", + "plan_details": { + "plan_type": "gold", + "duration": "3 months" + } }, "library": { "name": "com.rudderstack.android.sdk.core", @@ -917,13 +921,15 @@ "properties": { "vicePresdentInfo.PreviouslVicePresident": true, "vicePresdentInfo.VicePresidents": ["AaronBurr", "GeorgeClinton"], - "vicePresdentInfo.YearElected": 1801, - "age": "22" + "vicePresdentInfo.YearElected": 1801 }, "profile": { "$email": "test@rudderstack.com", "$phone_number": "9112340375", - "$id": "sajal12" + "$id": "sajal12", + "age": "22", + "plan_details.plan_type": "gold", + "plan_details.duration": "3 months" } } } @@ -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": "test@rudderstack.com", "$phone_number": "9112340375", - "$id": "sajal12" + "$id": "sajal12", + "age": "22", + "name": "Test", + "description": "Sample description" }, "value": 3000 } @@ -1152,12 +1158,12 @@ "properties": { "PreviouslyVicePresident": true, "YearElected": 1801, - "VicePresidents": ["Aaron Burr", "George Clinton"], - "age": "22" + "VicePresidents": ["Aaron Burr", "George Clinton"] }, "profile": { "$email": "test@rudderstack.com", "$phone_number": "9112340375", + "age": "22", "_id": "sajal12" } } @@ -1483,7 +1489,10 @@ "profile": { "$email": "test@rudderstack.com", "$phone_number": "9112340375", - "$id": "sajal12" + "$id": "sajal12", + "age": "22", + "name": "Test", + "description": "Sample description" }, "properties": { "ProductName": "test product", @@ -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"] } } } @@ -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", @@ -1652,7 +1655,10 @@ "profile": { "$email": "test@rudderstack.com", "$phone_number": "9112340375", - "$id": "sajal12" + "$id": "sajal12", + "age": "22", + "name": "Test", + "description": "Sample description" } } } @@ -1780,16 +1786,16 @@ "profile": { "$email": "test@rudderstack.com", "$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",