【问题标题】:Missing data in Google Analytics EcommerceGoogle Analytics(分析)电子商务中缺少数据
【发布时间】:2018-01-19 20:35:15
【问题描述】:

当我将生产数据库中的交易与 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 查找交易时,我找不到该交易:

在上面的椭圆中,我提供了 [Transaction ID],但如您所见,它没有找到。我在我的数据库中发现了很多案例,其中有些交易在 Google Analytics(分析)电子商务中找不到。

Google Analytics(分析)显示了一些交易,但不是全部。我检查了发送到 Google Analytics 的代码,它是正确的,没有语法错误,一切都很完美。为什么 Google Analytics(分析)电子商务“销售业绩”部分缺少交易?谢谢。

更新 1:

对于'name': '[Product name]',我将作为[Product name] 发送一个145 B 的字符串。给你一个想法,它大约有这么长:

¡ Lore T99 mi psumi ss E325 impl Dummyte Xtífthe + Printingand 排版 (Iñd Ustrylore, Ips um Hasbee, Nthein) Dustr Ss Ttandar! (2018-01-05)

文本包含以下特殊字符:

  1. ¡
  2. +
  3. (
  4. ñ
  5. ,
  6. )
  7. -

是长度问题(145 B),还是我在[Product name]中发送特殊字符的事实?

【问题讨论】:

标签: google-analytics transactions


【解决方案1】:

问题是我从数据库中获取[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 trim 函数(“从字符串的开头和结尾去除空格(或其他字符)”:http://php.net/manual/en/function.trim.php)以便您的 PHP 代码负责修复这些类别名称末尾的额外行。但我认为最好的方法是修复数据库中的类别名称,否则类似的情况可能会在您今天拥有或将来编写的其他 API 或脚本中导致类似的错误。如果您的代码不是用 PHP 编写的,请在您使用的编程语言中找到与 trim 函数等效的函数。

【讨论】:

    猜你喜欢
    • 2011-08-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-11
    • 1970-01-01
    • 2011-05-21
    • 2017-10-09
    • 2015-08-01
    • 2014-09-17
    相关资源
    最近更新 更多