aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorPeter Bacon Darwin2014-02-21 21:35:12 +0000
committerPeter Bacon Darwin2014-02-22 10:07:31 +0000
commit3b5480e9fc66fb13dc4723c0c836564a6d1aaaf3 (patch)
tree0228682a240e69cadc3e20ec252be50f10081920 /docs
parenta4078fcae4a33295675d769a1cd067837029da2f (diff)
downloadangular.js-3b5480e9fc66fb13dc4723c0c836564a6d1aaaf3.tar.bz2
chore(doc-app): ensure only canonical paths get sent to Google Analytics
Before we were simply sending the current location, but multiple URLs map to the same document. Now, we use the canonical path of the current document if available and fall back to the $location path otherwise. Includes tests!! Closes #6402
Diffstat (limited to 'docs')
-rw-r--r--docs/app/src/app.js23
-rw-r--r--docs/app/src/docs.js27
-rw-r--r--docs/app/test/docsSpec.js33
3 files changed, 59 insertions, 24 deletions
diff --git a/docs/app/src/app.js b/docs/app/src/app.js
new file mode 100644
index 00000000..0ac5f258
--- /dev/null
+++ b/docs/app/src/app.js
@@ -0,0 +1,23 @@
+angular.module('docsApp', [
+ 'ngRoute',
+ 'ngCookies',
+ 'ngSanitize',
+ 'ngAnimate',
+ 'DocsController',
+ 'versionsData',
+ 'pagesData',
+ 'directives',
+ 'errors',
+ 'examples',
+ 'search',
+ 'tutorials',
+ 'versions',
+ 'bootstrap',
+ 'bootstrapPrettify',
+ 'ui.bootstrap.dropdown'
+])
+
+
+.config(function($locationProvider) {
+ $locationProvider.html5Mode(true).hashPrefix('!');
+}); \ No newline at end of file
diff --git a/docs/app/src/docs.js b/docs/app/src/docs.js
index cb4f029f..5163e982 100644
--- a/docs/app/src/docs.js
+++ b/docs/app/src/docs.js
@@ -1,26 +1,4 @@
-angular.module('docsApp', [
- 'ngRoute',
- 'ngCookies',
- 'ngSanitize',
- 'ngAnimate',
- 'versionsData',
- 'pagesData',
- 'directives',
- 'errors',
- 'examples',
- 'search',
- 'tutorials',
- 'versions',
- 'bootstrap',
- 'bootstrapPrettify',
- 'ui.bootstrap.dropdown'
-])
-
-
-.config(function($locationProvider) {
- $locationProvider.html5Mode(true).hashPrefix('!');
-})
-
+angular.module('DocsController', [])
.controller('DocsController', function($scope, $rootScope, $location, $window, $cookies, NG_PAGES, NG_NAVIGATION, NG_VERSION) {
@@ -52,7 +30,8 @@ angular.module('docsApp', [
};
$scope.afterPartialLoaded = function() {
- $window._gaq.push(['_trackPageview', $location.path()]);
+ var pagePath = $scope.currentPage ? $scope.currentPage.path : $location.path();
+ $window._gaq.push(['_trackPageview', pagePath]);
};
/** stores a cookie that is used by apache to decide which manifest ot send */
diff --git a/docs/app/test/docsSpec.js b/docs/app/test/docsSpec.js
new file mode 100644
index 00000000..ea6c6ba9
--- /dev/null
+++ b/docs/app/test/docsSpec.js
@@ -0,0 +1,33 @@
+describe("DocsController", function() {
+ var $scope;
+
+ angular.module('fake', [])
+ .value('$cookies', {})
+ .value('NG_PAGES', {})
+ .value('NG_NAVIGATION', {})
+ .value('NG_VERSION', {});
+
+ beforeEach(module('fake', 'DocsController'));
+ beforeEach(inject(function($rootScope, $controller) {
+ $scope = $rootScope;
+ $controller('DocsController', { $scope: $scope });
+ }));
+
+
+ describe('afterPartialLoaded', function() {
+ it("should update the Google Analytics with currentPage path if currentPage exists", inject(function($window) {
+ $window._gaq = [];
+ $scope.currentPage = { path: 'a/b/c' };
+ $scope.afterPartialLoaded();
+ expect($window._gaq.pop()).toEqual(['_trackPageview', 'a/b/c']);
+ }));
+
+
+ it("should update the Google Analytics with $location.path if currentPage is missing", inject(function($window, $location) {
+ $window._gaq = [];
+ spyOn($location, 'path').andReturn('x/y/z');
+ $scope.afterPartialLoaded();
+ expect($window._gaq.pop()).toEqual(['_trackPageview', 'x/y/z']);
+ }));
+ });
+}); \ No newline at end of file