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

feat(integration): add common util function for mapping event names in ads destinations #643

Merged
merged 10 commits into from
Sep 14, 2022
18 changes: 16 additions & 2 deletions integrations/GoogleAds/browser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/* eslint-disable class-methods-use-this */
import logger from "../../utils/logUtil";
import { LOAD_ORIGIN } from "../ScriptLoader";
import { removeUndefinedAndNullValues } from "../utils/commonUtils";
import {
getHashFromArray,
ItsSudip marked this conversation as resolved.
Show resolved Hide resolved
getHashFromArrayWithDuplicate,
removeUndefinedAndNullValues,
setEventMappingFromConfig,
} from "../utils/commonUtils";
import { NAME } from "./constants";

class GoogleAds {
Expand All @@ -16,6 +21,7 @@ class GoogleAds {
this.conversionLinker = config.conversionLinker || true;
this.disableAdPersonalization = config.disableAdPersonalization || false;
this.name = NAME;
this.eventsMap = config.eventsMap;
}

init() {
Expand Down Expand Up @@ -83,7 +89,15 @@ class GoogleAds {
window.gtag("event", eventName, properties);
}
} else {
const { event } = rudderElement.message;
let { event } = rudderElement.message;
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
// modify the event name to mapped event name from the config
const eventsHashmap = getHashFromArrayWithDuplicate(
this.eventsMap,
"from",
"to",
false
);
event = setEventMappingFromConfig(event, eventsHashmap);
if (!event) {
logger.error("Event name not present");
return;
Expand Down
70 changes: 46 additions & 24 deletions integrations/RedditPixel/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
import logger from "../../utils/logUtil";
import { LOAD_ORIGIN } from "../ScriptLoader";
import { NAME } from "./constants";
import {
getHashFromArray,
getHashFromArrayWithDuplicate,
setEventMappingFromConfig,
} from "../utils/commonUtils";

class RedditPixel {
constructor(config) {
this.advertiserId = config.advertiserId;
this.name = NAME;
this.eventMappingFromConfig = config.eventMappingFromConfig;
}

init() {
Expand All @@ -30,7 +36,7 @@ class RedditPixel {
p.callQueue = [];
var t = d.createElement("script");
(t.src = "https://www.redditstatic.com/ads/pixel.js"), (t.async = !0);
(t.setAttribute("data-loader", LOAD_ORIGIN));
t.setAttribute("data-loader", LOAD_ORIGIN);
var s = d.getElementsByTagName("script")[0];
s.parentNode.insertBefore(t, s);
}
Expand Down Expand Up @@ -62,29 +68,45 @@ class RedditPixel {
logger.error("Event name is not present");
return;
}

switch (event.toLowerCase()) {
case "product added":
window.rdt("track", "AddToCart");
break;
case "product added to wishlist":
window.rdt("track", "AddToWishlist");
break;
case "order completed":
window.rdt("track", "Purchase");
break;
case "lead":
window.rdt("track", "Lead");
break;
case "view content":
window.rdt("track", "ViewContent");
break;
case "search":
window.rdt("track", "Search");
break;
default:
logger.error(`Invalid event ${event}. Track call not supported`);
break;
const eventMappingFromConfigMap = getHashFromArrayWithDuplicate(
this.eventMappingFromConfig,
"from",
"to",
false
);
if (eventMappingFromConfigMap[event]) {
// mapping event from UI
const events = setEventMappingFromConfig(
event,
eventMappingFromConfigMap
);
events.forEach((ev) => {
window.rdt("track", events[ev]);
utsabc marked this conversation as resolved.
Show resolved Hide resolved
});
} else {
switch (event.toLowerCase()) {
case "product added":
window.rdt("track", "AddToCart");
break;
case "product added to wishlist":
window.rdt("track", "AddToWishlist");
break;
case "order completed":
window.rdt("track", "Purchase");
break;
case "lead":
window.rdt("track", "Lead");
break;
case "view content":
window.rdt("track", "ViewContent");
break;
case "search":
window.rdt("track", "Search");
break;
default:
logger.error(`Invalid event ${event}. Track call not supported`);
break;
}
}
}

Expand Down
Loading