JS Analytics Ecommerce callback

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 13:19:19

问题


I couldn't find anywhere how to use hitCallback parameter with google analytics ecommerce:send. In docs its only example is with send,pageview.

Here is the code I tried:

ga('ecommerce:send',
   {'hitCallback': function() {window.location.href="/test.php";}}
);

but it didn't work although the tracking worked.


回答1:


I ran in to the same problem and, having looked at the source code, there's no clean way to do it.

The thing about ga('ecommerce:send') is that internally it calls -

  • ga('send', 'transaction', {...}) once for your transaction, then
  • ga('send', 'item', {...}) once for each item

If you have to wait for your ecommerce:send to complete you could do one of the following:

  1. Hack a custom ecommerce.js that allows you to pass in a hitCallback function, or
  2. Google Analytics uses <img/> tags to send data if it's less than 2KB. So, you could check every <img/> tag that is created by JavaScript, and if the src attribute contains www.google-analytics.com then wait for it to load.

I've actually used #2 successfully (see http://jsfiddle.net/zkQXX/), but it really is a hack.




回答2:


As mentioned, hitCallback doesn't work for ecommerce:send. Craziness.

However, what I found (today at least) is that it does work for ecommerce:addTransaction and ecommerce:addItem (for when they are finally sent). Therefor you just have to make sure that all your hitCallbacks from those calls have been hit and then you're safe.



来源:https://stackoverflow.com/questions/18812345/js-analytics-ecommerce-callback

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