From 1ef638f5a731d7b58eff94f1a6b4f271e9348dc7 Mon Sep 17 00:00:00 2001 From: Akash Gupta Date: Fri, 10 Sep 2021 12:25:35 +0530 Subject: [PATCH] ProfitWell Initial Commit --- integrations/ProfitWell/browser.js | 98 ++++++++++++++++++++++++++++++ integrations/ProfitWell/index.js | 3 + integrations/client_server_name.js | 1 + integrations/index.js | 2 + integrations/integration_cname.js | 3 + 5 files changed, 107 insertions(+) create mode 100644 integrations/ProfitWell/browser.js create mode 100644 integrations/ProfitWell/index.js diff --git a/integrations/ProfitWell/browser.js b/integrations/ProfitWell/browser.js new file mode 100644 index 0000000000..34d46b6555 --- /dev/null +++ b/integrations/ProfitWell/browser.js @@ -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; diff --git a/integrations/ProfitWell/index.js b/integrations/ProfitWell/index.js new file mode 100644 index 0000000000..6b7899971e --- /dev/null +++ b/integrations/ProfitWell/index.js @@ -0,0 +1,3 @@ +import ProfitWell from "./browser"; + +export default ProfitWell; diff --git a/integrations/client_server_name.js b/integrations/client_server_name.js index e5bd6da20f..fab45bc5c3 100644 --- a/integrations/client_server_name.js +++ b/integrations/client_server_name.js @@ -27,6 +27,7 @@ const clientToServerNames = { LYTICS: "Lytics", APPCUES: "Appcues", POSTHOG: "PostHog", + PROFITWELL: "ProfitWell", KLAVIYO: "Klaviyo", CLEVERTAP: "Clevertap", BINGADS: "BingAds", diff --git a/integrations/index.js b/integrations/index.js index 0e729da93e..79641c54ea 100644 --- a/integrations/index.js +++ b/integrations/index.js @@ -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)) @@ -81,6 +82,7 @@ const integrations = { MP: Mixpanel.default, QUALTRICS: Qualtrics.default, SNAP_PIXEL: SnapPixel.default, + PROFITWELL: ProfitWell.default, }; export { integrations }; diff --git a/integrations/integration_cname.js b/integrations/integration_cname.js index 4967bd3bbe..486eba2a00 100644 --- a/integrations/integration_cname.js +++ b/integrations/integration_cname.js @@ -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 };