我已经尝试了一切,试图让一些简单的事件跟踪工作无济于事。这是代码。我使用的是通用分析。
<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-xxxxxxx', 'thissite.net');
ga('send', 'pageview');
/*Testing with this link*/
$('.home-logo').on('click', function() {
alert('clicked');
ga('send', 'event', 'homelogo', 'click', 'icons');
});
</script>
<!--Sample Link -->
<a href="/portal/" class="home-logo"><img src="/images/aeportal_logo_small.png" width="95" border="0" /></a>
它使用AJAX和服务在应用程序上呈现内容,所以我不确定是否还需要做其他事情。我知道那里有一个“回击”和#39;功能也很好,但那也没有用。感谢您提供的任何帮助。
答案 0 :(得分:0)
您可能需要延迟页面继续前进,以便GA可以发送事件。
您可以使用hitCallback
功能执行此操作并将其放入可重复使用的功能中,以便为整个页面的出站链接添加事件:
function trackOutboundLinks(category, action, label, url){
ga('send', 'event', category, action, label, {'hitCallback':
function () {
document.location = url;
}
});
}
$('.home-logo').on('click', function(e) {
e.preventDefault();
trackOutboundLinks("homelogo", "click", "icons", $(this).attr("href"));
});
或者,您可以向链接本身添加onclick
函数,而不是使用上面的.on
函数:
<a href="/portal/" class="home-logo" onclick="trackOutboundLinks('homelogo', 'click', 'icons', '/portal/'); return false;"><img src="/images/aeportal_logo_small.png" width="95" border="0" /></a>
此外,您可以使用Google Analytics Debugger extension for Chrome检查事件是否被触发而不是实时盯着。