Skip to content

Instantly share code, notes, and snippets.

@pk
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pk/5552d00f36e624075302 to your computer and use it in GitHub Desktop.
Save pk/5552d00f36e624075302 to your computer and use it in GitHub Desktop.
core/analytics.service.ts
angular
.module("core.analytics", [])
.service("Analytics", function($rootScope, $state){
this.handle = null;
this.setup = function(handle, trackerID){
if (!handle) {
console.log("Analytics: Unable to initialize plugin!");
return false;
}
// Configuraiton
this.handle = handle;
this.handle.debugMode();
this.handle.startTrackerWithId("UA-59700725-1");
console.log("Analytics: Did setup analytics...");
// Observe view enter events and track current state
$rootScope.$on("$ionicView.enter", function(event){
this.handle.trackView($state.$current.name);
console.log("Analytics: tracking " + $state.$current.name);
});
return true;
};
this.setUser = function(userID){
if (!this.handle) return;
this.handle.setUserId(userID);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment