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(Vero-web-device-mode): new Integrations Vero web device mode #549

Merged
merged 16 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
18e82a3
feature[Vero-web-device-mode]: initial commit
sauravlal-rudderstack Jun 28, 2022
a114c0e
feature[Vero-web-device-mode]: build identify, track, alias call
sauravlal-rudderstack Jun 29, 2022
2620503
feature[vero]: Updating the init function
ItsSudip Jun 30, 2022
3f77a8d
feature[Vero-web-device-mode]: rebuild identify, track, alias call
sauravlal-rudderstack Jul 4, 2022
d84c97d
feature[Vero-web-device-mode]: reformat identify
sauravlal-rudderstack Jul 4, 2022
7c9ecec
feature[Vero-web-device-mode]: remove email from userId
sauravlal-rudderstack Jul 4, 2022
7e9a7d7
feature[Vero-web-device-mode]: update event name in page
sauravlal-rudderstack Jul 4, 2022
7487eb5
feature[Vero-web-device-mode]: reformat tags
sauravlal-rudderstack Jul 5, 2022
625caf4
feature[Vero-web-device-mode]: reformat tags with []
sauravlal-rudderstack Jul 5, 2022
8e1d842
feature[Vero-web-device-mode]: deepcopy in page call
sauravlal-rudderstack Jul 5, 2022
e2d64fb
feature[Vero-web-device-mode]: remove get function
sauravlal-rudderstack Jul 5, 2022
1345fce
feature[Vero-web-device-mode]: update ready and loaded function
sauravlal-rudderstack Jul 5, 2022
3d67ad6
feature[Vero-web-device-mode]: update ready and loaded
sauravlal-rudderstack Jul 5, 2022
01d0e86
feature[vero]: Updating addOrRemove function.
ItsSudip Jul 6, 2022
1c8923c
feature[vero]: removing optional chaining from addOrRemoveTags
ItsSudip Jul 6, 2022
18f5a02
feature[Vero-web-device-mode]: update addOrRemoveTags
sauravlal-rudderstack Jul 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions integrations/Vero/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/* eslint-disable no-underscore-dangle */
/* eslint-disable class-methods-use-this */
import { NAME, CNameMapping } from "./constants";
import logger from "../../utils/logUtil";
import { isDefinedAndNotNull } from "../utils/commonUtils";
import ScriptLoader from "../ScriptLoader";

