Skip to content

Commit

Permalink
add javascript sdk for GA
Browse files Browse the repository at this point in the history
  • Loading branch information
prabrisha-rudder committed Oct 8, 2019
1 parent e3fb321 commit caecd43
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
7 changes: 7 additions & 0 deletions rudder-client-javascript/analytics/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ class Analytics {
let intgInstance = new intgClass(hubId);
intgInstance.init();

this.clientIntegrationObjects.push(intgInstance);
}
if (intg === "GA") {
let trackingID = configArray[i].trackingID;
let intgInstance = new intgClass(trackingID);
intgInstance.init();

this.clientIntegrationObjects.push(intgInstance);
}
});
Expand Down
46 changes: 39 additions & 7 deletions rudder-client-javascript/analytics/integrations/GA/browser.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,56 @@
class GA {
constructor() {
console.log("nothing to construct");
constructor(trackingID) {
this.trackingID = trackingID;
}

init() {
console.log("browser not implemented");
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

//window.ga_debug = {trace: true};

ga('create', this.trackingID, 'auto');
ga('send', 'pageview');

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

identify(rudderElement) {
console.log("browser not implemented");
ga('set', 'userId', rudderElement.message.anonymous_id);
console.log("in GoogleAnalyticsManager identify");
}

track(rudderElement) {
console.log("browser not implemented");
var eventCategory = rudderElement.message.event
var eventAction = rudderElement.message.event
var eventLabel = rudderElement.message.event
var eventValue = rudderElement.message.properties.value ? rudderElement.message.properties.value : rudderElement.message.properties.revenue
var payLoad = {
hitType: 'event',
eventCategory : eventCategory,
eventAction : eventAction,
eventLabel : eventLabel,
eventValue : eventValue
}
console.log(window['GoogleAnalyticsObject'])
ga('send', 'event', payLoad);
console.log("in GoogleAnalyticsManager track");
}

page(rudderElement) {
console.log("browser not implemented");
console.log("in GoogleAnalyticsManager page");
console.log(window['GoogleAnalyticsObject'])
var path = (rudderElement.properties && rudderElement.properties.path) ? rudderElement.properties.path : undefined
if(path){
ga('set', 'page', path);
}
ga('send', 'pageview', {
hitCallback: function() {
console.log("===GA callback===");
}
});
}

loaded() {
Expand Down

0 comments on commit caecd43

Please sign in to comment.