The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Missing transactions in Google Analytics

wcrookwcrook Member
in Help edited July 2013
Specific Problem: I'm having some trouble with some transactions not showing up properly in Google Analytics. On June 28th, 6 transactions came through on our account in Foxycart, but only 4 of them made it over to Google Analytics. So it appears that for some, the tracking code is pushing the necessary info over, but not for all. Any ideas?

Name/Domain: http://whooptee.foxycart.com/
Comments
  • fc_adamfc_adam FoxyCart Team
    @wcrook,

    I see you're also tracking sales in iDevAffiliate - did it work for those sales you're missing?
  • wcrookwcrook Member
    @fc_adam,

    Thanks - the iDevAffiliate is only tracking affiliate links, so it will only contain a subset of the total transactions, while those orders/links which came in organically would be missed. So it looks like iDev -like Google in this case - is an unreliable source for the real number/amounts of the orders.
  • wcrookwcrook Member
    Google suggests placing the "addTrans", "addItem", and "trackTrans" methods immediately following the "trackPageview" chunk of code. Could the separation of the two (as it appear to be implemented on our receipt page) cause any trouble?

    Here's an example I found on Google's site (https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce):

    Code Example (Bread, Meat, then Bread):
    <script type="text/javascript">
    
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-XXXXX-X']);
      _gaq.push(['_trackPageview']);
      _gaq.push(['_addTrans',
        '1234',           // transaction ID - required
        'Acme Clothing',  // affiliation or store name
        '11.99',          // total - required
        '1.29',           // tax
        '5',              // shipping
        'San Jose',       // city
        'California',     // state or province
        'USA'             // country
      ]);
      _gaq.push(['_addItem',
        '1234',           // transaction ID - required
        'DD44',           // SKU/code - required
        'T-Shirt',        // product name
        'Green Medium',   // category or variation
        '11.99',          // unit price - required
        '1'               // quantity - required
      ]);
      _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
    
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
    
    </script>
    
    

    I see on our FoxyCart receipt page that the first part loads with the second part (i.e. just the two slices of bread in our hypothetical code sandwich):
    <!--//--><![CDATA[// ><!--
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-XXXXX-X']);
      _gaq.push(['_trackPageview']);
    
       // SHOULD THE "MEAT" BE HERE?
    
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
    //--><!]]>
    

    ...but then another 100 or so lines (including calls to over a dozen other javascripts) are loaded before the "addTrans", "addItem", and "trackTrans" methods are called.

    Could this dislocation of the "meat" of our code "sandwich" cause problems, such as allowing time for a user to potentially browse away before Google gets what it needs to track the transaction? If so, is there something we can do on our side to remedy the issue?

    Thanks,

    Wesley
  • fc_adamfc_adam FoxyCart Team
    @wcrook,

    It's possible that that is the case, that the customer closed the page before everything could finish loading, although I would assume most people would spend at least a little time looking over the data.

    One thing you could do is simply move your 'receipt_only' block to be right after the 'body' tag in your template, so it loads as one of the first things on the page, that would at least make it's execution happen sooner.

    For what it's worth, from what I understand, you don't need to have the addTrans/addItem stuff right in that script block. It's simply making sure that the code gets run. The way Google Analytics works currently is it passes the data across to their servers by loading an image with the data as a parameter of the image URL. That can be blocked simply by closing the window before it happens, or in some browsers clicking a URL while the image is loading. So by including it right after the trackPageview, or even just after that block as a whole, it just makes sure that if one happens, the other should happen too.

    The issue you have though is you need to make sure the ecommerce stuff is only tracked on first load of the receipt - so it needs to be within the receipt_only block. I'm pretty sure you can only include that block once, so you while you have images in there, you'll need to put that within the body tag of your page. If you upgrade to 1.0 or newer, you could use the Twig conditional tags to specify it multiple times on the page and split the ecommerce tracking stuff from the image tags.
Sign In or Register to comment.