Skip to content

Instantly share code, notes, and snippets.

@sloped
Created June 28, 2012 13:02
Show Gist options
  • Save sloped/3011255 to your computer and use it in GitHub Desktop.
Save sloped/3011255 to your computer and use it in GitHub Desktop.
GAAware tracking code using data attributes and class
/*
GA Aware Track Event Syntax
gaAware.track_event('Category', 'Action', 'Label', Count (1));
Data Attribute to attach to item to track. May be worth breaking these into seperate data attributes to make things more semantic. Might also be able to swap the quote types, but haven't tested yet.
data-tracking='{"category":"x","action":"x","label":"x"}''
*/
var gaAware = jQuery(document).gaaware({
UA: ['UA-2629988-12'],
auto_social: true,
domains: {entity: 'x.com'},
debug: false});
function track(a) {
var c = jQuery(a).data('tracking').category;
var b = jQuery(a).data('tracking').action;
var l = jQuery(a).data('tracking').label;
gaAware.track_event(c, b, l, 1);
};
jQuery(document).ready(function() {
jQuery('.gaa_click').on('click', function() {
track(this);
});
jQuery('.gaa_change').on('change', function() {
track(this);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment