Google Analytics电子商务中缺少数据

时间:2018-01-19 20:35:15

标签: google-analytics transactions

当我将生产数据库中的交易与Google Analytics电子商务信息中心中的交易进行比较时,很明显我错失了大量数据。我在我的网站和购买成功后出现的“谢谢页面”中进行了测试购买,我在检查元素时看到了以下Google Analytics跟踪代码:

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '[My Google Analytics tracking ID]', 'auto');
ga('require', 'ec');
ga('ec:addProduct', {
'id': '[Product ID]', 'name': '[Product name]', 'category': '[Product category]',
'brand': '[Product brand]', 'variant': '[Product variant]', 'price': '[Product price]', 'quantity': 1 });

// Transaction level information is provided via an actionFieldObject.
ga('ec:setAction', 'purchase', { 'id': '[Transaction ID]', 'affiliation': '[Organization where the transaction took place]', 'revenue': '[Revenue value]' });
ga('send', 'pageview');
</script>

此交易发生在大约24小时前。当我转到Google Analytics电子商务信息中心时,转到“销售效果”部分,当我查找具有我在上面'id': '[Transaction ID]'中发送的ID的交易时,我找不到该交易:

enter image description here

在上面的椭圆形中,我提供了[交易ID]但是找不到它。我在我的数据库中发现了很多案例,其中存在我在Google Analytics电子商务中找不到的交易。

Google Analytics正在展示一些交易,但不是全部。我查看了发送到Google Analytics的代码,这是正确的,没有语法错误,一切都很完美。为什么Google Analytics电子商务“销售效果”部分缺少交易?谢谢。

更新1:

对于'name': '[Product name]',我发送的是[Product name]一个145 B的字符串。为了给你一个想法,这将是这么长的时间:

  

¡Lore T99 mi psumi ss E325 impl DummyteXtífthe+ Printingand   排版(IñdBustrylore,Ips um Hasbee,Nthein)Dustr Ss Ttandar!   (2018年1月5日)

该文本包含以下特殊字符:

  1. ¡
  2. I
  3. +
  4. ñ
  5. <!/ LI>
  6. -
  7. 长度是问题(145 B),还是我在[Product name]发送特殊字符的事实?

1 个答案:

答案 0 :(得分:0)

问题是我从数据库中获取[Product category],令我惊讶的是,这些值中的许多值在字符串后面都有一个空行。这导致Google Analytics代码如下所示:

<script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
    ga('create', '[My Google Analytics tracking ID]', 'auto');
    ga('require', 'ec');
    ga('ec:addProduct', {
    'id': '[Product ID]', 'name': '[Product name]', 'category': '[Product category]
    ',
    'brand': '[Product brand]', 'variant': '[Product variant]', 'price': '[Product price]', 'quantity': 1 });

    // Transaction level information is provided via an actionFieldObject.
    ga('ec:setAction', 'purchase', { 'id': '[Transaction ID]', 'affiliation': '[Organization where the transaction took place]', 'revenue': '[Revenue value]' });
    ga('send', 'pageview');
</script>

请注意[Product category]如何不出现在一行中。这就是问题的原因。当然,这被解释为JavaScript语法错误,Google Analytics从未处理过该条目,这将是未运行Google Analytics脚本的同义词。修复是从我的数据库中删除那些不必要的行。或者,如果你正在使用PHP,你可以使用PHP修剪函数(&#34;从字符串的开头和结尾开始删除空格(或其他字符)&#34;:http://php.net/manual/en/function.trim.php)以便你的PHP代码负责在类别名称的末尾修复这些额外的行。但我认为最好的方法是修复数据库中的类别名称,因为否则类似的情况可能会导致您今天或将来编写的其他API或脚本中出现类似错误。如果您的代码不是用PHP编写的,请使用您使用的编程语言中的trim函数等效。