Last active
August 19, 2016 20:00
-
-
Save ethanhinson/c1d98c1f60df354b8fb6fd936fbe683d to your computer and use it in GitHub Desktop.
Pseudo code for firing dataLayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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