javascript Google Analytics事件跟踪

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Google Analytics事件跟踪相关的知识,希望对你有一定的参考价值。

// Universal Analytics events that include common element attributes
var gaPush = {
    p: function (element, cat, action, type) {
        var el = document.querySelectorAll(element)
        for (var i = 0; i < el.length; i++) {
            el[i].addEventListener('click', function () {
                var attr = {
                    title: eval('this.title'),
                    alt: eval('this.alt'),
                    value: eval('this.value'),
                    href: eval('this.href'),
                    text: eval('this.text')
                }
                var label = attr[type]
                ga('send', 'event', cat, action, label);
            });
        };
    }
}

// set your type to what attribute you want sent - title, alt, value, href, or text
// uncomment following line to test on any link click
// gaPush.p('a', 'hyperlink', 'Click link', 'text')

以上是关于javascript Google Analytics事件跟踪的主要内容,如果未能解决你的问题,请参考以下文章

Javascript - GA 和 Adwords

整合谷歌分析功能

javascript Javascript:Google Analytics Snipper + Google Analytics JS日志记录

Google 跟踪代码管理器使用沙盒 JavaScript?

javascript Google Analytics事件跟踪Javascript

javascript [userscript] [Google]修复Google搜索标签的顺序