Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active August 29, 2015 14:03
Show Gist options
  • Save miguelmota/cf1fcaba14f3bf50efa1 to your computer and use it in GitHub Desktop.
Save miguelmota/cf1fcaba14f3bf50efa1 to your computer and use it in GitHub Desktop.
Google Analytics in Angular.js
angular.module('App')
.controller('MyController', function ($scope, $location, $window, $rootScope) {
$rootScope.$on('$routeChangeSuccess', function(e) {
$window.ga('send', 'pageview', { page: $location.path() });
});
$scope.gaEvent = function() {
$window.ga('send', {
'hitType': 'event',
'eventCategory': 'button',
'eventAction': 'click',
'eventLabel': 'Navbar',
'eventValue': 'About'
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment