Skip to content

Commit

Permalink
modified few conditions and reformatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
akashrpo committed Aug 4, 2021
1 parent db8cf54 commit 059263e
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 deletions integrations/Drip/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ class Drip {
return;
}

const email = message.context.traits;
const { email } = message.context.traits;
if (!email) {
logger.error("email is required for the call");
return;
}

const euConsent = message.context.traits;
const { euConsent } = message.context.traits;
if (
!(
euConsent.toLowercase() === "granted" ||
Expand All @@ -68,35 +68,30 @@ class Drip {
};
payload = removeUndefinedAndNullValues(payload);

const campaignId = message.context.traits;
const campaignId =
get(message, "context.traits.campaignId") || this.campaignId;

_dcq.push(["identify", payload]);

if (campaignId) {
if (this.campaignId == campaignId) {
let campaign_payload = {
campaign_id: campaignId,
fields: get(message, "context.traits.fields"),
double_optin: get(message, "context.traits.doubleOptin"),
success: function (response) {
// Call a method with the response object
// Success callback is optional
logger.debug(
"Subscription to an Email Series Campaign was success"
);
},
};
campaign_payload = removeUndefinedAndNullValues(campaign_payload);

_dcq.push(["identify", payload]);
_dcq.push(["subscribe", campaign_payload]);
} else {
logger.error(
"config campaignId doesn't match with user traits campaignId"
);
return;
}
}
const fields = get(message, "context.traits");
delete fields.campaignId;
delete fields.doubleOptin;

let campaign_payload = {
campaign_id: campaignId,
fields: fields,
double_optin: get(message, "context.traits.doubleOptin"),
success: function (response) {
// Call a method with the response object
// Success callback is optional
logger.debug("Subscription to an Email Series Campaign was success");
},
};
campaign_payload = removeUndefinedAndNullValues(campaign_payload);

_dcq.push(["identify", payload]);
_dcq.push(["subscribe", campaign_payload]);
}
}

track(rudderElement) {
Expand Down

0 comments on commit 059263e

Please sign in to comment.