Google Analytics事件跟踪无效

时间:2012-11-26 14:57:43

标签: google-analytics

我在Google Analytics中添加了跟踪事件_trackEvent()以进行文件下载,但它无效。我已经等了24小时才能在Google Analytics上进行事件跟踪更新。 我的代码是:

<a class="buttonstyle" href="/DownloadDocuments/WINTER_2012_Magazine_visual.pdf" target="_blank"     onclick="return documentDownload(this, 'WINTER_2012_Magazine_visual.pdf');">Download</a>

<script>
function documentDownload(link, downloadFileName) {
_gaq.push(['_trackEvent', 'Downloads', 'Click', downloadFileName]);
setTimeout('document.location = "' + link.href + '"', 500);

return false;
}
</script>

我已经检查了控制台,这对我来说没问题:

_gaq.push processing "_trackEvent" for args: "[Downloads,Click,WINTER_2012_Magazine_visual.pdf]":    ga_debug.js:18
Track Event ga_debug.js:18
Tracking beacon sent!
utmwv=5.3.8d&utms=15&utmn=1916071374&utmhn=www.testmarketingstore.co.uk&utmt=event&utme=5(Downloads*Click*WINTER_2012_Magazine_visual.pdf)&utmcs=UTF-8&utmsr=1920x1080&utmvp=1903x955&utmsc=32-bit&utmul=en-gb&utmje=1&utmfl=11.5%20r31&utmdt=Test%20Marketing%20Store&utmhid=972203903&utmr=-&utmp=%2Fasp%2Fca%2Fced.asp%3FdisplayType%3Ddocs%26searchCriteria%3Duseful&utmac=UA-XXXXX-X&utmcc=__utma%3D231962136.231857795.1353415477.1353932330.1353939554.6%3B%2B__utmz%3D231962136.1353415477.1.1.utmcsr%3D(direct)%7Cutmccn%3D(direct)%7Cutmcmd%3D(none)%3B&utmu=yAAAAAAAAC~ ga_debug.js:18
Account ID               : UA-XXXXX-X
Page Title               : Test Marketing Store
Host Name                : www.testmarketingstore.co.uk
Page                         : /asp/ca/ced.asp?displayType=docs&searchCriteria=useful
Referring URL            : -
Hit ID                   : 972203903
Hit Type                 : event
Event Name               : Downloads
Event Type               : Click
Event Label              : WINTER_2012_Magazine_visual.pdf
Visitor ID               : 231857795
Session Count            : 6
Session Time - First     : Tue Nov 20 2012 12:44:37 GMT 0000 (GMT Standard Time)
Session Time - Last      : Mon Nov 26 2012 12:18:50 GMT 0000 (GMT Standard Time)
Session Time - Current   : Mon Nov 26 2012 14:19:14 GMT 0000 (GMT Standard Time)
Campaign Time            : Tue Nov 20 2012 12:44:37 GMT 0000 (GMT Standard Time)
Campaign Session         : 1
Campaign Count           : 1
Campaign Source          : (direct)
Campaign Medium          : (none);
Campaign Name            : (direct)
Language                 : en-gb
Encoding                 : UTF-8
Flash Version            : 11.5 r31
Java Enabled             : true
Screen Resolution        : 1920x1080
Browser Size             : 1903x955
Color Depth              : 32-bit
Ga.js Version            : 5.3.8d
Cachebuster              : 1916071374 

有人可以就如何追查问题给我一些建议吗?

2 个答案:

答案 0 :(得分:5)

您正在将旧式同步Google Analytics代码(在您的分析代码段中)与新式异步代码(在事件跟踪中)混合使用。因此,_trackEvent调用正在使用具有默认UA-XXXXX-X UID的分析跟踪器。

两个选项:将事件跟踪代码更改为同步代码:

function documentDownload(link, downloadFileName) {
  pageTracker._trackEvent('Downloads', 'Click', downloadFileName);
  setTimeout('document.location = "' + link.href + '"', 500);
  return false;
}

或将Google分析代码更新为异步风格:

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-464435-4']);
_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>

答案 1 :(得分:0)

你也应该发送_gaq.push(['_ setAccount','UA-XXXXXX-1']);在跟踪事件之前 并为chrome安装此扩展以进行调试 https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna

它对我们有用