JS分析电子商务回调 [英] JS Analytics Ecommerce callback
问题描述
我无法在任何地方找到如何使用 hitCallback
参数与google analytics ecommerce:send
。在文档中,它的唯一示例是发送,pageview
。
I couldn't find anywhere how to use hitCallback
parameter with google analytics ecommerce:send
. In docs its only example is with send,pageview
.
以下是我试过的代码:
ga('ecommerce:send',
{'hitCallback': function() {window.location.href="/test.php";}}
);
但它不起作用,尽管跟踪工作。
but it didn't work although the tracking worked.
推荐答案
我遇到了同样的问题,并且查看了源代码,没有干净的方法来完成它。
I ran in to the same problem and, having looked at the source code, there's no clean way to do it.
关于 ga('ecommerce:send')
的内容是在内部调用 -
The thing about ga('ecommerce:send')
is that internally it calls -
- $
-
ga('send','transaction',{...})
li>ga('send','item',{...})
每个项目一次
ga('send', 'transaction', {...})
once for your transaction, thenga('send', 'item', {...})
once for each item
如果您 要等待
If you have to wait for your ecommerce:send
to complete you could do one of the following:
- 编写一个自定义
ecommerce.js
,让您可以传入hitCallback
功能或 - Google Analytics使用
< img />
标签发送数据如果它小于2KB。因此,您可以检查每个由JavaScript创建的< img />
标记,并且如果src
属性包含www.google-analytics.com然后等待它加载。
- Hack a custom
ecommerce.js
that allows you to pass in ahitCallback
function, or - 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 thesrc
attribute contains www.google-analytics.com then wait for it to load.
我已经成功使用了#2(请参阅 http://jsfiddle.net/zkQXX/ ),但它确实是一个破解。
I've actually used #2 successfully (see http://jsfiddle.net/zkQXX/), but it really is a hack.
这篇关于JS分析电子商务回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!