Skip to content

Instantly share code, notes, and snippets.

@bcherny
Created June 24, 2014 15:54
Show Gist options
  • Save bcherny/d4ae69435773400ee82c to your computer and use it in GitHub Desktop.
Save bcherny/d4ae69435773400ee82c to your computer and use it in GitHub Desktop.
/**
* usage:
*
* <html analytics-auto-tag> ... </html>
*
*/
angular
.module('webapp', ['angulartics', 'angulartics.adobe.analytics'])
// not sure if this should be a service, since it deals with the DOM
.directive('analyticsAutoTag', function{
return {
restrict: 'A',
scope: false,
link: function(scope, element) {
scope.link = function (event) {
angular.forEach(element.find('[ng-' + event + ']'), function (el) {
var $el = angular.element(el);
$el.attrs({
'analytics-on': event,
'analytics-event': el.text() + '/' + el.attr('ng-' + event)
});
});
return scope;
};
scope
.link('click')
.link('hover');
}
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment