Google 分析跟踪 pdf 下载 [英] Google analytics track pdf downloads
问题描述
我想知道是否有人通过谷歌分析工作获得了文件下载和外部链接跟踪.
I was wondering if anyone has gotten file download and external link tracking with google analytics working.
我在这里阅读了它是如何完成的http://support.google.com/googleanalytics/bin/answer.py?hl=zh-CN&answer=55529.
I read here how its done http://support.google.com/googleanalytics/bin/answer.py?hl=en&answer=55529.
但是我尝试在我的链接上实现它,并且自从我这样做以来已经有几个星期了,我看不到它出现在哪里.(我知道我已经点击了几次)
But I tried implementing it on my links and its been a couple weeks since I did it and I can't see where it has shown up. (I know i've clicked it a couple of times)
这是我用过的代码.
外部链接
<a onclick="javascript: _gaq.push(['_trackPageview', '/external-link/www.somesite.com']);" href="http://www.somesite.com/" title="External link">www.somesite.com</a>
对于pdf文件
<a onclick="javascript: _gaq.push(['_trackPageview', '/pdfs/test.pdf']);" href="http://www.site.com/pdfs/test.pdf">Downland and complete a Transfer your super into Cbus form</a>
我在页面上有分析,但似乎没有跟踪.
I have analytics on the page but it doesn't seem to be tracking.
有人用过这个吗?任何帮助将不胜感激.
Has anyone gotten this working? Any help would be appreciated.
谢谢
推荐答案
您是否尝试过在 Chrome 中使用开发人员工具或 Firefox & 查看您的页面?Firebug 并检查控制台是否有 javascript 错误?
Have you tried looking at your page either in Chrome with the developer tools or Firefox & Firebug and check the console for javascript errors?
此外,您可能希望使用事件跟踪而不是浏览量,例如 http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html
Also, you may want to use event tracking instead of pageviews, like at http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html
在这种情况下,您的代码将类似于
In that case, your code would look something like
<a onclick="_gaq.push(['_trackEvent', 'File', 'Download', '/pdfs/test.pdf']);" href="http://www.site.com/pdfs/test.pdf">Downland and complete a Transfer your super into Cbus form</a>
需要注意的是,Google Analytics 通过请求跟踪像素来工作.如果您在跟踪像素请求完成之前离开当前页面,您将看不到分析数据.我通过以下变体获得了不错的结果:
Something to be aware of is that Google Analytics works by requesting a tracking pixel. If you leave the current page before the tracking pixel request has completed, you won't see the analytics data. I've had good results with variations of the following:
<script type="text/javascript">
function trackLink(link) {
_gaq.push(['_trackEvent', 'Link', 'Click', link.href])
if ("_blank" == link.target) return true;
setTimeout('document.location = "' + link.href + '"', 150);
return false;
}
</script>
<a onclick="return trackLink(this);" href="http://www.somesite.com/" title="External link">www.somesite.com</a>
简而言之,除非链接在新窗口中打开(`_blank" == link.target),等待 150 毫秒后自己处理转到新 URL.
In brief, unless the link opens in a new window (`_blank" == link.target), handle going to the new URL ourselves after waiting 150 ms.
这篇关于Google 分析跟踪 pdf 下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!