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

fix(klaviyo): add check for listId for subscribe #2263

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions src/v0/destinations/klaviyo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ const identifyRequestHandler = async (message, category, destination) => {
// Update Profile
const responseArray = [profileUpdateResponseBuilder(payload, profileId, category, privateApiKey)];

// check if user wants to subscribe profile or not
if (traitsInfo?.properties?.subscribe) {
// check if user wants to subscribe profile or not and listId is present or not
if (
traitsInfo?.properties?.subscribe &&
(traitsInfo.properties?.listId || destination.Config?.listId)
) {
responseArray.push(subscribeUserToList(message, traitsInfo, destination));
return responseArray;
}
krishna2020 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
21 changes: 0 additions & 21 deletions src/v0/destinations/klaviyo/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,6 @@ const subscribeUserToList = (message, traitsInfo, destination) => {
return response;
};

/**
* This function is used to check if the user needs to be subscribed or not.
* Building and returning response array for subscribe endpoint (for subscribing)
* @param {*} message
* @param {*} traitsInfo
* @param {*} destination
* @returns
*/
const checkForSubscribe = (message, traitsInfo, destination) => {
const responseArray = [];
if (
(traitsInfo.properties?.listId || destination.Config?.listId) &&
traitsInfo.properties?.subscribe === true
) {
const subscribeResponse = subscribeUserToList(message, traitsInfo, destination);
responseArray.push(subscribeResponse);
}
return responseArray;
};

// This function is used for creating and returning customer properties using mapping json
const createCustomerProperties = (message) => {
let customerProperties = constructPayload(
Expand Down Expand Up @@ -271,7 +251,6 @@ const batchSubscribeEvents = (subscribeRespList) => {

module.exports = {
subscribeUserToList,
checkForSubscribe,
createCustomerProperties,
populateCustomFieldsFromTraits,
generateBatchedPaylaodForArray,
Expand Down
109 changes: 109 additions & 0 deletions test/__tests__/data/klaviyo.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,115 @@
}
]
},
{
"description": "Profile updation call listId is not provided for subscribing the user",
"input": {
"destination": {
"Config": {
"publicApiKey": "WJqij9",
"privateApiKey": "pk_b68c7b5163d98807fcb57e6f921216629d"
}
},
"message": {
"type": "identify",
"sentAt": "2021-01-03T17:02:53.195Z",
"userId": "utsabc",
"channel": "web",
"context": {
"os": {
"name": "",
"version": ""
},
"app": {
"name": "RudderLabs JavaScript SDK",
"build": "1.0.0",
"version": "1.1.11",
"namespace": "com.rudderlabs.javascript"
},
"traits": {
"firstName": "Utsab",
"lastName": "Chowdhury",
"email": "utsab@rudderstack.com",
"phone": "+12 345 578 900",
"userId": "utsabc",
"title": "Developer",
"organization": "Rudder",
"city": "Tokyo",
"region": "Kanto",
"country": "JP",
"zip": "100-0001",
"Flagged": false,
"Residence": "Shibuya",
"properties": {
"subscribe": false,
"consent": ["email", "sms"]
}
},
"locale": "en-US",
"screen": {
"density": 2
},
"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.1.11"
},
"campaign": {},
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0"
},
"rudderId": "8f8fa6b5-8e24-489c-8e22-61f23f2e364f",
"messageId": "2116ef8c-efc3-4ca4-851b-02ee60dad6ff",
"anonymousId": "97c46c81-3140-456d-b2a9-690d70aaca35",
"integrations": {
"All": true
},
"originalTimestamp": "2021-01-03T17:02:53.193Z"
}
},
"output": {
"version": "1",
"type": "REST",
"method": "PATCH",
"endpoint": "https://a.klaviyo.com/api/profiles/01GW3PHVY0MTCDGS0A1612HARX",
"headers": {
"Accept": "application/json",
"Authorization": "Klaviyo-API-Key pk_b68c7b5163d98807fcb57e6f921216629d",
"Content-Type": "application/json",
"revision": "2023-02-22"
},
"params": {},
"body": {
"JSON": {
"data": {
"type": "profile",
"attributes": {
"external_id": "utsabc",
"email": "utsab@rudderstack.com",
"first_name": "Utsab",
"last_name": "Chowdhury",
"phone_number": "+12 345 578 900",
"title": "Developer",
"organization": "Rudder",
"location": {
"city": "Tokyo",
"region": "Kanto",
"country": "JP",
"zip": "100-0001"
}
},
"properties": {
"Flagged": false,
"Residence": "Shibuya"
},
"id": "01GW3PHVY0MTCDGS0A1612HARX"
}
},
"JSON_ARRAY": {},
"XML": {},
"FORM": {}
},
"files": {}
}
},
{
"description": "Identify call with enforceEmailAsPrimary enabled from UI",
"input": {
Expand Down