Created
May 16, 2013 20:05
-
-
Save postpostmodern/5594656 to your computer and use it in GitHub Desktop.
General event tracking for Google Universal Analytics
This file contains hidden or 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
$('body').on('click', 'a, img, button', function(e) { | |
var $el = $(e.target); | |
if($el.data('event-count')) { | |
$el.data('event-count', ($el.data('event-count') + 1)); | |
} else { | |
$el.data('event-count', 1); | |
} | |
var category = e.target.nodeName; | |
var action = e.type; | |
var label = $el.data('event-label'); | |
var value = $el.data('event-count'); | |
ga('send', 'event', category, action, label, value); | |
return true; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment