Skip to content

Commit

Permalink
1. Add GA node code( initial commit )
Browse files Browse the repository at this point in the history
2. publish cjs to npm
3. Add a test to download rudder-sdk-node module from npm and use it to send data to BE and GA.
4. Other refactoring.
  • Loading branch information
sayan-rudder committed Oct 8, 2019
1 parent eb9f3e4 commit e3fb321
Show file tree
Hide file tree
Showing 16 changed files with 4,046 additions and 16 deletions.
9 changes: 9 additions & 0 deletions rudder-client-javascript/analytics/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Analytics {
* @memberof Analytics
*/
processResponse(status, response) {
console.log("===in process response=== " + status);
response = JSON.parse(response);
response.source.destinations.forEach(function(destination, index) {
console.log(
Expand Down Expand Up @@ -112,6 +113,13 @@ class Analytics {
}
});

// Add GA forcibly for tests , TODO : Remove
/* let GAClass = integrations["GA"];
let GAInstance = new GAClass("UA-143161493-8");
GAInstance.init();
console.log("GA initialized");
this.clientIntegrationObjects.push(GAInstance); */

for (let i = 0; i < this.clientIntegrationObjects.length; i++) {
//send the queued events to the fetched integration
this.toBeProcessedByIntegrationArray.forEach(event => {
Expand Down Expand Up @@ -509,6 +517,7 @@ class Analytics {
load(writeKey) {
console.log("inside load ");
this.writeKey = writeKey;
//this.init([], this.configArray); TODO: Remove
getJSONTrimmed(
this,
CONFIG_URL + "/source-config?write_key=" + writeKey,
Expand Down
1,563 changes: 1,562 additions & 1 deletion rudder-client-javascript/analytics/dist/browser.js

Large diffs are not rendered by default.

1,563 changes: 1,562 additions & 1 deletion rudder-client-javascript/analytics/dist/node.js

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions rudder-client-javascript/analytics/integrations/GA/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class GA {
constructor() {
console.log("nothing to construct");
}

init() {
console.log("browser not implemented");

console.log("===in init===");
}

identify(rudderElement) {
console.log("browser not implemented");
}

track(rudderElement) {
console.log("browser not implemented");
}

page(rudderElement) {
console.log("browser not implemented");
}

loaded() {
console.log("in GA isLoaded");
console.log("browser not implemented");
}
}

export { GA };
4 changes: 4 additions & 0 deletions rudder-client-javascript/analytics/integrations/GA/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { GANode } from "./node";
import { GA } from "./browser";

export default process.browser ? GA : GANode;
58 changes: 58 additions & 0 deletions rudder-client-javascript/analytics/integrations/GA/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import ua from "universal-analytics";

class GANode {
constructor(trackingID) {
this.trackingID = trackingID;
this.client = "";
}

init() {
console.log("===in GA Node init===");

//this.client = ua(this.trackingID, "6a14abda-6b12-4578-bf66-43c754eaeda9");
}

identify(rudderElement) {
console.log("=== in GA Node identify===");
this.client = ua(this.trackingID, rudderElement.message.user_id);
}

track(rudderElement) {
console.log("=== in GA Node track===");
this.client.event(
rudderElement.message.type,
rudderElement.message.event,
function(err) {
// Handle the error if necessary.
// In case no error is provided you can be sure
// the request was successfully sent off to Google.
console.log("error sending to GA" + err);
}
);
}

page(rudderElement) {
console.log("=== in GA Node page===");
if (
rudderElement.message.properties &&
rudderElement.message.properties.path
) {
this.client.pageview(rudderElement.message.properties.path, function(
err
) {
// Handle the error if necessary.
// In case no error is provided you can be sure
// the request was successfully sent off to Google.
console.log("error sending to GA" + err);
});
//this.client.pageview(rudderElement.message.properties.path).send();
}
}

loaded() {
console.log("in GA isLoaded");
console.log("node not supported");
}
}

export { GANode };
3 changes: 2 additions & 1 deletion rudder-client-javascript/analytics/integrations/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as HubSpot from "./HubSpot";
import * as GA from "./GA";

let integrations = { HS: HubSpot.default };
let integrations = { HS: HubSpot.default, GA: GA.default };

export { integrations };

0 comments on commit e3fb321

Please sign in to comment.