From a23aca8f02358a0fa35988148bae10798d5fe0b3 Mon Sep 17 00:00:00 2001 From: Sandoche Adittane Date: Tue, 19 Jul 2016 17:34:54 +0200 Subject: [PATCH] google analytics bug fixed --- .grunt/grunt-gh-pages/gh-pages/src | 2 +- app/index.html | 1 + app/scripts/app.js | 14 +++++--------- app/scripts/services/analyticsservice.js | 16 ++++++++++++++++ test/spec/services/analyticsservice.js | 18 ++++++++++++++++++ 5 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 app/scripts/services/analyticsservice.js create mode 100644 test/spec/services/analyticsservice.js diff --git a/.grunt/grunt-gh-pages/gh-pages/src b/.grunt/grunt-gh-pages/gh-pages/src index 96417b1..54c3af6 160000 --- a/.grunt/grunt-gh-pages/gh-pages/src +++ b/.grunt/grunt-gh-pages/gh-pages/src @@ -1 +1 @@ -Subproject commit 96417b1836232740cc63c448573d77b1f2562f99 +Subproject commit 54c3af6466eef2878207c41a174d5a4480d9b618 diff --git a/app/index.html b/app/index.html index b34cde3..3890bcf 100644 --- a/app/index.html +++ b/app/index.html @@ -86,6 +86,7 @@ + diff --git a/app/scripts/app.js b/app/scripts/app.js index 48f2aeb..2b21975 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -36,12 +36,8 @@ angular .otherwise({ redirectTo: '/alex' }); - }).run(['$rootScope', '$location', '$window', function($rootScope, $location, $window){ - $rootScope - .$on('$stateChangeSuccess', - function(event){ - if (!$window.ga) - return; - $window.ga('send', 'pageview', { page: $location.path() }); - }); -}]); + }).run(function($rootScope, $location, analyticsService) { + $rootScope.$on('$routeChangeSuccess', function() { + analyticsService.recordPageview($location.url()); + }); + }); diff --git a/app/scripts/services/analyticsservice.js b/app/scripts/services/analyticsservice.js new file mode 100644 index 0000000..4e3d9ac --- /dev/null +++ b/app/scripts/services/analyticsservice.js @@ -0,0 +1,16 @@ +'use strict'; + +/** + * @ngdoc service + * @name happybotsApp.analyticsService + * @description + * # analyticsService + * Service in the happybotsApp. + */ +angular.module('happybotsApp') + .service('analyticsService', function () { + this.recordPageview = function(url) { + ga('set', 'page', url); + ga('send', 'pageview'); + }; + }); diff --git a/test/spec/services/analyticsservice.js b/test/spec/services/analyticsservice.js new file mode 100644 index 0000000..94e3c71 --- /dev/null +++ b/test/spec/services/analyticsservice.js @@ -0,0 +1,18 @@ +'use strict'; + +describe('Service: analyticsService', function () { + + // load the service's module + beforeEach(module('happybotsApp')); + + // instantiate service + var analyticsService; + beforeEach(inject(function (_analyticsService_) { + analyticsService = _analyticsService_; + })); + + it('should do something', function () { + expect(!!analyticsService).toBe(true); + }); + +});