skip to Main Content

Google Analytics Not Working With Magento

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.

This Post Has 5 Comments

  1. 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.
    /app/design/frontend/default/yourtemplate/template/page/html/head.phtml

  2. 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!
    Thanks.
    Andy

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

Leave a Reply

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

Back To Top
Search