我正在尝试扩展企业的GoogleAnalyticsUniversal模块块。一切都很好。我还通过布局文件添加了我的自定义模板,如下所示。
<layout version="0.1.0">
<default>
<!-- Remove Mage_GoogleAnalytics -->
<remove name="google_analytics" />
<reference name="head">
<action method="addJs" ifconfig="google/analytics/active"><script>google/ga.js</script></action>
</reference>
<reference name="after_body_start">
<reference name="content">
<block type="Test_Googleanalyticsuniversal/Ga" name="google_analyticsuniversal" as="google_analyticsuniversal"
template="googleanalyticsuniversal/ga.phtml" />
</reference>
</reference>
</default>
</layout>
我的Config.xml为:
<config>
<modules>
<Test_Googleanalyticsuniversal>
<version>0.0.1</version>
</Test_Googleanalyticsuniversal>
<depends>
<Enterprise_GoogleAnalyticsUniversal />
</depends>
</modules>
<global>
<helpers>
<enterprise_googleanalyticsuniversal>
<rewrite>
<data>Test_Googleanalyticsuniversal_Helper_Data</data>
</rewrite>
</enterprise_googleanalyticsuniversal>
</helpers>
<blocks>
<test_googleanalyticsuniversal>
<class>Test_Googleanalyticsuniversal_Block</class>
</test_googleanalyticsuniversal>
<enterprise_googleanalyticsuniversal>
<rewrite>
<ga>Test_Googleanalyticsuniversal_Block_Ga</ga>
</rewrite>
</enterprise_googleanalyticsuniversal>
</blocks>
</global>
<frontend>
<layout>
<updates>
<test_googleanalyticsuniversal>
<file>googleanalyticsuniversal.xml</file>
</test_googleanalyticsuniversal>
</updates>
</layout>
</frontend>
</config>
我阻止Ga.php为:
class Test_Googleanalyticsuniversal_Block_Ga extends Enterprise_GoogleAnalyticsUniversal_Block_Ga
{
protected function _getContainerSnippet()
{
// Get the container ID.
$containerId = Mage::helper('googleanalyticsuniversal')->isTagManagerId();
// Render the container snippet JavaScript.
return "<noscript><iframe src=\"//www.googletagmanager.com/ns.html?id=".$containerId."\"
height=\"0\" width=\"0\" style=\"display:none;visibility:hidden\"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','".$containerId."');</script>\n";
}
/**
* Generate JavaScript for the data layer.
*
* @return string|null
*/
protected function _getDataLayer()
{
// Initialise our data source.
$data = array();
$data = $data;
// Enable modules to add custom data to the data layer
$data_layer = new Varien_Object();
$data_layer->setData($data);
$data = $data_layer->getData();
// Generate the data layer JavaScript.
if (!empty($data)) return "<script>dataLayer = [".json_encode($data)."];</script>\n\n";
else return '';
}
}
但是当我运行前端时,它在Exception.log中给出了以下错误..
exception 'Mage_Core_Exception' with message 'Invalid block type: Mage_Test_Googleanalyticsuniversal_Block_Ga' in /var/www/tbstr-dev/html/app/Mage.php:595
Stack trace:
#0 /var/www/tbstr-dev/html/app/code/core/Mage/Core/Model/Layout.php(495): Mage::throwException('Invalid block t...')
#1 /var/www/tbstr-dev/html/app/code/core/Mage/Core/Model/Layout.php(437): Mage_Core_Model_Layout->_getBlockInstance('Alshaya_Googlea...', Array)
#2 /var/www/tbstr-dev/html/app/code/core/Mage/Core/Model/Layout.php(472): Mage_Core_Model_Layout->createBlock('Alshaya_Googlea...', 'google_analytic...')
#3 /var/www/tbstr-dev/html/app/code/core/Mage/Core/Model/Layout.php(239): Mage_Core_Model_Layout->addBlock('Alshaya_Googlea...', 'google_analytic...')
#4 /var/www/tbstr-dev/html/app/code/core/Mage/Core/Model/Layout.php(205): Mage_Core_Model_Layout->_generateBlock(Object(Mage_Core_Model_Layout_Element), Object(Mage_Core_Model_Layout_Element))
#5 /var/www/tbstr-dev/html/app/code/core/Mage/Core/Model/Layout.php(210): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
#6 /var/www/tbstr-dev/html/app/code/core/Mage/Core/Model/Layout.php(210): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
#7 /var/www/tbstr-dev/html/app/code/core/Mage/Core/Controller/Varien/Action.php(344): Mage_Core_Model_Layout->generateBlocks()
#8 /var/www/tbstr-dev/html/app/code/core/Mage/Catalog/controllers/CategoryController.php(148): Mage_Core_Controller_Varien_Action->generateLayoutBlocks()
#9 /var/www/tbstr-dev/html/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Catalog_CategoryController->viewAction()
#10 /var/www/tbstr-dev/html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('view')
#11 /var/www/tbstr-dev/html/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#12 /var/www/tbstr-dev/html/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#13 /var/www/tbstr-dev/html/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#14 /var/www/tbstr-dev/html/index.php(83): Mage::run('', 'store')
#15 {main}
在日志中,它会在Mage
Test_Googleanalyticsuniversal_Block_Ga
之前添加额外的Mage_Test_Googleanalyticsuniversal_Block_Ga
关键字...
我尝试将googleanalytics.xml中的布局块类型修改为许多不同的方法。但没有成功。所以有人可以就此提出建议。