Skip to content

Instantly share code, notes, and snippets.

@mhz-tamb
Created December 3, 2015 20:14
Show Gist options
  • Save mhz-tamb/ddebf8cfb49db01c122f to your computer and use it in GitHub Desktop.
Save mhz-tamb/ddebf8cfb49db01c122f to your computer and use it in GitHub Desktop.
Simple analytics goals
document.addEventListener('DOMContentLoaded', function() {
var elements = document.querySelectorAll('[data-goal-ya], [data-goal-ga]');
for (var i = 0; i < elements.length; i++) {
elements[i].addEventListener('click', function() {
try {
if (typeof(this.dataset.goalYa) != 'undefined') {
yaCounterXXXXXXX.reachGoal(this.dataset.goalYa);
}
if (typeof(this.dataset.goalGa) != 'undefined') {
ga('send', this.dataset.goalGa, location.pathname);
}
} catch(e) {
/*console.log(e);*/
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment