In a custom module I'm inserting universal analytics so I have to change a few functions from Ga.php
file
In Ga.php
there is:
class Mage_GoogleAnalytics_Block_Ga extends Mage_Core_Block_Template
{
//google analytics functions
}
If I do like this:
class Custom_Module_Block_Universalanalytics extends Mage_GoogleAnalytics_Block_Ga{
//a couple of functions that I change from Ga.php
}
it doesn't work.
But if I do like this:
class Custom_Module_Block_Universalanalytics extends Mage_Core_Block_Template{
//all functions from Ga.php plus the ones that I change
}
it does work.
So my question is why wouldn't it work if I extend the Mage_GoogleAnalytics_Block_Ga
class which already has all the functions?
Update: Here is my config.xml
<?xml version="1.0"?>
<config>
<modules>
<Custom_Module>
<version>0.1.0</version>
</Custom_Module>
</modules>
<global>
<blocks>
<universalanalytics>
<class>Custom_Module_Block</class>
</universalanalytics>
</blocks>
<helpers>
<universalanalytics>
<class>Custom_Module_Helper</class>
</universalanalytics>
</helpers>
<models>
<universalanalytics>
<class>Custom_Module_Model</class>
</universalanalytics>
</models>
</global>
<frontend>
<events>
<checkout_onepage_controller_success_action>
<observers>
<universalanalytics_order_success>
<class>universalanalytics/observer</class>
<method>setUniversalanalyticsOnOrderSuccessPageView</method>
</universalanalytics_order_success>
</observers>
</checkout_onepage_controller_success_action>
<checkout_multishipping_controller_success_action>
<observers>
<universalanalytics_order_success>
<class>universalanalytics/observer</class>
<method>setUniversalanalyticsOnOrderSuccessPageView</method>
</universalanalytics_order_success>
</observers>
</checkout_multishipping_controller_success_action>
</events>
<layout>
<updates>
<universalanalytics>
<file>universalanalytics.xml</file>
</universalanalytics>
</updates>
</layout>
</frontend>
</config>
Thanks!
Update: Folowing the comments, indeedthe issue is with this function:
protected function _toHtml(){
if (!Mage::helper('universalanalytics')->isUniversalanalyticsAvailable()) {
return '';
}
return parent::_toHtml();
}
Mage::helper('universalanalytics')->isUniversalanalyticsAvailable()
is returning true, but, as I read here https://stackoverflow.com/questions/11179732/overwritten-block-appears-in-addition-to-module-overwrite return parent::_toHtml();
will return the google classic analytics object.
Mage::helper('googleanalytics')->isGoogleAnalyticsAvailable())
is returningtrue
? If not, thetoHtml
function will return an empty string. – Mayers May 18 '15 at 10:06Mage::helper('universalanalytics')->isUniversalanalyticsAvailable()
which is returning true. I want the client to be able to control it from the admin. – Claudiu Creanga May 19 '15 at 7:55