Amsive

PUBLISHED: Jul 2, 2010 1 min read

FIX Google Analytics _gaq is not defined In Magento 1.4.0.1

Tom DiDomenico

Tom DiDomenico

Senior Vice President, Digital Strategy & Technology

Locate: /app/design/frontend/base/default/layout/googleanalytics.xml

Replace With:

<default>
<!-- Mage_GoogleAnalytics -->
<reference name="before_body_end">
<block type="googleanalytics/ga" name="google_analytics" as="google_analytics" />
</reference>
</default>
</layout>

^ This will move the Google Analytics code to before the closing of the HTML </body> tag (for faster page load times)

Locate: /app/code/core/Mage/GoogleAnalytics/Block/ga.php

Replace at around LINE 171:

<!-- BEGIN GOOGLE ANALYTICS CODE -->
<script type="text/javascript">
//<![CDATA[
var _gaq = _gaq || [];
_gaq.push(["_setAccount", "' . $this->getAccount() . '"]);
_gaq.push(["_trackPageview", "'.$this->getPageName().'"]);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();

//]]>
</script>
<!-- END GOOGLE ANALYTICS CODE -->
Share: