Magento LogoWe were having a heck of a time trying to figure out why Google Analytics wasn’t capturing any data with a new Magento eCommerce (V 4.1) website we just built.

We added the Google Analytics account ID within the admin area, but no results.

We then noticed the error:  _gaq is not defined being displayed from the browser.

Searching through the Magento community, Google search and blogs we were given various fixes and advice that suggested replacing the original code or updating the Magento core files. We did not want to change the existing code or core files because we wanted our client to be able to use the eCommerce portion of Google Analytics with Magento and we’re suspect about some of the fixes.

So we took matters into our own hands.

Since the error was not being defined, we defined it.

  1. Open /app/design/frontend/default/yourtemplate/page/html/head.phtml
  2. Add the code var _gaq = _gaq || []; on line #38 to the head tag of the head.phtml file after var BLANK_IMG = '<?php echo $this->helper('core/js')->getJsUrl('spacer.gif') ?>';
  3. Refresh your Magento Cache
  4. In a few hours Google Analytics should start registering your data.

I hope this helps others who may be experiencing the same issue.


  1. Reply


    November 23, 2010

    Hi, great workaround for the GA fix.
    I just wanted to clarify if they are using a template other than magento’s free templates here is where I had to go many times to fix it.

  2. Reply

    Michael Swartz

    November 23, 2010

    Thank you Melissa. Your clarification is very helpful.

  3. Reply


    January 17, 2011

    Thanks everyone. you all saved us a lot of time and headaches….Great tips

  4. Reply


    May 18, 2011

    I thought I was going mad, as you assume stable products don’t have major bugs like this.
    But close inspection of the Google snippet in the source showed that my client’s site has exactly this problem!

  5. Reply


    December 22, 2011

    Got the same problem with one for my client.

    Followed your instructions and waiting for tracking results. 🙂

    I hope almost solved. Thanks for sharing.

    – Ravi

Would you like to share your thoughts?

Your email address will not be published. Required fields are marked *

© 2018 MJS Web Solutions. All rights reserved.