我想为bit.ly,j.mp和domain.com/go/类型的链接(在内容和评论中)添加onClick=""
,这些链接尚未包含,以便链接如下所示: / p>
<a href="http://domain.com/go/best-house/" rel="external nofollow" onClick="_gaq.push(['_trackEvent', 'click', 'ps', 'http://domain.com/go/best-house/']);">link text</a>
我该怎么做?
答案 0 :(得分:0)
使用纯JavaScript:
window.onload = function() {
var elements = document.getElementsByTagName('a'),
addGaqPush = function() {
_gaq.push(['_trackEvent', 'click', 'ps', 'event_house']);
};
for( var i = 0, len = elements.length; i < len; i++ ) {
elements[i].onclick = addGaqPush;
}
}