Skip to content

Commit

Permalink
ProfitWell Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
akashrpo committed Sep 10, 2021
1 parent cd860cd commit 1ef638f
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 0 deletions.
98 changes: 98 additions & 0 deletions integrations/ProfitWell/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* eslint-disable class-methods-use-this */
import get from "get-value";
import logger from "../../utils/logUtil";
import Storage from "../../utils/storage";
import { removeUndefinedAndNullValues } from "../utils/commonUtils";

class ProfitWell {
constructor(config) {
this.publicApiToken = config.publicApiToken;
this.name = "ProfitWell";
}

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

(function (i, s, o, g, r, a, m) {
i[o] =
i[o] ||
function () {
(i[o].q = i[o].q || []).push(arguments);
};
a = s.createElement(g);
m = s.getElementsByTagName(g)[0];
a.async = 1;
a.src =
r +
"?auth=" +
s.getElementById(o + "-js").getAttribute(this.publicApiToken);
m.parentNode.insertBefore(a, m);
})(
window,
document,
"profitwell",
"script",
"https://public.profitwell.com/js/profitwell.js"
);

const cookieData = Storage.getUserTraits();

let payload = {
user_email: cookieData.email,
user_id: cookieData.userId,
};

if (!payload.user_email && !payload.user_id) {
logger.debug(
"User parameter (email or id) not found in cookie. identify is required"
);
return;
}

if (payload.user_email) {
delete payload.user_id;
} else {
delete payload.user_email;
}

payload = removeUndefinedAndNullValues(payload);
window.profitwell("start", payload);
}

isLoaded() {
logger.debug("===In isLoaded ProfitWell===");
return !!window.profitwell;
}

isReady() {
logger.debug("===In isReady ProfitWell===");
return !!window.profitwell;
}

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

const { message } = rudderElement;

let payload = {
user_email: get(message, "context.traits.email"),
user_id: get(message, "context.userId"),
};

if (!payload.user_email && !payload.user_id) {
logger.error("User parameter (email or id) is required");
return;
}

if (payload.user_email) {
delete payload.user_id;
} else {
delete payload.user_email;
}

payload = removeUndefinedAndNullValues(payload);
window.profitwell("start", payload);
}
}

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

export default ProfitWell;
1 change: 1 addition & 0 deletions integrations/client_server_name.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const clientToServerNames = {
LYTICS: "Lytics",
APPCUES: "Appcues",
POSTHOG: "PostHog",
PROFITWELL: "ProfitWell",
KLAVIYO: "Klaviyo",
CLEVERTAP: "Clevertap",
BINGADS: "BingAds",
Expand Down
2 changes: 2 additions & 0 deletions integrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import * as Criteo from "./Criteo";
import * as Mixpanel from "./Mixpanel";
import * as Qualtrics from "./Qualtrics";
import * as SnapPixel from "./SnapPixel";
import * as ProfitWell from "./ProfitWell";

// the key names should match the destination.name value to keep partity everywhere
// (config-plan name, native destination.name , exported integration name(this one below))
Expand Down Expand Up @@ -81,6 +82,7 @@ const integrations = {
MP: Mixpanel.default,
QUALTRICS: Qualtrics.default,
SNAP_PIXEL: SnapPixel.default,
PROFITWELL: ProfitWell.default,
};

export { integrations };
3 changes: 3 additions & 0 deletions integrations/integration_cname.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ const commonNames = {
"Snap Pixel": "SNAP_PIXEL",
"SNAP PIXEL": "SNAP_PIXEL",
"snap pixel": "SNAP_PIXEL",
PROFITWELL: "PROFITWELL",
ProfitWell: "PROFITWELL",
profitwell: "PROFITWELL",
};

export { commonNames };

0 comments on commit 1ef638f

Please sign in to comment.