0

gaq_push is not defined: Google Analytics error

I've implement the new "Async" Google Analytics Snippet. Here is the snippet:

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

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>

On my order page, I'm tracking transactions like so:

    <!-- google receipt begin -->
    <script language="JavaScript" type="text/javascript">
    // total transaction
    gaq_push._addTrans(      
    "[[DMI:Expression value='((Order)Container.DataItem).OrderNumber']][[/DMI:Expression]]", // order ID - required      
    "A.M. Leonard", // affiliation or store name      
    "[[DMI:Expression value='((Order)Container.DataItem).ItemTotal.ToString("0.00")']][[/DMI:Expression]]", // total - required      
    "[[DMI:Expression value='((Order)Container.DataItem).Tax.ToString("0.00")' ]][[/DMI:Expression]]", // tax      
    "[[DMI:Expression value='((Order)Container.DataItem).ShippingCost.ToString("0.00")' ]][[/DMI:Expression]]", // shipping      
    "[[DMI:Expression value='((Order)Container.DataItem).ShippingInfos[0].Address.City' ]][[/DMI:Expression]]", // city      
    "[[DMI:Expression value='((Order)Container.DataItem).ShippingInfos[0].Address.State' ]][[/DMI:Expression]]", // state or province      
    "[[DMI:Expression value='((Order)Container.DataItem).ShippingInfos[0].Address.Country' ]][[/DMI:Expression]]" // country    
    );          
    // all items 
    [[DMI:Use dmisource='((Order)Container.DataItem).Items']]
    gaq_push._addItem(      
    "[[DMI:Expression value='((OrderItem)Container.DataItem).OrderNumber' ]][[/DMI:Expression]]", // order ID - necessary to associate item with transaction      
    "[[DMI:Expression value='((OrderItem)Container.DataItem).Sku' ]][[/DMI:Expression]]", // SKU/code - required      
    "[[DMI:Expression value='Core.URLEncode(((OrderItem)Container.DataItem).ProductName)' ]][[/DMI:Expression]]", // product name      
    "", // category or variation      
    "[[DMI:Expression value='((OrderItem)Container.DataItem).UnitPrice.ToString("0.00")' ]][[/DMI:Expression]]", // unit price - required      
    "[[DMI:Expression value='((OrderItem)Container.DataItem).QtyOrdered' ]][[/DMI:Expression]]" // quantity - required   
    );   
    [[/DMI:Use]]        
    gaq_push._trackTrans(); //submits transaction to the analytics servers       
    </script>
    <!-- google receipt end -->

However,I am receiving an error that says: Uncaught ReferenceError: gaq_push is not defined

The DMI:Expression code is internal API code used for passing variables. As you can see, I'm passing in stuff like ItemTotal,Tax, etc. etc.

However, I believe the error is in the Transaction Tracking area. Any ideas?

  • Are you placing your scripts in the right order and right pages? – Caner Akdeniz Oct 10 '13 at 14:35
  • The GA Snippet is before the transaction tracking snippet. The GA Snippet is Async though. –  Oct 10 '13 at 14:43
  • 1
    I don't get it - why would gaq_push (gaq underscore push) ever be defined by Google Analytics ? gaq is an object, push is a method for this object which is called with the dot notation (_gaq.push). gaq_push is just some arbitrary variable name which is not defined by GA and apparently nowhere else on your website. – Eike Pierstorff Oct 11 '13 at 09:29

2 Answers2

0

You're receiving that error because gaq is not defined in your GA ecommerce script.

Per the (Google Analytics async ecommerce tracking)[https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce] page, you should be declaring gaq, setting the account, and sending a track pageview.

Blexy
  • 9,573
  • 6
  • 42
  • 55
0

Most tracking snippets include this line:

var _gaq = _gaq || [];

It ensures that _gaq.push() etc. is defined, whether or not GA is fully loaded.

See this related question: What is "var _gaq = _gaq || []; " for?

Community
  • 1
  • 1
lzimmerman
  • 16
  • 1