Google Analytics(分析)事件跟踪只能在Chrome上启用多个帐户 [英] Google Analytics Event Tracking not firing for multiple accounts on Chrome ONLY

查看:165
本文介绍了Google Analytics(分析)事件跟踪只能在Chrome上启用多个帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Google Analytics(分析)事件跟踪问题,仅在 在Chrome上显示,没有其他浏览器。



我有以下Google Google Analytics(分析)跟踪代码在我的网站上触发点击锚定链接:

  _gaq.push(['_ trackEvent' Remove',product_name,product_code,product_price,false]); 
_gaq.push(['rollup._trackEvent','Basket Remove',product_name,product_code,product_price,false]);

使用Web代理工具我可以看到第一个是启动,但第二个不是。这似乎是一些 _trackEvent 点击的情况,其中点击是到另一个页面的链接,并且正如我所说的明显



几乎就好像Chrome已经决定在完成JavaScript执行之前重定向到锚点中的链接。我没有遇到这个问题在IE或FF。



我尝试了一个 setTimeout 后, ,调用但无效。

  setTimeout('document.location ='+ link.href +' 500);问题是Chrome(以及其他浏览器)会在不同的浏览器上显示不同的图片。当在当前窗口中加载新页面的请求被取消时,取消任何未决的图像请求。您可能很幸运,第一个_trackEvent请求正在记录,因为在第二个_trackEvent期间进行了额外的处理。



当向链接添加延迟时,需要确保保持链接的默认操作执行 - 否则默认操作跟随链接之前的setTimeout函数可能发生。



以下代码检查链接是否在新窗口中打开 - 如果没有,则在链接之后延迟150ms:

  function track(link){
_gaq.push(['_ trackEvent','Basket Remove',product_name,product_code,product_price,false] ;
_gaq.push(['rollup._trackEvent','Basket Remove',product_name,product_code,product_price,false]);
if('_blank'== link.target)return true;
var url = link.href;
setTimeout(function(){document.location = url;},150);
return false;
}

< a href =someURLonclick =return track(this);> ClickMe< / a>


I have an issue with Google Analytics Event Tracking that is only apparent on Chrome and no other browser.

I have the following Google Analytics Tracking Code firing on my site for a click on an anchor link:

_gaq.push(['_trackEvent', 'Basket Remove', product_name, product_code, product_price, false]);          
_gaq.push(['rollup._trackEvent', 'Basket Remove', product_name, product_code, product_price, false]);       

Using a Web Proxy tool I can see that the first one is firing, but the second one is not. This appears to be the case for a number of _trackEvent clicks where the click is a link to another page, and as I have said is only apparent in Google Chrome.

It is almost as if Chrome has decided to redirect away to the link in the anchor before completing the JavaScript execution. I am not experiencing this problem in IE or FF.

I've tried sticking a setTimeout after, and between, the calls but to no avail.

setTimeout('document.location="' + link.href + '"', 500);

解决方案

The issue is that Chrome (and other browsers) will cancel any pending image requests when a request for loading a new page in the current window is made. You've probably been lucky that the first _trackEvent request is getting recorded because of the extra processing going on during the second _trackEvent.

When adding a delay to a link, you need to make sure to keep the link's default action from executing -- otherwise the default action follows the link before the setTimeout function can occur.

The following code checks to see if the link is opening in a new window -- if not, it delays following the link by 150ms:

function track(link) {
  _gaq.push(['_trackEvent', 'Basket Remove', product_name, product_code, product_price, false]);          
  _gaq.push(['rollup._trackEvent', 'Basket Remove', product_name, product_code, product_price, false]);
  if ('_blank' == link.target) return true;
  var url = link.href;
  setTimeout(function(){ document.location = url; }, 150);
  return false;
}

<a href="someURL" onclick="return track(this);">ClickMe</a>

这篇关于Google Analytics(分析)事件跟踪只能在Chrome上启用多个帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