Magento Analytics - Detect CategoryId & ProductId?
I have a custom tracking script which is recording things like Product and Category Page views. Because the script loads on every page, not all pages are category pages and would have a $categoryid OR a Product_View with a $productid.
What would be the best way to detect if $categoryid OR $productid exist in order to pass those values to the tracking script?
In the block you use to call the script use some logic after calling:
$category = Mage::registry('current_category'); //if null then not a category $category->getParentId(); //if null $catagory is a top level category $product = Mage::registry('current_product'); //if null then not a product $product = Mage::registry('product'); //if null then not a product
For more info check out: Magento: How to tell if you're on a category page, or product page in .phtml file(s)