Magento News

 

Determine if on product page programmatically in Magento

I want to insert tracking codes on all of the pages of a Magento site, and need to use a different syntax if the page is a CMS page, a category browsing page, or a product view page. I have a custom module set up with a block that inserts a generic tracking code on each page for now. From within the block, how can I distinguish between CMS pages, category pages, and product pages?

I started with:

Mage::app()->getRequest();

I can see that

Mage::app()->getRequest()->getParam('id');

returns the product or category ID on product and category pages, but doesn’t distinguish between those page types.

Mage::app()->getRequest()->getRouteName();

return “cms” for CMS pages, but returns “catalog” for both category browsing and product view pages, so I can’t use that to tell category and product pages apart.

Is there some indicator in the request I can use safely? Or is there a better way to accomplish my goal of different tracking codes for different page types?

Determine if on product page programmatically in Magento

Possibly Related Posts:


 

Leave a Reply