diff --git a/app/index.html b/app/index.html index ffc99632..660f7fac 100644 --- a/app/index.html +++ b/app/index.html @@ -38,5 +38,16 @@ + <% if (uaTracking) { %> + + <% } %> + \ No newline at end of file diff --git a/app/js/app.js b/app/js/app.js index fda622f0..4bce8a08 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -1,11 +1,16 @@ angular.module('app', ['ui.router', 'shipyard', 'ngLodash', 'app.templates']) -.run(['$rootScope','$document','$state','commonArray','shipPurpose','shipSize','hardPointClass','internalGroupMap','hardpointsGroupMap', function ($rootScope, $doc, $state, CArr, shipPurpose, sz, hpc, igMap, hgMap) { +.run(['$rootScope', '$location', '$window', '$document','$state','commonArray','shipPurpose','shipSize','hardPointClass','internalGroupMap','hardpointsGroupMap', function ($rootScope, $location, $window, $doc, $state, CArr, shipPurpose, sz, hpc, igMap, hgMap) { // Redirect any state transition errors to the error controller/state $rootScope.$on('$stateChangeError', function(e, toState, toParams, fromState, fromParams, error){ e.preventDefault(); $state.go('error', error, {location:false, reload:true}); // Go to error state, reload the controller, keep the current URL }); + // Track on Google analytics if available + $rootScope.$on('$stateChangeSuccess', function() { + if ($window.ga) ga('send', 'pageview', {page: $location.path()}); + }); + // Global Reference variables $rootScope.CArr = CArr; $rootScope.SP = shipPurpose; diff --git a/gulpfile.js b/gulpfile.js index bb296edf..73b1b2ba 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -108,7 +108,8 @@ gulp.task('generateIndexHTML', function() { return gulp.src('app/index.html') .pipe(template({ version: pkg.version, - date : (new Date()).toLocaleDateString() + date : (new Date()).toLocaleDateString(), + uaTracking: process.env.CORIOLIS_UA_TRACKING })) .pipe(htmlmin({ 'collapseBooleanAttributes': true,