Magento – Magento 1.9 Google Analytics template not loading

google analyticstemplatetemplate-directive

Why isn't my ga.phtml file loading on the live site (but does load on my dev site)?

After upgrading from 1.6 to 1.9, my Magento site has stopped tracking in Google Analytics.

After doing some troubleshooting, I've gotten stuck.

I can prove that the ga.phtml template is not loading, but I cannot sort out why. To be complete, I will provide as much background as seems relevant:

  1. The Analytics is configured properly in System => Configuration => Sales => Google APIGoogle Analytics Settings

  2. The googleanalytics.xml file (located at app/design/frontend/[my_package]/[my_theme]/layout/googleanalytics.xml) is correct (from another answer here: https://magento.stackexchange.com/a/80566/3286)

    <!--
    Default layout, loads most of the pages
    -->
    
    <default>
        <!-- Mage_GoogleAnalytics -->
        <reference name="head" before="-">
            <block type="googleanalytics/ga" name="google_analytics" as="google_analytics" template="googleanalytics/ga.phtml" />
        </reference>
    </default>
    

  3. The ga.phtml template is in the correct location, and I have added an HTML comment that should get rendered any time the template gets loaded. (The template is here: app/design/frontend/[my_package]/[my_theme]/template/ga.phtml)

  4. I have confirmed that all of the theme templates include the relevant <?php echo $this->getChildHtml('after_body_start') ?> and <?php echo $this->getChildHtml('before_body_end') ?> calls.

  5. The "Cookie Restriction Mode" is set to "No" (in System => Configuration => General => Web => Session Cookie Management)

  6. Lastly – and this is the real twist – this is all working (and the ga.phtml is loading properly) on my local dev machine, but it does NOT load on the live site.

What am I missing? Is there a configuration or other setting that I need to check for?

Best Answer

So, after much research, I found the specific answer that took care of this.

NOTE: Many answers I had previously tried included altering the layout file, but this one noteably had the reference name set to after_body_start, whereas others I had tried utilized head.

In the layout file app/frontend/[package]/[theme]/layout/googleanalytics.xml:

<layout version="0.1.0">
  <default>
    <reference name="after_body_start">
      <block type="googleanalytics/ga" name="google_analytics" as="google_analytics" template="googleanalytics/ga.phtml" />
    </reference>
  </default>
</layout>
Related Topic