2012-07-23 71 views
1

我正在尝试在Google Analytics中为文件下载设置事件跟踪。经过一番研究,我下面的代码添加到链接,需要跟踪:Google Analtyics事件跟踪文件下载不起作用

<a onclick="_gaq.push(['_trackEvent','Download','PDF',this.href]);" href="http://www.link.com/file.pdf" target="_blank">Link Text</a> 

下面的代码是在网页的谷歌Analytics(分析):

<script type="text/javascript"> 
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); 
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); 
</script> 
<script type="text/javascript"> 
try { 
var pageTracker = _gat._getTracker("UA-9999999-1"); 
pageTracker._trackPageview(); 
} catch(err) {} 
</script> 

这已经活跃了超过48小时但我在GA中没有收到活动。它表示“您的13次访问发送了事件”,但没有显示其他信息。有任何想法吗?

回答

3

看起来您正在为Google Analytics(分析)混合使用两种不同的API。

您发布的第一个片段用于ASYNC跟踪,但您已经在第二个片段中使用了(现在的传统)传统跟踪。

为了让它工作,请将页面跟踪代码更改为如下所示,其他代码看起来不错。

<script type="text/javascript"> 
    var _gaq = _gaq || []; 
    _gaq.push(['_setAccount', 'UA-XXXXX-X']); 
    _gaq.push(['_trackPageview']); 

    (function() { 
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
    })(); 
</script> 

更多细节在这里: https://developers.google.com/analytics/devguides/collection/gajs/asyncTracking