Google Analytics Event Tracking not firing for multiple accounts on Chrome ONLY

丶灬走出姿态 提交于 2019-12-05 21:52:39

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>

For those who arrived here and the proposed answer was not working for them:

What I did was placing the tracking code (i.e. _gaq.push() within the setTimeout function, and giving 1500ms as a parameter.

I work with analytics.js and my code looks like this:

setTimeout(function(){ga('send', 'event', 'click' , 'label',2);}, 1500);

So essentially, I do not interfere with the natural usage of my site with tracking. Rather report tracking after what the user did already happened.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!