Last active
December 14, 2015 20:18
-
-
Save jamesmrobinson/5142524 to your computer and use it in GitHub Desktop.
Google Analytics event tracking function. Uses HTML5 data-attributes. Any anchor with the data-event="ga" will fire a Google Analytics event. The event details should also be specified as data-attributes: data-category, data-action, data-label. Requires jQuery > 1.4
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
eventTracking = function () { | |
$t = $('[data-event="ga"]'); | |
$t.click(function () { | |
var gaCat = $(this).data('category') ? $(this).data('category') : '', | |
gaAct = $(this).data('action') ? $(this).data('action') : '', | |
gaLab = $(this).data('label') ? $(this).data('label') : ''; | |
try { | |
_gaq.push(['_trackEvent', gaCat, gaAct, gaLab]); | |
} catch (e) { | |
console.log(e); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks doro, that's updated.