Skip to content

Commit

Permalink
added review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchiramoitra committed Jun 15, 2020
1 parent 71b64dd commit 7abdbca
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 124 deletions.
54 changes: 1 addition & 53 deletions integrations/GA/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,8 @@ class GA {
pushEnhancedEcommerce(rudderElement, this.inputs);
break;
default:
var contextOpts; //need to implement
var interfaceOpts = this.inputs;
var opts = defaults(options || {}, contextOpts);
var opts = options || {};
opts = defaults(opts, interfaceOpts);

var eventCategory = rudderElement.message.properties.category;
Expand Down Expand Up @@ -903,55 +902,4 @@ function getProductPosition(item, products) {
);
}

// function rejectArr(obj, fn) {
// fn = fn || compact;
// return "array" == type(obj) ? rejectarray(obj, fn) : rejectobject(obj, fn);
// }

// var rejectarray = function (arr, fn) {
// var ret = [];

// for (var i = 0; i < arr.length; ++i) {
// if (!fn(arr[i], i)) ret[ret.length] = arr[i];
// }

// return ret;
// };

// var rejectobject = function (obj, fn) {
// var ret = {};

// for (var k in obj) {
// if (obj.hasOwnProperty(k) && !fn(obj[k], k)) {
// ret[k] = obj[k];
// }
// }

// return ret;
// };

// function compact(value) {
// return null == value;
// }

// function type(val) {
// switch (toString.call(val)) {
// case "[object Function]":
// return "function";
// case "[object Date]":
// return "date";
// case "[object RegExp]":
// return "regexp";
// case "[object Arguments]":
// return "arguments";
// case "[object Array]":
// return "array";
// }

// if (val === null) return "null";
// if (val === undefined) return "undefined";
// if (val === Object(val)) return "object";

// return typeof val;
// }
export { GA };
175 changes: 104 additions & 71 deletions utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//import * as XMLHttpRequestNode from "Xmlhttprequest";
import logger from "./logUtil";
import {commonNames} from "../integrations/integration_cname"
import {clientToServerNames} from "../integrations/client_server_name"
import { commonNames } from "../integrations/integration_cname";
import { clientToServerNames } from "../integrations/client_server_name";

