Custom Web Designs by Bay Area Web Design Company MJS Web Solutions Building Websites That Can
   Actually be Found
Contact Us | Our Company | Home
510.523.7312
MJS Web Solutions Blog
Thoughts :: Opinions :: Trends

Monday, May 17, 2010
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.

Posted by: Michael Swartz at 4:55 pm

Comments: 5 Comments | Filed under: HTML, SEO, Web Design

5 Comments Add your own

  1. Melissa says:

    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

    Posted on: November 23rd, 2010 at 3:14 am
  2. Thank you Melissa. Your clarification is very helpful.

    Posted on: November 23rd, 2010 at 8:47 am
  3. Pablo says:

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

    Posted on: January 17th, 2011 at 7:49 am
  4. AndyW says:

    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

    Posted on: May 18th, 2011 at 2:07 pm
  5. Ravi says:

    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

    Posted on: December 22nd, 2011 at 3:58 am

Leave a Comment

Required
Required, hidden
Comment moderation is in use. Please do not submit your comment twice -- it will appear shortly.

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Support  |  Partners  |  Site Map
Alameda Chamber of Commerce Member
West Alameda Business Association Member (WABA)
© Copyright 2012 MJS Web Solutions Blog. All rights reserved.
Powered by Westhost and WordPress.
Log in