Log page views to Google Analytics from Angular

This commit is contained in:
Steve Purcell 2013-09-23 18:15:13 +01:00
parent b5659b4c7b
commit 84f3f9c49e
2 changed files with 9 additions and 2 deletions

View file

@ -62,7 +62,6 @@
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-39278673-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';

View file

@ -143,11 +143,19 @@
});
});
app.controller('AppCtrl', function($scope, $rootScope, $route) {
app.controller('AppCtrl', function($scope, $rootScope, $route, $window) {
$scope.hideSplash = false;
$rootScope.$on("$routeChangeSuccess", function() {
$scope.hideSplash = ($route.current.controller != 'PackageListCtrl');
});
$rootScope.$on("$locationChangeSuccess", function(e, newURL, oldURL) {
if (newURL && (newURL.$$route||newURL).redirectTo) return;
if ($window._gaq && newURL != (oldURL + "#/")) {
var l = $window.location;
var path = l.pathname + l.hash + l.search;
$window._gaq.push (["_trackPageview", path ]);
}
});
});
//////////////////////////////////////////////////////////////////////////////