Skip to content

Commit

Permalink
Release v1.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Saunders committed Mar 25, 2016
1 parent bfed10c commit bb47043
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
46 changes: 43 additions & 3 deletions dist/angular-google-analytics.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Angular Google Analytics - Easy tracking for your AngularJS application
* @version v1.1.6 - 2016-01-27
* @version v1.1.7 - 2016-03-25
* @link http://github.com/revolunet/angular-google-analytics
* @author Julien Bouquillon <julien@revolunet.com> (https://github.com/revolunet)
* @contributors Julien Bouquillon (https://github.com/revolunet),Justin Saunders (https://github.com/justinsa),Chris Esplin (https://github.com/deltaepsilon),Adam Misiorny (https://github.com/adam187)
Expand Down Expand Up @@ -41,6 +41,7 @@
hybridMobileSupport = false,
offlineMode = false,
pageEvent = '$routeChangeSuccess',
readFromRoute = false,
removeRegExp,
testMode = false,
traceDebuggingMode = false,
Expand Down Expand Up @@ -192,11 +193,23 @@
traceDebuggingMode = !!enableTraceDebugging;
return this;
};

// Enable reading page url from route object
this.readFromRoute = function(val) {
readFromRoute = !!val;
return this;
};

/**
* Public Service
*/
this.$get = ['$document', '$location', '$log', '$rootScope', '$window', function ($document, $location, $log, $rootScope, $window) {
this.$get = ['$document', // To read title
'$location', //
'$log', //
'$rootScope',//
'$window', //
'$injector', // To access ngRoute module without declaring a fixed dependency
function ($document, $location, $log, $rootScope, $window, $injector) {
var that = this;

/**
Expand All @@ -217,9 +230,26 @@
}
return isPropertyDefined('name', config) ? (config.name + '.' + commandName) : commandName;
};

// Try to read route configuration and log warning if not possible
var $route = {};
if (readFromRoute) {
if (!$injector.has('$route')) {
$log.warn('$route service is not available. Make sure you have included ng-route in your application dependencies.');
} else {
$route = $injector.get('$route');
}
}

// Get url for current page
var getUrl = function () {
var url = trackUrlParams ? $location.url() : $location.path();
// Using ngRoute provided tracking urls
if (readFromRoute && $route.current && ('pageTrack' in $route.current)) {
return $route.current.pageTrack;
}

// Otherwise go the old way
var url = trackUrlParams ? $location.url() : $location.path();
return removeRegExp ? url.replace(removeRegExp, '') : url;
};

Expand Down Expand Up @@ -1062,6 +1092,15 @@
// activates page tracking
if (trackRoutes) {
$rootScope.$on(pageEvent, function () {
// Apply $route based filtering if configured
if (readFromRoute) {
// Avoid tracking undefined routes, routes without template (e.g. redirect routes)
// and those explicitly marked as 'do not track'
if (!$route.current || !$route.current.templateUrl || $route.current.doNotTrack) {
return;
}
}

that._trackPage();
});
}
Expand All @@ -1088,6 +1127,7 @@
ignoreFirstPageLoad: ignoreFirstPageLoad,
logAllCalls: logAllCalls,
pageEvent: pageEvent,
readFromRoute: readFromRoute,
removeRegExp: removeRegExp,
testMode: testMode,
traceDebuggingMode: traceDebuggingMode,
Expand Down
Loading

1 comment on commit bb47043

@Toxantron
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was a pleasure to be part of this. Looking forward to another chance to contribute. ;)

Please sign in to comment.