Shoora
5/15/2019 - 2:07 PM

Simple analytics goals

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);*/
            }
        });
    }
});