class Vero {
constructor(config) {
this.apiKey = config.apiKey;
this.name = NAME;
}

init() {
logger.debug("===In init Vero===");
window._veroq = window._veroq || [];
ScriptLoader(
"vero-integration",
"https://d3qxef4rp70elm.cloudfront.net/m.js"
);
window._veroq.push(["init", { api_key: this.apiKey }]);
}

isLoaded() {
logger.debug("===In isLoaded Vero===");
return !!window._veroq && typeof window._veroq === "object";
}

isReady() {
logger.debug("===In isReady Vero===");
return !!window._veroq && !!window._veroq.ready;
}

/**
* AddOrRemoveTags.
* This block handles any tag addition or removal requests.
* Ref - http://developers.getvero.com/?javascript#tags
*
* @param {Object} tags
*/
addOrRemoveTags(message) {
let name;
const keys = Object.keys(message.integrations);
utsabc marked this conversation as resolved.
Show resolved Hide resolved
for (let i = 0; i < keys.length; i += 1) {
if (CNameMapping.indexOf(keys[i]) > -1) {
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
name = keys[i];
break;
}
}
if (name) {
const tags = message.integrations?.[name]?.tags;
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
if (isDefinedAndNotNull(tags)) {
const userId = message.userId || message.anonymousId;
const addTags = Array.isArray(tags.add) ? tags.add : [];
const removeTags = Array.isArray(tags.remove) ? tags.remove : [];
window._veroq.push([
"tags",
{
id: userId,
add: addTags,
remove: removeTags,
},
]);
}
}
}

/**
* Identify.
* Ref - https://developers.getvero.com/?javascript#users-identify
*
* @param {Identify} identify
*/
identify(rudderElement) {
const { message } = rudderElement;
const { traits } = message.context || message;
const userId = message.userId || message.anonymousId;
let payload = traits;
if (userId) {
payload = { id: userId, ...payload };
}
window._veroq.push(["user", payload]);
this.addOrRemoveTags(message);
}
utsabc marked this conversation as resolved.
Show resolved Hide resolved

/**
* Track - tracks an event for a specific user
* for event `unsubscribe`
* Ref - https://developers.getvero.com/?javascript#users-unsubscribe
* for event `resubscribe`
* Ref - https://developers.getvero.com/?javascript#users-resubscribe
* else
* Ref - https://developers.getvero.com/?javascript#events-track
*
* @param {Track} track
*/
track(rudderElement) {
logger.debug("=== In Vero track ===");

const { message } = rudderElement;
const { event, properties } = message;
ItsSudip marked this conversation as resolved.
Show resolved Hide resolved
if (!event) {
logger.error("[Vero]: Event name from track call is missing!!===");
return;
}
const userId = message.userId || message.anonymousId;
switch (event.toLowerCase()) {
case "unsubscribe":
window._veroq.push(["unsubscribe", userId]);
break;
case "resubscribe":
window._veroq.push(["resubscribe", userId]);
break;
default:
window._veroq.push(["track", event, properties]);
}
this.addOrRemoveTags(message);
}

/**
* Page.
*
* @param {Page} page
*/
page(rudderElement) {
logger.debug("=== In Vero Page ===");
const { name, category } = rudderElement.message;
let eventName;
if (!name && !category) {
eventName = `Viewed Page`;
} else if (!name && category) {
eventName = `Viewed ${category} Page`;
} else if (name && !category) {
eventName = `Viewed ${name} Page`;
} else {
eventName = `Viewed ${category} ${name} Page`;
}
const elemClone = { ...rudderElement };
elemClone.message = { ...rudderElement.message };
elemClone.message.event = eventName;
this.track(elemClone);
}

/**
* Alias.
* Ref - https://www.getvero.com/api/http/#users
*
* @param {Alias} alias
*/
alias(rudderElement) {
const { message } = rudderElement;
const { userId, previousId } = message;
if (!previousId) {
logger.error("===Vero: previousId is required for alias call===");
return;
}
if (!userId) {
logger.error("===Vero: userId is required for alias call===");
return;
}
window._veroq.push(["reidentify", userId, previousId]);
this.addOrRemoveTags(message);
}
}

export default Vero;
4 changes: 4 additions & 0 deletions integrations/Vero/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const NAME = "VERO";
const CNameMapping = [NAME, "Vero", "vero"];

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

export default Vero;
1 change: 1 addition & 0 deletions integrations/client_server_name.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const clientToServerNames = {
LAUNCHDARKLY: "LaunchDarkly",
GA360: "Google Analytics 360",
ADROLL: "Adroll",
VERO: "Vero"
};

export { clientToServerNames };
2 changes: 2 additions & 0 deletions integrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import * as LaunchDarkly from "./LaunchDarkly";
import * as GA360 from "./GA360";
import * as DCMFloodlight from "./DCMFloodlight";
import * as Adroll from "./Adroll";
import * as Vero from "./Vero";

// 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 @@ -99,6 +100,7 @@ const integrations = {
LAUNCHDARKLY: LaunchDarkly.default,
GA360: GA360.default,
ADROLL: Adroll.default,
VERO: Vero.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 @@ -46,6 +46,7 @@ import { CNameMapping as VWO } from "./VWO/constants";
import { CNameMapping as GA360 } from "./GA360/constants";
import { CNameMapping as DCMFloodlight } from "./DCMFloodlight/constants";
import { CNameMapping as Adroll } from "./Adroll/constants";
import { CNameMapping as Vero } from "./Vero/constants";

// for sdk side native integration identification
// add a mapping from common names to index.js exported key names as identified by Rudder
Expand Down Expand Up @@ -98,6 +99,7 @@ const commonNames = {
...Sentry,
...SnapPixel,
...TVSquared,
...Vero,
...VWO,
};

Expand Down