JS分析电子商务回调 [英] JS Analytics Ecommerce callback

查看:119
本文介绍了JS分析电子商务回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在任何地方找到如何使用 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, then
  • ga('send', 'item', {...}) once for each item

如果您 要等待 ecommerce:send 完成,您可以执行以下任一操作: p>

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


  1. 编写一个自定义 ecommerce.js ,让您可以传入 hitCallback 功能或

  2. Google Analytics使用< img /> 标签发送数据如果它小于2KB。因此,您可以检查每个由JavaScript创建的< img /> 标记,并且如果 src 属性包含www.google-analytics.com然后等待它加载。

  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.

我已经成功使用了#2(请参阅 http://jsfiddle.net/zkQXX/ ),但它确实是一个破解。

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

这篇关于JS分析电子商务回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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