Created
June 24, 2014 15:54
-
-
Save bcherny/d4ae69435773400ee82c to your computer and use it in GitHub Desktop.
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
/** | |
* 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