Add Stats Script Code before Closing in Magento

Not surprisingly, most people believe the right way to do this is to find the *footer* template in the Magento theme and then include the analytics code at the end of the file. While this approach works, it’s not the best, because it’s NOT immediately before </body></html>.

What if you really need to add the code IMMEDIATELY before the page closing tags </body></html>?

Add code immediately before </body></html> in your Magento store

The best intended approach is to supply the code in your Magento System Configuration. Just go to:

System -> Configuration -> Design -> Footer.

Here you will find a textarea field that readsĀ Miscellaneous HTML. Just put the analytics code there and it will appear immediately before the closing </body></html> on every page of your Magento store.

Similarly, add code immediately before closing </head>

Follow the configuration path:

System -> Configuration -> Design -> HTML Head

And you will find a textarea field namedĀ Miscellaneous Scripts. Just put any head meta or scripts code there and they will appear immediately before </head> on every page of your Magento store.