Search This Blog

Friday 28 September 2012

Magento: Move Google Analytics code to head tag

To move the GA code from after <body> tag  to before closing </head> tag involves following two steps:

Step 1:
Add the following code with in the <block type="page/html_head" name="head" as="head"> tag in app\design\frontend\base\default\layout\page.xml

<block type="core/text_list" name="before_head_end" as="before_head_end" translate="label">
 <label>Page Top</label>
</block>

Step 2:
Now open app\design\frontend\base\default\layout\googleanalytics.xml file and replace
after_body_start

With

before_head_end


Note: Make sure you enabled GA in admin section Magento: Setting Up Google Analytics + eCommerce Tracking

If the changes not reflecting then refresh the Magento cache and check.....

3 comments:

  1. Nice!

    Thank you

    ReplyDelete
  2. Thank you!!!!! Very helpful - not sure what Magento is thinking here - as if they are above Google....hmm.....

    ReplyDelete
  3. Great post!

    Works for me! :D

    Thank you!

    ReplyDelete