简体   繁体   中英

Setting a CMS Page Name in Magento for Google Analytics

In /app/code/core/Mage/GoogleAnalytics/Block/Ga.php line 88 makes reference to $this->getPageName() which is used in line 95 of the same script. While this makes sense in that if the page has a "Page Name" defined it will attach it to the Google Analytics code what I can not find is where in the Magento Admin or the page XML do I set this "Page Name" for a CMS page? In the notes on Ga.php it says "The custom "page name" may be set from layout or somewhere else. It must start from slash." but I don't see how I would do that.

When I asked this question to Magento Support they came back with "Look at our design guide" and no other information.

How do I set a Page Name for a CMS page in Magento Enterprise 1.12.0.2? Thanks!

It's not set anywhere by default. You could set it when you create the block in the layout xml using an action call eg:

<action method="setPageName"><name>blah/blahblah/foo.html</name></action>

You could set it in a controller by calling the setPageName() method on the block. Or you could just override the Mage_GoogleAnalytics_Block_Ga class and add your own custom functionality:

public function getPageName()
{
    if (!$this->hasData('page_name')) {
        $this->setPageName(Mage::getSingleton('core/url')->escape($_SERVER['REQUEST_URI']));
     }
    return $this->getData('page_name');
}

Another solution, based on Roscius version:

public function getPageName()
{
    if (!$this->hasData('page_name')) {
        $this->setPageName(str_replace(Mage::getStoreConfig('design/head/title_prefix'), '', $this->getLayout()->getBlock('head')->getTitle()));
     }
    return $this->getData('page_name');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM