views:

177

answers:

1

I'm having trouble getting Google Analytics to track transactions for commerce. Here's the code I'm generating on my order confirmation page.

I don't know how to debug this either, I can't find information on how to get error codes out of google's js. I'd run it in firebug's console if I could. At this point I'm stuck on how to proceed.

<script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-########-#']);
    _gaq.push(['_setDomainName', '.mydomain.com']);
    _gaq.push(['_trackPageview']);


    _gaq.push(['_addTrans',
      '117',           // order ID - required
      'StoreName.com',  // affiliation or store name
      '35.96',          // total - required
      '0',           // tax
      '0',              // shipping
      '',       // city
      '',     // state or province
      ''             // country
    ]);
    _gaq.push(['_addItem',
      '117',           // order ID - required
      '1',           // SKU/code - required
      '1 Pack',        // product name
      'Catagory5',          // catagory   
      '35.96,          // unit price - required
      '1'               // quantity - required
    ]);
    _gaq.push(['_trackTrans']);

  (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';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
  })();
</script>

Thank you for any suggestions.

+2  A: 

Checkout this page on Google Code. It provides an example of what your trying to do.

Binary Nerd
I'm using Google's newer async methods, but the ideas are the same. I'm currently doing the 3 steps that are required and listed on that page.
wizard
Your code looks good compared with the Google examples. You did turn eCommerce tracking on? :+) Also, did the non-async code work for you?
Binary Nerd
I will swap it out and check.
wizard
I was rebuilding my code to use the older system, and I found a typo.
wizard