Is it worth making a few website improvements or completely redesigning the entire website? Depends...we chose website improvements.
Google Analytics Not Working With Magento
We 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.
- Open /app/design/frontend/default/yourtemplate/page/html/head.phtml
- 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') ?>';
- Refresh your Magento Cache
- 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
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.
Thank you Melissa. Your clarification is very helpful.
Thanks everyone. you all saved us a lot of time and headaches….Great tips
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!
Got the same problem with one for my client.
Followed your instructions and waiting for tracking results. 🙂
I hope almost solved. Thanks for sharing.