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(destination): stringify the object and array for Clevertap #1554

Merged
merged 11 commits into from
Nov 9, 2022
47 changes: 47 additions & 0 deletions v0/destinations/clevertap/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,46 @@ const responseWrapper = (payload, destination) => {
return response;
};

/**
* Expected behaviours:
payload = { "finalPayload": {
"device": { "device": "{\"browser\":{\"name\":\"Chrome121\",\"version\":\"106.0.0.0\"},\"os\":{\"version\":\"10.15.7\"}}",
"browser": { "name": "macOS",
"name": "Chrome121", "platform": "web"
"version": "106.0.0.0" }
},
"os": {
"version": "10.15.7"
}
},
"name": "macOS",
"platform": "web"
}
*
}
* This function stringify the payload attributes if it's an array or objects.
* @param {*} payload
* @returns
* return the final payload after converting to the relevant data-types.
*/
const convertObjectAndArrayToString = payload => {
const finalPayload = {};
if (payload) {
const category = Object.keys(payload);
category.forEach(key => {
ItsSudip marked this conversation as resolved.
Show resolved Hide resolved
if (
payload[key] &&
(Array.isArray(payload[key]) || typeof payload[key] === "object")
) {
finalPayload[key] = JSON.stringify(payload[key]);
} else {
finalPayload[key] = payload[key];
}
});
}
return finalPayload;
};

// generates clevertap identify payload with both objectId and identity
const mapIdentifyPayloadWithObjectId = (message, profile) => {
const userId = getFieldValueFromMessage(message, "userIdOnly");
Expand Down Expand Up @@ -172,6 +212,7 @@ const getClevertapProfile = (message, category) => {
["traits", "context.traits"],
CLEVERTAP_DEFAULT_EXCLUSION
);
profile = convertObjectAndArrayToString(profile);

return removeUndefinedAndNullValues(profile);
};
Expand Down Expand Up @@ -267,6 +308,12 @@ const responseBuilderSimple = (message, category, destination) => {
eventPayload = constructPayload(message, MAPPING_CONFIG[category.name]);
}
eventPayload.type = "event";
// stringify the evtData if it's an Object or array.
if (eventPayload.evtData) {
eventPayload.evtData = convertObjectAndArrayToString(
eventPayload.evtData
);
}

// setting identification for tracking payload here based on destination config
if (destination.Config.enableObjectIdMapping) {
Expand Down