let XMLHttpRequestNode;
if (!process.browser) {
Expand Down Expand Up @@ -42,7 +42,7 @@ function generateUUID() {
) {
d += performance.now(); //use high-precision timer if available
}
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
let r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
Expand Down Expand Up @@ -84,7 +84,7 @@ function getJSON(url, wrappers, isLoaded, callback) {
var xhr = new XMLHttpRequestNode.XMLHttpRequest();
}
xhr.open("GET", url, false);
xhr.onload = function() {
xhr.onload = function () {
let status = xhr.status;
if (status == 200) {
logger.debug("status 200");
Expand Down Expand Up @@ -119,7 +119,7 @@ function getJSONTrimmed(context, url, writeKey, callback) {
xhr.setRequestHeader("Authorization", "Basic " + btoaNode(writeKey + ":"));
}

xhr.onload = function() {
xhr.onload = function () {
let status = xhr.status;
if (status == 200) {
logger.debug("status 200 " + "calling callback");
Expand All @@ -138,24 +138,32 @@ function getJSONTrimmed(context, url, writeKey, callback) {

function handleError(error, analyticsInstance) {
let errorMessage = error.message ? error.message : undefined;
let sampleAdBlockTest = undefined
let sampleAdBlockTest = undefined;
try {
if (error instanceof Event) {
if (error.target && error.target.localName == "script") {
errorMessage = "error in script loading:: src:: " + error.target.src + " id:: " + error.target.id;
if(analyticsInstance && error.target.src.includes("adsbygoogle")) {
sampleAdBlockTest = true
analyticsInstance.page("RudderJS-Initiated", "ad-block page request", {path: "/ad-blocked", title: errorMessage}, analyticsInstance.sendAdblockPageOptions)
errorMessage =
"error in script loading:: src:: " +
error.target.src +
" id:: " +
error.target.id;
if (analyticsInstance && error.target.src.includes("adsbygoogle")) {
sampleAdBlockTest = true;
analyticsInstance.page(
"RudderJS-Initiated",
"ad-block page request",
{ path: "/ad-blocked", title: errorMessage },
analyticsInstance.sendAdblockPageOptions
);
}
}
}
if (errorMessage && !sampleAdBlockTest) {
logger.error("[Util] handleError:: ", errorMessage);
}
} catch (e) {
logger.error("[Util] handleError:: ", e)
logger.error("[Util] handleError:: ", e);
}

}

function getDefaultPageProperties() {
Expand All @@ -171,7 +179,7 @@ function getDefaultPageProperties() {
referrer: referrer,
search: search,
title: title,
url: url
url: url,
};
}

Expand Down Expand Up @@ -230,108 +238,130 @@ function getRevenue(properties, eventName) {
* @param {*} integrationObject
*/
function tranformToRudderNames(integrationObject) {
Object.keys(integrationObject).forEach(key => {
if(integrationObject.hasOwnProperty(key)) {
if(commonNames[key]) {
integrationObject[commonNames[key]] = integrationObject[key]
Object.keys(integrationObject).forEach((key) => {
if (integrationObject.hasOwnProperty(key)) {
if (commonNames[key]) {
integrationObject[commonNames[key]] = integrationObject[key];
}
if(key != "All") {
// delete user supplied keys except All and if except those where oldkeys are not present or oldkeys are same as transformed keys
if(commonNames[key] != undefined && commonNames[key] != key) {
delete integrationObject[key]
if (key != "All") {
// delete user supplied keys except All and if except those where oldkeys are not present or oldkeys are same as transformed keys
if (commonNames[key] != undefined && commonNames[key] != key) {
delete integrationObject[key];
}
}

}
})
});
}

function transformToServerNames(integrationObject) {
Object.keys(integrationObject).forEach(key => {
if(integrationObject.hasOwnProperty(key)) {
if(clientToServerNames[key]) {
integrationObject[clientToServerNames[key]] = integrationObject[key]
Object.keys(integrationObject).forEach((key) => {
if (integrationObject.hasOwnProperty(key)) {
if (clientToServerNames[key]) {
integrationObject[clientToServerNames[key]] = integrationObject[key];
}
if(key != "All") {
// delete user supplied keys except All and if except those where oldkeys are not present or oldkeys are same as transformed keys
if(clientToServerNames[key] != undefined && clientToServerNames[key] != key) {
delete integrationObject[key]
if (key != "All") {
// delete user supplied keys except All and if except those where oldkeys are not present or oldkeys are same as transformed keys
if (
clientToServerNames[key] != undefined &&
clientToServerNames[key] != key
) {
delete integrationObject[key];
}
}

}
})
});
}

/**
*
* @param {*} sdkSuppliedIntegrations
* @param {*} configPlaneEnabledIntegrations
*
* @param {*} sdkSuppliedIntegrations
* @param {*} configPlaneEnabledIntegrations
*/
function findAllEnabledDestinations(sdkSuppliedIntegrations, configPlaneEnabledIntegrations) {
let enabledList = []
if(!configPlaneEnabledIntegrations || configPlaneEnabledIntegrations.length == 0) {
return enabledList
function findAllEnabledDestinations(
sdkSuppliedIntegrations,
configPlaneEnabledIntegrations
) {
let enabledList = [];
if (
!configPlaneEnabledIntegrations ||
configPlaneEnabledIntegrations.length == 0
) {
return enabledList;
}
let allValue = true
if(typeof configPlaneEnabledIntegrations[0] == "string") {
if(sdkSuppliedIntegrations["All"] != undefined) {
allValue = sdkSuppliedIntegrations["All"]
let allValue = true;
if (typeof configPlaneEnabledIntegrations[0] == "string") {
if (sdkSuppliedIntegrations["All"] != undefined) {
allValue = sdkSuppliedIntegrations["All"];
}
configPlaneEnabledIntegrations.forEach(intg => {
if(!allValue) {
configPlaneEnabledIntegrations.forEach((intg) => {
if (!allValue) {
// All false ==> check if intg true supplied
if(sdkSuppliedIntegrations[intg]!= undefined && sdkSuppliedIntegrations[intg] == true) {
enabledList.push(intg)
if (
sdkSuppliedIntegrations[intg] != undefined &&
sdkSuppliedIntegrations[intg] == true
) {
enabledList.push(intg);
}
} else {
// All true ==> intg true by default
let intgValue = true
let intgValue = true;
// check if intg false supplied
if(sdkSuppliedIntegrations[intg] != undefined && sdkSuppliedIntegrations[intg] == false) {
intgValue = false
if (
sdkSuppliedIntegrations[intg] != undefined &&
sdkSuppliedIntegrations[intg] == false
) {
intgValue = false;
}
if(intgValue) {
enabledList.push(intg)
if (intgValue) {
enabledList.push(intg);
}
}
})
});

return enabledList
return enabledList;
}

if(typeof configPlaneEnabledIntegrations[0] == "object") {
if(sdkSuppliedIntegrations["All"] != undefined) {
allValue = sdkSuppliedIntegrations["All"]
if (typeof configPlaneEnabledIntegrations[0] == "object") {
if (sdkSuppliedIntegrations["All"] != undefined) {
allValue = sdkSuppliedIntegrations["All"];
}
configPlaneEnabledIntegrations.forEach(intg => {
if(!allValue) {
configPlaneEnabledIntegrations.forEach((intg) => {
if (!allValue) {
// All false ==> check if intg true supplied
if(sdkSuppliedIntegrations[intg.name]!= undefined && sdkSuppliedIntegrations[intg.name] == true) {
enabledList.push(intg)
if (
sdkSuppliedIntegrations[intg.name] != undefined &&
sdkSuppliedIntegrations[intg.name] == true
) {
enabledList.push(intg);
}
} else {
// All true ==> intg true by default
let intgValue = true
let intgValue = true;
// check if intg false supplied
if(sdkSuppliedIntegrations[intg.name] != undefined && sdkSuppliedIntegrations[intg.name] == false) {
intgValue = false
if (
sdkSuppliedIntegrations[intg.name] != undefined &&
sdkSuppliedIntegrations[intg.name] == false
) {
intgValue = false;
}
if(intgValue) {
enabledList.push(intg)
if (intgValue) {
enabledList.push(intg);
}
}
})
});

return enabledList
return enabledList;
}

}

//reject all null values from array/object

function rejectArr(obj, fn) {
fn = fn || compact;
return "array" == type(obj) ? rejectarray(obj, fn) : rejectobject(obj, fn);
}

//particular case when rejecting an array
var rejectarray = function (arr, fn) {
var ret = [];

Expand All @@ -342,6 +372,8 @@ var rejectarray = function (arr, fn) {
return ret;
};

//when any other object is needed to be rejected

var rejectobject = function (obj, fn) {
var ret = {};

Expand All @@ -358,6 +390,7 @@ function compact(value) {
return null == value;
}

//check type of object incoming in the rejectArr function
function type(val) {
switch (toString.call(val)) {
case "[object Function]":
Expand Down Expand Up @@ -391,5 +424,5 @@ export {
tranformToRudderNames,
transformToServerNames,
handleError,
rejectArr
rejectArr,
};

0 comments on commit 7abdbca

Please sign in to comment.