篇首语:本文由小常识网(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事件跟踪的主要内容,如果未能解决你的问题,请参考以下文章