简体   繁体   中英

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. 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:

<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. 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:

在此处输入图片说明

In the oval above I am providing the [Transaction ID] but it is not found as you can see. I have found many cases in my database where there are transactions that I cannot find in Google Analytics Ecommerce.

Google Analytics is showing some transactions but not all of them. I examined the code sent to Google Analytics and it is correct, no syntax errors, everything is perfect. Why is the Google Analytics Ecommerce "Sales Performance" section missing transactions? Thank you.

UPDATE 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:

¡Lore T99 mi psumi ss E325 impl Dummyte Xtífthe + Printingand Typesetting (Iñd Ustrylore, Ips um Hasbee, Nthein) Dustr Ss Ttandar! (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] ?

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. That was causing the Google Analytics code to look like this:

<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. 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. 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. 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. If your code is not written in PHP, find an equivalent to the trim function in the programming language that you use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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