Skip to content

Commit

Permalink
conditional require, won't be used by rollup for iife
Browse files Browse the repository at this point in the history
  • Loading branch information
sayan-rudder committed Oct 10, 2019
1 parent f60cfbf commit 4052ad0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 35 deletions.
6 changes: 5 additions & 1 deletion rudder-client-javascript/analytics/integrations/GA/node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import ua from "universal-analytics";
//import ua from "universal-analytics";
let ua;
if (!process.browser) {
ua = require("universal-analytics");
}

class GANode {
constructor(trackingID) {
Expand Down
65 changes: 36 additions & 29 deletions rudder-client-javascript/analytics/tests/html/test_browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ <h1>Page Loaded</h1>

<script type="text/javascript">
analytics = window.analytics = [];
XMLHttpRequestNode = XMLHttpRequest;
ua = {};
//XMLHttpRequestNode = XMLHttpRequest;
//ua = {};
analytics.page = function() {
console.log(...arguments);
analytics.push(["page", ...arguments]);
Expand Down Expand Up @@ -71,7 +71,7 @@ <h1>Page Loaded</h1>
revenue: 10
}); */
</script>
<script src="browser.js"></script>
<script src="../../dist/browser.js"></script>

<script type="text/javascript">
//var testObj = new analytics.test();
Expand Down Expand Up @@ -105,32 +105,39 @@ <h1>Page Loaded</h1>
)
.build()
); */
analytics.identify('12345', {email: "sayan@gmail.com"}, {
context: {
ip: '0.0.0.0',
},
page: {
path: '',
referrer: '',
search: '',
title: '',
url: '',
},
anonymousId: '00000000000000000000000000',
});
analytics.page('ApplicationLoaded', {
path: '',
referrer: '',
search: '',
title: '',
url: '',
},
{
context: {
ip: '0.0.0.0'
},
anonymousId: '00000000000000000000000000'
});
analytics.identify(
"12345",
{ email: "sayan@gmail.com" },
{
context: {
ip: "0.0.0.0"
},
page: {
path: "",
referrer: "",
search: "",
title: "",
url: ""
},
anonymousId: "00000000000000000000000000"
}
);
analytics.page(
"ApplicationLoaded",
{
path: "",
referrer: "",
search: "",
title: "",
url: ""
},
{
context: {
ip: "0.0.0.0"
},
anonymousId: "00000000000000000000000000"
}
);
</script>
</body>
</html>
9 changes: 7 additions & 2 deletions rudder-client-javascript/analytics/utils/EventRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import {
import { getCurrentTimeFormatted } from "./utils";
import { replacer } from "./utils";
import { RudderPayload } from "./RudderPayload";
import * as XMLHttpRequestNode from "Xmlhttprequest";
//import * as XMLHttpRequestNode from "Xmlhttprequest";

let XMLHttpRequestNode;
if (!process.browser) {
XMLHttpRequestNode = require("Xmlhttprequest");
}

/**
*
Expand Down Expand Up @@ -57,7 +62,7 @@ class EventRepository {
//server-side integration, XHR is node module

if (process.browser) {
var xhr = new XMLHttpRequestNode();
var xhr = new XMLHttpRequest();
} else {
var xhr = new XMLHttpRequestNode.XMLHttpRequest();
}
Expand Down
11 changes: 8 additions & 3 deletions rudder-client-javascript/analytics/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import * as XMLHttpRequestNode from "Xmlhttprequest";
//import * as XMLHttpRequestNode from "Xmlhttprequest";

let XMLHttpRequestNode;
if (!process.browser) {
XMLHttpRequestNode = require("Xmlhttprequest");
}

/**
*
Expand Down Expand Up @@ -66,7 +71,7 @@ function getJSON(url, wrappers, isLoaded, callback) {
//server-side integration, XHR is node module

if (process.browser) {
var xhr = new XMLHttpRequestNode();
var xhr = new XMLHttpRequest();
} else {
var xhr = new XMLHttpRequestNode.XMLHttpRequest();
}
Expand Down Expand Up @@ -95,7 +100,7 @@ function getJSONTrimmed(context, url, writeKey, callback) {
let cb_ = callback.bind(context);

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

0 comments on commit 4052ad0

Please sign in to comment.