Skip to content

Commit

Permalink
minor changes from review comment and formatting
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 3a85480 commit 214727b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 34 deletions.
4 changes: 0 additions & 4 deletions integrations/ScriptLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ 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
67 changes: 37 additions & 30 deletions integrations/TVSquared/browser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* eslint-disable camelcase */
/* eslint-disable no-underscore-dangle */
import ScriptLoader from "../ScriptLoader";
import logger from "../../utils/logUtil";

class TVSquared {
constructor(config) {
Expand All @@ -11,44 +14,47 @@ class 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 = window._tvq || [];
let 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(["setTrackerUrl", `&${url}tv2track.php`]);
ScriptLoader("TVSquared-integration", `${url}tv2track.js`);

window._tvq.push([
function () {
() => {
this.deleteCustomVariable(5, "page");
},
]);
}

isLoaded() {
isLoaded = () => {
logger.debug("in TVSqaured isLoaded");
return !!window_tvq;
}
return !!window._tvq;
};

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

return !!window_tvq;
}
return !!window._tvq;
};

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

track(rudderElement) {
const { event, userId, anonymousId } = rudderElement.message;
const {
revenue,
productType,
category,
order_id,
promotion_id,
} = rudderElement.message.properties;
let i, j;
var whitelist = eventWhiteList.slice();
let i;
let j;
let whitelist = this.eventWhiteList.slice();
whitelist = whitelist.filter((wl) => {
return wl.event !== "";
});
Expand All @@ -61,44 +67,45 @@ class TVSquared {
}
}

var session = { user: userId || anonymousId || "" };
var action = {
rev: this.formatRevenue(revenue) || "",
prod: productType || "",
const session = { user: userId || anonymousId || "" };
const action = {
rev: revenue ? this.formatRevenue(revenue) : "",
prod: category || productType || "",
id: order_id || "",
promo: promotion_id || "",
};
var customMetrics = this.customMetrics.slice();
let 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];
const key = customMetrics[j].propertyName;
const 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") {
if (event.toUpperCase() !== "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;
}
formatRevenue = (revenue) => {
let rev = revenue;
rev = parseFloat(rev.toString().replace(/^[^\d.]*/, ""));
return rev;
};
}
export { TVSquared };

0 comments on commit 214727b

Please sign in to comment.