Skip to content

Commit dd9585b

Browse files
committed
Merge branch 'website' of https://github.com/nlaplante/angular-google-maps into website
2 parents 079d0ea + ad06159 commit dd9585b

File tree

1 file changed

+58
-0
lines changed
  • app/scripts/services

1 file changed

+58
-0
lines changed

app/scripts/services/ga.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use strict';
2+
3+
angular.module('angularGoogleMapsApp').provider('analytics', function () {
4+
5+
var _trackingCode = null,
6+
_trackViewChange = true,
7+
ga = null;
8+
9+
this.trackingCode = function () {
10+
if (arguments.length) {
11+
_trackingCode = arguments[0];
12+
return this;
13+
}
14+
15+
return _trackingCode;
16+
};
17+
18+
this.trackViewChange = function () {
19+
if (arguments.length) {
20+
_trackViewChange = arguments[0];
21+
return this;
22+
}
23+
24+
return _trackViewChange;
25+
};
26+
27+
this.$get = function ($window, $log, $rootScope, $document) {
28+
29+
ga = $window._gaq || [];
30+
31+
ga.push(['_setAccount', _trackingCode]);
32+
33+
var _trackPageView = function (path) {
34+
ga.push(['_trackPageview', path]);
35+
},
36+
_trackEvent = function (name, value) {
37+
ga.push(['_trackEvent', name, value]);
38+
};
39+
40+
if (_trackViewChange) {
41+
42+
$log.info('analytics: telling analytics service to track view changes');
43+
44+
$rootScope.$on('$routeChangeSuccess', function () {
45+
_trackPageView();
46+
});
47+
48+
$rootScope.$on('$routeChangeError', function () {
49+
_trackPageView();
50+
});
51+
}
52+
53+
return {
54+
trackPageView: _trackPageView,
55+
trackEvent: _trackEvent
56+
};
57+
};
58+
});

0 commit comments

Comments
 (0)