diff --git a/public/js/app.js b/public/js/app.js index 011b1500f5..57fb7a25f3 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -189,10 +189,7 @@ window.habitrpg = angular.module('habitrpg', }) .state('options.settings.subscription', { url: "/subscription", - templateUrl: "partials/options.settings.subscription.html", - onEnter: function(){ - window.ga && ga('send', 'event', 'page', 'view', 'Basic Subscription'); - } + templateUrl: "partials/options.settings.subscription.html" }) var settings = JSON.parse(localStorage.getItem(STORAGE_SETTINGS_ID)); diff --git a/public/js/controllers/rootCtrl.js b/public/js/controllers/rootCtrl.js index e0c3355093..d9d56efe9e 100644 --- a/public/js/controllers/rootCtrl.js +++ b/public/js/controllers/rootCtrl.js @@ -13,6 +13,11 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$ }) $rootScope.$on('userUpdated',initSticky); + $rootScope.$on('$stateChangeSuccess', + function(event, toState, toParams, fromState, fromParams){ + if (!!fromState.name) window.ga && ga('send', 'pageview', {page: '/#/'+toState.name}); + }); + $rootScope.User = User; $rootScope.user = user; $rootScope.moment = window.moment; diff --git a/public/js/static.js b/public/js/static.js index c939c2a931..84894ec5ab 100644 --- a/public/js/static.js +++ b/public/js/static.js @@ -6,14 +6,8 @@ window.habitrpgStatic = angular.module('habitrpgStatic', ['notificationServices' .constant("STORAGE_SETTINGS_ID", 'habit-mobile-settings') .constant("MOBILE_APP", false) -habitrpgStatic.controller("PlansCtrl", ['$rootScope', '$location', '$timeout', - function($rootScope, $location, $timeout) { - - // GA goal-tracking - $timeout(function(){ - window.ga && ga('send', 'event', 'page', 'view', 'Plans'); - }); - +habitrpgStatic.controller("PlansCtrl", ['$rootScope', + function($rootScope) { $rootScope.clickContact = function(){ window.ga && ga('send', 'event', 'button', 'click', 'Contact Us (Plans)'); } diff --git a/src/controllers/auth.js b/src/controllers/auth.js index 47c3b19c24..c4d1541eaa 100644 --- a/src/controllers/auth.js +++ b/src/controllers/auth.js @@ -8,6 +8,7 @@ var async = require('async'); var utils = require('../utils'); var nconf = require('nconf'); var User = require('../models/user').model; +var ga = require('./../utils').ga; var api = module.exports; @@ -88,6 +89,7 @@ api.registerUser = function(req, res, next) { }; user = new User(newUser); user.save(cb); + ga.event('register', 'Local').send() } ], function(err, saved) { if (err) { @@ -250,8 +252,7 @@ api.setupPassport = function(router) { } }); user.save(cb); - - + ga.event('register', 'Facebook').send() } ], function(err, saved){ if (err) return res.redirect('/static/front?err=' + err); diff --git a/src/controllers/user.js b/src/controllers/user.js index 9247ddafa7..5556a25093 100644 --- a/src/controllers/user.js +++ b/src/controllers/user.js @@ -461,7 +461,7 @@ _.each(shared.wrap({}).ops, function(op,k){ if (err) return next(err); res.json(200,response); }) - }) + }, ga); } } })