Skip to content

Commit

Permalink
added tvsquared as destination
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchiramoitra authored and arnab-p committed Sep 10, 2020
1 parent 5c63766 commit 3a85480
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 0 deletions.
4 changes: 4 additions & 0 deletions integrations/ScriptLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ const ScriptLoader = (id, src) => {
js.src = src;
js.async = true;
js.type = "text/javascript";
if(id === "TVSquared-integration"){
js.defer = true;
}
js.id = id;
const e = document.getElementsByTagName("script")[0];
logger.debug("==script==", e);
console.log("==script==", e)
e.parentNode.insertBefore(js, e);
};

Expand Down
104 changes: 104 additions & 0 deletions integrations/TVSquared/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import ScriptLoader from "../ScriptLoader";

class TVSquared {
constructor(config) {
this.brandId = config.brandId;
this.clientId = config.clientId;
this.eventWhiteList = config.eventWhiteList || [];
this.customMetrics = config.customMetrics || [];
this.name = "TVSquared";
}

init() {
logger.debug("===in init TVSquared===");
window._tvq = window._tvq = [];
var url = document.location.protocol == "https:" ? "https://" : "http://";
url += "collector-" + this.clientId + ".tvsquared.com/";
window._tvq.push(["setSiteId", this.brandId]);
window._tvq.push(["setTrackerUrl", url + "tv2track.php"]);
ScriptLoader("TVSquared-integration", url + "tv2track.js");
window._tvq.push([
function () {
this.deleteCustomVariable(5, "page");
},
]);
}

isLoaded() {
logger.debug("in TVSqaured isLoaded");
return !!window_tvq;
}

isReady() {
logger.debug("in TVSqaured isReady");

return !!window_tvq;
}

page() {
window._tvq.push(["trackPageView"]);
}

track(rudderElement) {
const { event, userId, anonymousId } = rudderElement.message;
const {
revenue,
productType,
order_id,
promotion_id,
} = rudderElement.message.properties;
let i, j;
var whitelist = eventWhiteList.slice();
whitelist = whitelist.filter((wl) => {
return wl.event !== "";
});
for (i = 0; i < whitelist.length; i += 1) {
if (event.toUpperCase() === whitelist[i].event.toUpperCase()) {
break;
}
if (i === whitelist.length - 1) {
return;
}
}

var session = { user: userId || anonymousId || "" };
var action = {
rev: this.formatRevenue(revenue) || "",
prod: productType || "",
id: order_id || "",
promo: promotion_id || "",
};
var customMetrics = this.customMetrics.slice();
customMetrics = customMetrics.filter((cm) => {
return cm.propertyName !== "";
});
if (customMetrics.length) {
for (j = 0; j < customMetrics.length; j += 1) {
var key = customMetrics[j].propertyName;
var value = rudderElement.message.properties[key];
if (value) {
action[key] = value;
}
}
}
window._tvq.push([
function () {
this.setCustomVariable(5, "session", JSON.stringify(session), "visit");
},
]);
if (event !== "Response") {
window._tvq.push([
function () {
this.setCustomVariable(5, event, JSON.stringify(action), "page");
},
]);
window._tvq.push(["trackPageView"]);
}
}

formatRevenue(revenue) {
revenue = parseFloat(revenue.replace(/^[^\d\.]*/, ""));
return revenue;
}
}
export { TVSquared };
3 changes: 3 additions & 0 deletions integrations/TVSquared/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { TVSquared } from "./browser";

export default TVSquared;
1 change: 1 addition & 0 deletions integrations/client_server_name.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const clientToServerNames = {
VWO: "VWO",
OPTIMIZELY: "Optimizely",
FULLSTORY: "Fullstory",
TVSQUUARED: "TVSquared"
};

export { clientToServerNames };
2 changes: 2 additions & 0 deletions integrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as Lotame from "./Lotame";
import * as Optimizely from "./Optimizely";
import * as Bugsnag from "./Bugsnag";
import * as Fullstory from "./Fullstory";
import * as TVSquared from "./TVSquared";

// 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 All @@ -39,6 +40,7 @@ const integrations = {
OPTIMIZELY: Optimizely.default,
BUGSNAG: Bugsnag.default,
FULLSTORY: Fullstory.default,
TVSQUARED: TVSquared.default,
};

export { integrations };
1 change: 1 addition & 0 deletions integrations/integration_cname.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const commonNames = {
FULLSTORY: "FULLSTORY",
Fullstory: "FULLSTORY",
BUGSNAG: "BUGSNAG",
TVSQUARED: "TVSQUARED",
};

export { commonNames };

0 comments on commit 3a85480

Please sign in to comment.