简体   繁体   English

Google Analytics(分析)电子商务中的数据丢失

[英]Missing data in Google Analytics Ecommerce

When I compare transactions in my production database with transactions in the Google Analytics Ecommerce dashboard, it is evident that I am missing a significant amount of data. 当我将生产数据库中的交易与Google Analytics(分析)电子商务面板中的交易进行比较时,很明显我丢失了大量数据。 I made a purchase for testing purposes in my website and in the "Thank you page" that appears after a successful purchase, I saw the following Google Analytics tracking code when I inspected the element: 我在网站上进行购买是为了进行测试,并且在购买成功后出现的“谢谢页面”中,我在检查该元素时看到以下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>

This transaction took place about 24 hours ago. 此交易大约在24小时前进行。 When I go to the Google Analytics Ecommerce dashboard, to the "Sales Performance" section, when I look for a transaction with the ID that I sent in 'id': '[Transaction ID]' above, I cannot find that transaction: 当我转到Google Analytics(分析)电子商务信息中心的“销售业绩”部分时,当我查找具有在上面'id': '[Transaction ID]'发送'id': '[Transaction ID]' ,找不到该交易:

在此处输入图片说明

In the oval above I am providing the [Transaction ID] but it is not found as you can see. 在上面的椭圆中,我提供了[交易ID],但您找不到它。 I have found many cases in my database where there are transactions that I cannot find in Google Analytics Ecommerce. 我在数据库中发现很多情况,其中有些交易在Google Analytics(分析)电子商务中找不到。

Google Analytics is showing some transactions but not all of them. Google Analytics(分析)显示了一些交易,但不是全部。 I examined the code sent to Google Analytics and it is correct, no syntax errors, everything is perfect. 我检查了发送给Google Analytics(分析)的代码,它是正确的,没有语法错误,一切都很完美。 Why is the Google Analytics Ecommerce "Sales Performance" section missing transactions? 为什么Google Analytics(分析)电子商务的“销售业绩”部分缺少交易? Thank you. 谢谢。

UPDATE 1: 更新1:

For 'name': '[Product name]' , I am sending as the [Product name] a string of 145 B. To give you an idea, it would be approximately this long: 对于'name': '[Product name]' ,我将[Product name]字符串145 B发送给您。大概有这么长的时间:

¡Lore T99 mi psumi ss E325 impl Dummyte Xtífthe + Printingand Typesetting (Iñd Ustrylore, Ips um Hasbee, Nthein) Dustr Ss Ttandar! ¡在T99 mi psumi ss E325上启用DummyteXtífthe+印刷和排版(Id Ustrylore,Ips um Hasbee,Nthein)Dustr Ss Ttandar! (2018-01-05) (2018-01-05)

The text contains the following special characters: 文本包含以下特殊字符:

  1. ¡ ¡
  2. í 一世
  3. + +
  4. (
  5. ñ ñ
  6. ,
  7. )
  8. !
  9. - --

Is the length the problem (145 B), or the fact that I am sending special characters in the [Product name] ? 长度是问题所在(145 B),还是我在[Product name]发送特殊字符的事实?

The problem was that I was taking [Product category] from a database, and to my surprise many of those values had an empty line after the string. 问题是我从数据库中提取了[Product category] ,令我惊讶的是,其中许多值在字符串后都有一个空行。 That was causing the Google Analytics code to look like this: 这导致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>

Notice how [Product category] does not appear in a single line. 请注意[Product category]不会出现在一行中。 That was the cause of the problem. 这就是问题的原因。 Surely that was interpreted as a JavaScript syntax error and Google Analytics never processed that entry, which would be a synonym of not running the Google Analytics script. 当然,这被解释为JavaScript语法错误,并且Google Analytics(分析)从未处理过该条目,这就是不运行Google Analytics(分析)脚本的同义词。 The fix was to remove those unnecessary lines from my database. 解决方法是从数据库中删除那些不必要的行。 Alternatively, if you are using PHP for instance, you could use the PHP trim function ("Strip whitespace (or other characters) from the beginning and end of a string": http://php.net/manual/en/function.trim.php ) so that your PHP code takes care of fixing those extra lines at the end of the category names. 另外,例如,如果您使用的是PHP,则可以使用PHP修剪函数(“从字符串的开头和结尾开始的带空格(或其他字符)”): http : //php.net/manual/en/function。 trim.php ),以便您的PHP代码可以在类别名称的末尾修复这些多余的行。 But I think the best approach would be to fix the category names in your database because otherwise a similar situation could potentially cause similar errors in other APIs or scripts that you have today or write in the future. 但是我认为最好的方法是修复数据库中的类别名称,因为否则类似的情况可能会导致您今天或将来编写的其他API或脚本中出现类似的错误。 If your code is not written in PHP, find an equivalent to the trim function in the programming language that you use. 如果您的代码不是用PHP编写的,请在您使用的编程语言中找到与trim函数等效的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM