Skip to content

Commit

Permalink
Merge pull request #304 from rudderlabs/production-staging
Browse files Browse the repository at this point in the history
  • Loading branch information
arnab-p authored Aug 11, 2021
2 parents 2f9c545 + a883a35 commit 81605a7
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 0 deletions.
178 changes: 178 additions & 0 deletions integrations/Drip/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/* eslint-disable class-methods-use-this */
/* eslint-disable no-underscore-dangle */
import get from "get-value";
import logger from "../../utils/logUtil";
import {
isDefinedAndNotNull,
removeUndefinedAndNullValues,
} from "../utils/commonUtils";
import { getDestinationExternalID } from "./utils";

import { extractCustomFields } from "../../utils/utils";

class Drip {
constructor(config) {
this.accountId = config.accountId;
this.campaignId = config.campaignId;
this.name = "DRIP";
this.exclusionFields = [
"email",
"new_email",
"newEmail",
"tags",
"remove_tags",
"removeTags",
"prospect",
"eu_consent",
"euConsent",
"eu_consent_message",
"euConsentMessage",
];
}

init() {
logger.debug("===In init Drip===");

window._dcq = window._dcq || [];
window._dcs = window._dcs || {};
window._dcs.account = this.accountId;

(function () {
var dc = document.createElement("script");
dc.type = "text/javascript";
dc.async = true;
dc.src = `//tag.getdrip.com/${window._dcs.account}.js`;
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(dc, s);
})();
}

isLoaded() {
logger.debug("===In isLoaded Drip===");
return !!window._dcq;
}

isReady() {
logger.debug("===In isReady Drip===");
return !!window._dcq;
}

identify(rudderElement) {
logger.debug("===In Drip identify===");

const { message } = rudderElement;
if (!message.context || !message.context.traits) {
logger.error("user context or traits not present");
return;
}

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

let euConsent = get(message, "context.traits.euConsent");
if (
euConsent &&
!(
euConsent.toLowerCase() === "granted" ||
euConsent.toLowerCase() === "denied"
)
) {
euConsent = null;
}

let payload = {
email,
new_email: get(message, "context.traits.newEmail"),
user_id: get(message, "userId") || get(message, "anonymousId"),
tags: get(message, "context.traits.tags"),
remove_tags: get(message, "context.traits.removeTags"),
prospect: get(message, "context.traits.prospect"),
eu_consent: euConsent,
eu_consent_message: get(message, "context.traits.euConsentMessage"),
};

let extraFields = {};
try {
extraFields = extractCustomFields(
message,
extraFields,
["context.traits"],
this.exclusionFields
);
} catch (err) {
logger.debug(`Error occured at extractCustomFields ${err}`);
}

payload = {
...payload,
...extraFields,
};

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

const campaignId =
getDestinationExternalID(message, "dripCampaignId") || this.campaignId;

if (campaignId) {
const fields = payload;
delete fields.campaignId;
delete fields.doubleOptin;
delete fields.tags;

let campaignPayload = {
fields,
campaign_id: campaignId,
double_optin: get(message, "context.traits.doubleOptin"),
};
campaignPayload = removeUndefinedAndNullValues(campaignPayload);
window._dcq.push(["subscribe", campaignPayload]);
}
}

track(rudderElement) {
logger.debug("===In Drip track===");

const { message } = rudderElement;
const { event } = rudderElement.message;

if (!event) {
logger.error("Event name not present");
return;
}

const email =
get(message, "properties.email") || get(message, "context.traits.email");
if (!email) {
logger.error("email is required for track");
return;
}

let payload = get(message, "properties");

if (isDefinedAndNotNull(payload.revenue)) {
const cents = Math.round(payload.revenue * 100);
if (cents) {
payload.value = cents;
}

delete payload.revenue;
}

payload = {
...payload,
email,
occurred_at:
get(message, "properties.occurred_at") ||
get(message, "originalTimestamp"),
};

payload = removeUndefinedAndNullValues(payload);
window._dcq.push(["track", event, payload]);
}
}

export default Drip;
3 changes: 3 additions & 0 deletions integrations/Drip/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Drip from "./browser";

export default Drip;
29 changes: 29 additions & 0 deletions integrations/Drip/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// External ID format
// {
// "context": {
// "externalId": [
// {
// "type": "kustomerId",
// "id": "12345678"
// }
// ]
// }
// }
// to get destination specific external id passed in context.
function getDestinationExternalID(message, type) {
let externalIdArray = null;
let destinationExternalId = null;
if (message.context && message.context.externalId) {
externalIdArray = message.context.externalId;
}
if (externalIdArray) {
externalIdArray.forEach((extIdObj) => {
if (extIdObj.type === type) {
destinationExternalId = extIdObj.id;
}
});
}
return destinationExternalId;
}

export { getDestinationExternalID };
1 change: 1 addition & 0 deletions integrations/client_server_name.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const clientToServerNames = {
PINTEREST_TAG: "PinterestTag",
LINKEDIN_INSIGHT_TAG: "LinkedInInsightTag",
REDDIT_PIXEL: "Reddit Pixel",
DRIP: "Drip",
HEAP: "Heap.io",
CRITEO: "Criteo",
MP: "Mixpanel",
Expand Down
2 changes: 2 additions & 0 deletions integrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import * as PinterestTag from "./PinterestTag";
import * as AdobeAnalytics from "./AdobeAnalytics";
import * as LinkedInInsightTag from "./LinkedInInsightTag";
import * as RedditPixel from "./RedditPixel";
import * as Drip from "./Drip";
import * as Heap from "./Heap";
import * as Criteo from "./Criteo";
import * as Mixpanel from "./Mixpanel";
Expand Down Expand Up @@ -73,6 +74,7 @@ const integrations = {
ADOBE_ANALYTICS: AdobeAnalytics.default,
LINKEDIN_INSIGHT_TAG: LinkedInInsightTag.default,
REDDIT_PIXEL: RedditPixel.default,
DRIP: Drip.default,
HEAP: Heap.default,
CRITEO: Criteo.default,
MP: Mixpanel.default,
Expand Down
2 changes: 2 additions & 0 deletions integrations/integration_cname.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ const commonNames = {
"Reddit Pixel": "REDDIT_PIXEL",
"REDDIT PIXEL": "REDDIT_PIXEL",
"reddit pixel": "REDDIT_PIXEL",
Drip: "DRIP",
drip: "DRIP",
Heap: "HEAP",
heap: "HEAP",
"Heap.io": "HEAP",
Expand Down

0 comments on commit 81605a7

Please sign in to comment.