谷歌分析自动标记出站链接
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了谷歌分析自动标记出站链接相关的知识,希望对你有一定的参考价值。
This will automatically tag external links and prefix the URL with '/outgoing' for tracking in Google Analytics. The pageTracker is assumed to be added to the page elsewhere in the markup. By default it is applied to all links contained in the BODY tag, excluding those with the class 'noAutoLink.' This snippet is not an original work of mine, but I do not know its author.
$(document).ready(function() { $('body a').filter(function() { var theHref = this; if (theHref.hostname && theHref.hostname !== location.hostname) { $(theHref).not(".noAutoLink").attr('target', '_blank').bind('click keypress', function(event) { var code = event.charCode || event.keyCode; if (!code || (code && code == 13)) { if (pageTracker) { var fixedLink = this.href; fixedLink = fixedLink.replace(/https?://(.*)/, "$1"); fixedLink = '/outgoing/' + fixedLink; pageTracker._trackPageview(fixedLink); } }; }); }; }); }); </script>
以上是关于谷歌分析自动标记出站链接的主要内容,如果未能解决你的问题,请参考以下文章
javascript 出站链接跟踪 - 谷歌分析jquery / javascript