Skip to content

Commit

Permalink
adding server identifiable names
Browse files Browse the repository at this point in the history
  • Loading branch information
sayan-rudder committed May 14, 2020
1 parent 694d3bc commit 3dbe7ea
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 6 deletions.
6 changes: 5 additions & 1 deletion analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
handleError,
getDefaultPageProperties,
findAllEnabledDestinations,
tranformToRudderNames
tranformToRudderNames,
transformToServerNames
} from "./utils/utils";
import {
CONFIG_URL,
Expand Down Expand Up @@ -620,6 +621,9 @@ class Analytics {
this.toBeProcessedByIntegrationArray.push([type, rudderElement]);
}

// convert integrations object to server identified names, kind of hack now!
transformToServerNames(rudderElement.message.integrations)

// self analytics process, send to rudder
enqueue.call(this, rudderElement, type);

Expand Down
43 changes: 41 additions & 2 deletions dist/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ var rudderanalytics = (function (exports) {
}
};

// for sdk side native integration identification
var commonNames = {
"All": "All",
"Google Analytics": "GA",
Expand Down Expand Up @@ -196,6 +197,25 @@ var rudderanalytics = (function (exports) {
"VWO": "VWO"
};

var clientToServerNames = {
"All": "All",
"GA": "Google Analytics",
"GOOGLEADS": "Google Ads",
"BRAZE": "Braze",
"Chartbeat": "Chartbeat",
"COMSCORE": "Comscore",
"CUSTOMERIO": "Customer IO",
"FB_PIXEL": "Facebook Pixel",
"GOOGLETAGMANAGER": "Google Tag Manager",
"HOTJAR": "Hotjar",
"HS": "HubSpot",
"INTERCOM": "Intercom",
"KEEN": "Keen",
"KISSMETRICS": "Kiss Metrics",
"LOTAME": "Lotame",
"VWO": "VWO"
};

/**
*
* Utility method for excluding null and empty values in JSON
Expand Down Expand Up @@ -384,14 +404,31 @@ var rudderanalytics = (function (exports) {
}

if (key != "All") {
// delete user supplied keys except All and if except those where oldkeys are same as transformed keys
// 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(function (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];
}
}
}
});
}
/**
*
* @param {*} sdkSuppliedIntegrations
Expand Down Expand Up @@ -10973,8 +11010,10 @@ var rudderanalytics = (function (exports) {
logger.debug("pushing in replay queue"); //new event processing after analytics initialized but integrations not fetched from BE

this.toBeProcessedByIntegrationArray.push([type, rudderElement]);
} // self analytics process, send to rudder
} // convert integrations object to server identified names, kind of hack now!


transformToServerNames(rudderElement.message.integrations); // self analytics process, send to rudder

enqueue.call(this, rudderElement, type);
logger.debug(type + " is called ");
Expand Down
2 changes: 1 addition & 1 deletion dist/rudder-analytics.min.js

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions integrations/client_server_name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// from client native integration name to server identified display name
let clientToServerNames = {
"All": "All",
"GA": "Google Analytics",
"GOOGLEADS": "Google Ads",
"BRAZE": "Braze",
"Chartbeat": "Chartbeat",
"COMSCORE": "Comscore",
"CUSTOMERIO": "Customer IO",
"FB_PIXEL": "Facebook Pixel",
"GOOGLETAGMANAGER": "Google Tag Manager",
"HOTJAR": "Hotjar",
"HS": "HubSpot",
"INTERCOM": "Intercom",
"KEEN": "Keen",
"KISSMETRICS": "Kiss Metrics",
"LOTAME": "Lotame",
"VWO": "VWO"
}

export {clientToServerNames}
1 change: 1 addition & 0 deletions integrations/integration_cname.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// for sdk side native integration identification
let commonNames = {
"All": "All",
"Google Analytics": "GA",
Expand Down
43 changes: 41 additions & 2 deletions tests/html/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ var rudderanalytics = (function (exports) {
}
};

// for sdk side native integration identification
var commonNames = {
"All": "All",
"Google Analytics": "GA",
Expand Down Expand Up @@ -196,6 +197,25 @@ var rudderanalytics = (function (exports) {
"VWO": "VWO"
};

var clientToServerNames = {
"All": "All",
"GA": "Google Analytics",
"GOOGLEADS": "Google Ads",
"BRAZE": "Braze",
"Chartbeat": "Chartbeat",
"COMSCORE": "Comscore",
"CUSTOMERIO": "Customer IO",
"FB_PIXEL": "Facebook Pixel",
"GOOGLETAGMANAGER": "Google Tag Manager",
"HOTJAR": "Hotjar",
"HS": "HubSpot",
"INTERCOM": "Intercom",
"KEEN": "Keen",
"KISSMETRICS": "Kiss Metrics",
"LOTAME": "Lotame",
"VWO": "VWO"
};

/**
*
* Utility method for excluding null and empty values in JSON
Expand Down Expand Up @@ -384,14 +404,31 @@ var rudderanalytics = (function (exports) {
}

if (key != "All") {
// delete user supplied keys except All and if except those where oldkeys are same as transformed keys
// 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(function (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];
}
}
}
});
}
/**
*
* @param {*} sdkSuppliedIntegrations
Expand Down Expand Up @@ -10973,8 +11010,10 @@ var rudderanalytics = (function (exports) {
logger.debug("pushing in replay queue"); //new event processing after analytics initialized but integrations not fetched from BE

this.toBeProcessedByIntegrationArray.push([type, rudderElement]);
} // self analytics process, send to rudder
} // convert integrations object to server identified names, kind of hack now!


transformToServerNames(rudderElement.message.integrations); // self analytics process, send to rudder

enqueue.call(this, rudderElement, type);
logger.debug(type + " is called ");
Expand Down
19 changes: 19 additions & 0 deletions utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//import * as XMLHttpRequestNode from "Xmlhttprequest";
import logger from "./logUtil";
import {commonNames} from "../integrations/integration_cname"
import {clientToServerNames} from "../integrations/client_server_name"

let XMLHttpRequestNode;
if (!process.browser) {
Expand Down Expand Up @@ -235,6 +236,23 @@ function tranformToRudderNames(integrationObject) {
})
}

function transformToServerNames(integrationObject) {
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]
}
}

}
})
}

/**
*
* @param {*} sdkSuppliedIntegrations
Expand Down Expand Up @@ -310,5 +328,6 @@ export {
getDefaultPageProperties,
findAllEnabledDestinations,
tranformToRudderNames,
transformToServerNames,
handleError
};

0 comments on commit 3dbe7ea

Please sign in to comment.