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

feature/new integration: Convertflow onboarding #611

Merged
merged 10 commits into from
Aug 18, 2022
50 changes: 50 additions & 0 deletions integrations/ConvertFlow/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* eslint-disable no-underscore-dangle */
/* eslint-disable class-methods-use-this */
import { NAME } from "./constants";
import logger from "../../utils/logUtil";
import ScriptLoader from "../ScriptLoader";

class ConvertFlow {
constructor(config) {
this.websiteId = config.websiteId;
this.toggleToSendData = config.toggleToSendData;
this.eventsList = config.eventsList;
this.eventsMappping = config.eventsMappping;
this.name = NAME;
}

init() {
logger.debug("===In init convertflow===");
ScriptLoader(
"convertflow-integration",
`https://js.convertflow.co/production/websites/${this.websiteId}.js`
);
}

isLoaded() {
logger.debug("===In isLoaded convertflow===");
if (this.toggleToSendData) {
this.trigger();
}
return !!window.convertflow && typeof window.convertflow === "object";
}

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

// identify call to Convertflow
identify(rudderElement) {
logger.debug("===In convertflow Identify===");
const { message } = rudderElement;
const email = message.context.traits?.email || message.traits?.email;
if (!email) {
logger.error("email is rquired for identify call");
}
ItsSudip marked this conversation as resolved.
Show resolved Hide resolved
const payload = { email, override: true };
window.convertflow.identify(payload);
}
}

export default ConvertFlow;
10 changes: 10 additions & 0 deletions integrations/ConvertFlow/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const NAME = "CONVERTFLOW";
const CNameMapping = {
[NAME]: NAME,
Convertflow: NAME,
convertflow: NAME,
convertFlow: NAME,
ConvertFlow: NAME,
};

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

export default ConvertFlow;
73 changes: 73 additions & 0 deletions integrations/ConvertFlow/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {
getHashFromArray,
isDefinedAndNotNullAndNotEmpty,
} from "../utils/commonUtils";

// default mapping for the events
const standardEventsListMapping = {
cfReady: "CTA Ready",
cfView: "CTA Viewed",
cfConversion: "CTA Converted",
cfCompletion: "CTA Completed",
cfSubmit: "CTA Form Submitted",
cfAddToCart: "Product Added to Cart",
cfClosed: "CTA Closed",
};

/**
* This function is used to make a track Call to rudderstack.
* @param {*} standardEventsMap - mapping of events done by the user
* @param {*} eventName - standard event name
* @param {*} data
*/
const makeACall = (standardEventsMap, eventName, data) => {
const eventNames = Object.keys(standardEventsMap);
let updatedEvent = standardEventsListMapping[eventName];
eventNames.forEach((event) => {
ItsSudip marked this conversation as resolved.
Show resolved Hide resolved
if (standardEventsMap[event].includes(eventName)) {
ItsSudip marked this conversation as resolved.
Show resolved Hide resolved
updatedEvent = event;
}
});
const properties = {};
if (data) {
if (data.cta) {
const { cta } = data;
properties.cta_name = cta.name;
properties.cta_type = cta.cta_type;
properties.cta_id = cta.id;
}
if (data.variant) {
properties.cta_variant = data.variant.variation;
}
if (data.step) {
properties.cta_step = data.step.position;
}
}
if (isDefinedAndNotNullAndNotEmpty(properties)) {
window.rudderanalytics.track(updatedEvent, properties);
} else {
window.rudderanalytics.track(updatedEvent);
}
};

const trigger = () => {
const standardEventsMap = getHashFromArray(this.eventsMappping);
const standardEventsList = [
"cfReady",
"cfView",
"cfConversion",
"cfCompletion",
"cfSubmit",
"cfAddToCart",
"cfClosed",
];
standardEventsList.forEach((events) => {
window.addEventListener(events, function (event, data) {
if (this.eventsList === event) {
makeACall(standardEventsMap, event, data);
}
});
});
ItsSudip marked this conversation as resolved.
Show resolved Hide resolved
};

export { makeACall, trigger };
1 change: 1 addition & 0 deletions integrations/client_server_name.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const clientToServerNames = {
MATOMO: "Matomo",
ROCKERBOX: "Rockerbox",
MOUSEFLOW: "Mouseflow",
CONVERTFLOW: "ConvertFlow",
};

export { clientToServerNames };
2 changes: 2 additions & 0 deletions integrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import * as Vero from "./Vero";
import * as Matomo from "./Matomo";
import * as Rockerbox from "./Rockerbox";
import * as Mouseflow from "./Mouseflow";
import * as ConvertFlow from "./ConvertFlow";

// 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 @@ -107,6 +108,7 @@ const integrations = {
MATOMO: Matomo.default,
ROCKERBOX: Rockerbox.default,
MOUSEFLOW: Mouseflow.default,
CONVERTFLOW: ConvertFlow.default,
};

export { integrations };
2 changes: 2 additions & 0 deletions integrations/integration_cname.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { CNameMapping as Vero } from "./Vero/constants";
import { CNameMapping as Matomo } from "./Matomo/constants";
import { CNameMapping as Rockerbox } from "./Rockerbox/constants";
import { CNameMapping as Mouseflow } from "./Mouseflow/constants";
import { CNameMapping as ConvertFlow } from "./ConvertFlow/constants";

// for sdk side native integration identification
// add a mapping from common names to index.js exported key names as identified by Rudder
Expand All @@ -65,6 +66,7 @@ const commonNames = {
...Chartbeat,
...Clevertap,
...Comscore,
...ConvertFlow,
...Criteo,
...CustomerIO,
...DCMFloodlight,
Expand Down