Skip to content

Instantly share code, notes, and snippets.

@ethanhinson
Last active August 19, 2016 20:00
Show Gist options
  • Save ethanhinson/c1d98c1f60df354b8fb6fd936fbe683d to your computer and use it in GitHub Desktop.
Save ethanhinson/c1d98c1f60df354b8fb6fd936fbe683d to your computer and use it in GitHub Desktop.
Pseudo code for firing dataLayer
(function(ng) {
ng
.module('app', ['ngRoute'])
.run($run);
// Safely instantiate dataLayer
var dataLayer = window.dataLayer = window.dataLayer || [];
$run.$inject = ['$rootScope', '$location'];
function $run($rootScope, $location) {
$rootScope.$on('$routeChangeSuccess', function() {
dataLayer.push({
event: 'ngRouteChange',
attributes: {
route: $location.path()
}
});
});
}
})(angular);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment