I have a request from client where he wants to put google analytics code on different pages in Magento under footer.
I see that footer is generic, so is there a way to place a different code under footers for pages / create different footers?
footermagento-1.7template
I have a request from client where he wants to put google analytics code on different pages in Magento under footer.
I see that footer is generic, so is there a way to place a different code under footers for pages / create different footers?
Best Answer
This is a common problem: Adding something in the footer but only on some pages. Everything works perfectly as Alex suggested but only when the block cache is disabled. You can add a block to the footer on any page using layouts. For example adding something only on the home page can be done like this:
The problem occurs when you activate the block cache. The footer cache is general and does not take into account the page it's in.
Here is my general solution for this kind of problem. I override the footer block (
Mage_Page_Block_Html_Footer
) and change the cache key info. Let's say that my new footer block isEasylife_Page_Block_Html_Footer
, the methodgetCacheKeyInfo()
would look like this:Now in the layout section where I added the block to the footer I add a new line:
This solved all my issues for this kind of problem.