Skip to content

Commit

Permalink
adding xmlhttp as external and other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sayan-rudder committed Oct 1, 2019
1 parent 61a59fa commit dc0a3e1
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion rudder-client-javascript/analytics/dist/browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rudder-client-javascript/analytics/dist/node.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions rudder-client-javascript/analytics/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions rudder-client-javascript/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
"main": "./dist/browser.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"buildDev": "uglify=\"false\" rollup -c",
"buildProd": "uglify=\"true\" rollup -c"
"buildDevBrowser": "NODE_ENV=false uglify=false rollup -c",
"buildProdBrowser": "NODE_ENV=false uglify=true rollup -c",
"buildDevNode": "NODE_ENV=true uglify=false rollup -c",
"buildProdNode": "NODE_ENV=true uglify=true rollup -c"
},
"author": "",
"license": "ISC",
Expand All @@ -28,6 +30,7 @@
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-terser": "^5.1.2",
"rollup-plugin-uglify": "^6.0.3"
"rollup-plugin-uglify": "^6.0.3",
"xmlhttprequest": "^1.8.0"
}
}
5 changes: 4 additions & 1 deletion rudder-client-javascript/analytics/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { terser } from "rollup-plugin-terser";

export default {
input: "analytics.js",
external: ["Xmlhttprequest"],
output: [
{
file: "dist/browser.js",
Expand All @@ -18,7 +19,9 @@ export default {
}
],
plugins: [
replace({ "process.browser": true }),
replace({
"process.browser": process.env.NODE_ENV == "true" ? false : true
}),
resolve(),
commonjs(),
babel({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ <h1>Page Loaded</h1>

<script type="text/javascript">
analytics = window.analytics = [];
XMLHttpRequestNode = XMLHttpRequest;
analytics.page = function() {
console.log(...arguments)
analytics.push(["page", ...arguments]);
Expand Down
7 changes: 6 additions & 1 deletion rudder-client-javascript/analytics/utils/EventRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { getCurrentTimeFormatted } from "./utils";
import { replacer } from "./utils";
import { RudderPayload } from "./RudderPayload";
import * as XMLHttpRequestNode from "Xmlhttprequest";

//Event Repository
class EventRepository {
Expand Down Expand Up @@ -33,7 +34,11 @@ class EventRepository {
payload.sent_at = getCurrentTimeFormatted();
//server-side integration, XHR is node module

var xhr = new XMLHttpRequest();
if (process.browser) {
var xhr = new XMLHttpRequestNode();
} else {
var xhr = new XMLHttpRequestNode.XMLHttpRequest();
}

console.log("==== in flush sending to Rudder BE ====");
console.log(JSON.stringify(payload, replacer).replace(/rl_/g, ""));
Expand Down
15 changes: 13 additions & 2 deletions rudder-client-javascript/analytics/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as XMLHttpRequestNode from "Xmlhttprequest";

//Utility method for excluding null and empty values in JSON
function replacer(key, value) {
if (!value || value == "") {
Expand Down Expand Up @@ -39,7 +41,11 @@ function getCurrentTimeFormatted() {
function getJSON(url, wrappers, isLoaded, callback) {
//server-side integration, XHR is node module

let xhr = new XMLHttpRequest();
if (process.browser) {
var xhr = new XMLHttpRequestNode();
} else {
var xhr = new XMLHttpRequestNode.XMLHttpRequest();
}
xhr.open("GET", url, false);
xhr.onload = function() {
let status = xhr.status;
Expand All @@ -60,7 +66,12 @@ function getJSON(url, wrappers, isLoaded, callback) {
function getJSONTrimmed(context, url, callback) {
//server-side integration, XHR is node module
let cb_ = callback.bind(context);
let xhr = new XMLHttpRequest();

if (process.browser) {
var xhr = new XMLHttpRequestNode();
} else {
var xhr = new XMLHttpRequestNode.XMLHttpRequest();
}
xhr.open("GET", url, true);
xhr.onload = function() {
let status = xhr.status;
Expand Down

0 comments on commit dc0a3e1

Please sign in to comment.