Skip to content

Commit

Permalink
feature(ConvertFlow): updating event and data
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwal-ab committed Aug 17, 2022
1 parent 70e2abc commit 8e30f19
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
3 changes: 2 additions & 1 deletion integrations/ConvertFlow/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { NAME } from "./constants";
import logger from "../../utils/logUtil";
import ScriptLoader from "../ScriptLoader";
import { trigger } from "./utils";

class ConvertFlow {
constructor(config) {
Expand All @@ -24,7 +25,7 @@ class ConvertFlow {
isLoaded() {
logger.debug("===In isLoaded convertflow===");
if (this.toggleToSendData) {
this.trigger();
trigger(this.eventsMappping, this.eventsList);
}
return !!window.convertflow && typeof window.convertflow === "object";
}
Expand Down
28 changes: 19 additions & 9 deletions integrations/ConvertFlow/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@ const standardEventsListMapping = {
};

/**
* This function is used to make a track Call to rudderstack.
* This function is used to trigger a callback.
* @param {*} standardEventsMap - mapping of events done by the user
* @param {*} eventName - standard event name
* @param {*} data
*/
const makeACall = (standardEventsMap, eventName, data) => {
// stroring all the supported standard event names
const eventNames = Object.keys(standardEventsMap);
// stroing default event name in the updatedEvent
let updatedEvent = standardEventsListMapping[eventName];
// Updating the event name with any mapping from the webapp
eventNames.forEach((event) => {
if (standardEventsMap[event].includes(eventName)) {
if (standardEventsMap[event] === eventName) {
updatedEvent = event;
}
});
// Populating Properties
const properties = {};
if (data) {
if (data.cta) {
Expand All @@ -37,10 +41,10 @@ const makeACall = (standardEventsMap, eventName, data) => {
properties.cta_id = cta.id;
}
if (data.variant) {
properties.cta_variant = data.variant.variation;
properties.cta_variant = data.variant;
}
if (data.step) {
properties.cta_step = data.step.position;
properties.cta_step = data.step;
}
}
if (isDefinedAndNotNullAndNotEmpty(properties)) {
Expand All @@ -50,8 +54,14 @@ const makeACall = (standardEventsMap, eventName, data) => {
}
};

const trigger = () => {
const standardEventsMap = getHashFromArray(this.eventsMappping);
/**
* This function has event listners for the occuring events and to make a call for the event after
* collecting the data.
* @param {*} eventsMappping - Mapping of events in the webapp by the user
* @param {*} eventsList - List of requested events by the user.
*/
const trigger = (eventsMappping, eventsList) => {
const standardEventsMap = getHashFromArray(eventsMappping);
const standardEventsList = [
"cfReady",
"cfView",
Expand All @@ -62,9 +72,9 @@ const trigger = () => {
"cfClosed",
];
standardEventsList.forEach((events) => {
window.addEventListener(events, function (event, data) {
if (this.eventsList === event) {
makeACall(standardEventsMap, event, data);
window.addEventListener(events, function (event) {
if (eventsList.includes(event.type)) {
makeACall(standardEventsMap, event.type, event.detail);
}
});
});
Expand Down

0 comments on commit 8e30f19

Please sign in to comment.