Magento Fix for Google Analytics – Not Tracking – Not Receiving Data

  • Share
  • Share

Recently google had changed there tracking code.
You will need to make some modify before your site it back in track with Google Analytics.

Here’s what you will need to do.
create the folder structure like the following
/app/code/local/Mage/GoogleAnalytics/Block/

Then copy the file from /app/code/core/Mage/GoogleAnalytics/Block/Ga.php – by doing this step you will not alter the core of magento. Do like the following steps
Copy
/app/code/core/Mage/GoogleAnalytics/Block/Ga.php
Paste to
/app/code/local/Mage/GoogleAnalytics/Block/Ga.php

Then open up the file /app/code/local/Mage/GoogleAnalytics/Block/Ga.php, you will need to change to the latest Google Analytic JavaScript code to the following.
Please open up /app/code/local/Mage/GoogleAnalytics/Block/Ga.php
Goto line 171
Original code

$this->addText('
<!-- BEGIN GOOGLE ANALYTICS CODE -->
<script type="text/javascript">
//<![CDATA[
    (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);
    })();

    _gaq.push(["_setAccount", "' . $this->getAccount() . '"]);
    _gaq.push(["_trackPageview", "'.$this->getPageName().'"]);
//]]>
</script>
<!-- END GOOGLE ANALYTICS CODE -->
');

Please change it to the following

$this->addText('
<!-- BEGIN GOOGLE ANALYTICS CODE -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push([\'_setAccount\', \'' . $this->getAccount() . '\']);
_gaq.push([\'_trackPageview\']);
(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\';
var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>
<!-- END GOOGLE ANALYTICS CODE -->
');

Here’s the second step, do this step only if the google analytics tracking code are not presented in your theme. Do a quick search on your page source code. See if the google analytic are showing up or not. If it is not presented, you will need to do the following step to fix the problem.
Copy the file /app/design/frontend/base/default/layout/googleanalytics.xml
to your default theme folder /app/design/frontend/default/default/layout/googleanalytics.xml

And changed the code of this page from
Original Code

<reference name="after_body_start">
     <block type="googleanalytics/ga" name="google_analytics" as="google_analytics" />
</reference>

Replace with the following code

<reference name="before_body_end">
     <block type="googleanalytics/ga" name="google_analytics" as="google_analytics" />
</reference>
Related Posts Plugin for WordPress, Blogger...

I hope you have enjoyed this post, be sure to subscribe to my rss feed by click the subscribe button at the top.

Good Luck!

Be Sure to Subscribe to our feed or follow us on twitter to get the latest updates/patches
End of Article, Thanks for reading.
You can leave a response, or trackback from your own site.

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

4 Responses to “Magento Fix for Google Analytics – Not Tracking – Not Receiving Data

  1. jordi says:

    Thx for the code…

    After i changed the code i cant see my e-commerce tracking on analytics. Do you have any solution for thís?

    Thx!

  2. I just saw your web page on About.com its a fantastic web page you have accomplished a fantastic job I will surely come back Thanks!

  3. william says:

    Enable Google analytics in System/configeratiuon/advanced. – enable it :)

  4. Brian says:

    Helped a lot – Couldn't figure out why GA wasn't tracking anymore. Thanks much.

Leave a Reply