gpt4 book ai didi

javascript - 使用通用分析跟踪出站链接

转载 作者:行者123 更新时间:2023-11-28 01:30:38 25 4
gpt4 key购买 nike

我刚刚将以下“通用”分析代码添加到[e head][1],但找不到如何设置标准的通用出站跟踪事件:

<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-xxxx-Y', 'auto');
ga('send', 'pageview');

</script>
<!-- End Google Analytics -->

这是建议的内容:

var trackOutboundLink = function(url) {

_gaq.push(['_trackEvent', 'Outbound', 'Click', this.href]);
setTimeout('document.location = "' + this.href + '"', 100);
return false;
}

这是用于通用出站事件跟踪吗?它是否跟踪所有事件以及它应该放置在哪里 - 在头部或正文结束标记之前?

这是跟踪单个通用事件的正确语法吗?

onclick="trackOutboundLink('/WEBSITE/www.something.com')

最佳答案

来源:https://github.com/tomfuertes/jquery-universal-analytics/blob/master/src/jquery.universal-analytics.js

$(document).on('mousedown', 'a', function () {
if ((this.protocol === 'http:' || this.protocol === 'https:') && this.hostname.indexOf(document.location.hostname) === -1) {
ga('send', 'event', 'Outbound', this.hostname, this.pathname);
}
});

关于javascript - 使用通用分析跟踪出站链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22153460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com