向PDF / Microsoft Word下载站点添加事件跟踪

问题描述 投票:1回答:2

我在设置事件跟踪时遇到了一些困难。我有一个网站,人们可以在其中下载各种内容的PDF和Word文档。我像这样插入事件跟踪:

<a href=files/8399039122.pdf onClick='_gaq.push(['_trackEvent', 'downloads', 
'all', 'nofilter']);' >File #1</a>

<a href=files/8329384939.doc onClick='_gaq.push(['_trackEvent', 'downloads',
 'all', 'nofilter']);' >File #2</a>

但是,四天后数据仍未显示在我的分析资料中。我安装错了吗?另外,我是否需要将_gaq.push(['_trackEvent', 'downloads', 'all', nofilter]);'添加到页面标题中的分析脚本中?

javascript google-analytics analytics dom-events
2个回答
1
投票

好像是您使用单引号(未正确嵌套)。试试这个:

<a href="files/8399039122.pdf" onClick="_gaq.push(['_trackEvent', 'downloads', 'all', 'nofilter']);" >File #1</a>

<a href="files/8329384939.doc" onClick="_gaq.push(['_trackEvent', 'downloads', 'all', 'nofilter']);" >File #2</a>

将整个onClick用双引号引起来。并且,还应引用指向链接(href)的路径。

[不使用target =“ blank”来延迟onclick

<a href="pdfs/my-file.pdf" onclick="var that=this;_gaq.push(['_trackEvent,'Download','PDF',this.href]);setTimeout(function(){location.href=that.href;},200);return false;">Download my file</a>

0
投票

解决此问题的另一种方法是将target="_blank"添加到<a>标签:

<a href="files/2117802037.pdf" onclick="_gaq.push(['_trackEvent', 'downloads', 'all', 'nofilter']);" target="_blank">File #1</a>
<a href="files/8329384939.doc" onclick="_gaq.push(['_trackEvent', 'downloads', 'all', 'nofilter']);" target="_blank">File #2</a>
© www.soinside.com 2019 - 2024. All rights reserved.