谷歌文件下载分析未启动,位置问题

Google Analytics for File Downloads not firing, placement issues?

本文关键字:位置 问题 启动 文件下载 谷歌      更新时间:2023-09-26

我不确定我的位置是否正确。。。这是我需要帮助的部分。。。

我有一个web应用程序,它将动态生成可用资源的列表,并且文件信息变量的解析非常完美。。。我正在用这样的代码安装锚标签:

<ul id="ul_4" class="resources_list fa-ul h_4">
    <li>
        <a onclick="var that=this;_gaq.push(['_trackEvent','Resources: Tools','Download','Policy template: Access to confidential information']);setTimeout(function(){location.href=that.href;},200);return false;" href="/file.cfm?f=402&type=resource">Policy template: Access to confidential information</a>
    </li>
    <li>
        <a onclick="var that=this;_gaq.push(['_trackEvent','Resources: Tools','Download','Policy template: Client records']);setTimeout(function(){location.href=that.href;},200);return false;" href="/file.cfm?f=407&type=resource">Policy template: Client records</a>
    </li>
    <li>
        <a onclick="var that=this;_gaq.push(['_trackEvent','Resources: Tools','Download','Policy template: Privacy']);setTimeout(function(){location.href=that.href;},200);return false;" href="/file.cfm?f=391&type=resource">Policy template: Privacy</a>
    </li>
</ul>

然后是我的谷歌分析标准代码,如下所示:

<script>
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-12345678-1']);
    _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>

不幸的是,无论我在这些链接上使用的点击次数如何,触发器似乎都不会记录在谷歌分析中。。。即使在24小时或更长时间后。。。我是否使用了错误的方法来填充链接上的触发器,或者我是否使用错误的代码来引用触发器?我应该把最初的谷歌分析顽童代码放在我的页面顶部吗?

事实上,我知道标准GA代码是有效的,因为我看到了其他页面的活动。。。但关于从这些链接下载的文件,问题是。。。在GA方面,我是一个非常优秀的人,所以我愿意接受任何建议。。。我错过了什么?

提前感谢。。。

问题是onclick属性在页面更改为资源之前不一定执行;CCD_ 2可以在GA请求通过之前执行。您可以通过查看开发人员控制台中的"网络"选项卡来看到这一点;GA请求可能永远不会完成,因为用户在CCD_。

您似乎也在使用_gaq(在旧版本的Analytics中使用)而不是ga

谷歌的文档中总结了正确的方法。在这里它是为您改编的:

<script>
var trackFileDownload = function(url, page, description) {
   ga('send', 'event', 'fileDownload', url, page + " " + description, {'hitCallback':
     function () {
       document.location = url;
     }
   });
}
</script>
<a onclick="trackFileDownload(this.href, 'Resources: Tools', 'Policy template: Access to confidential information'); return false;" href="/file.cfm?f=402&type=resource">Policy template: Access to confidential information</a>