3

In our specific situation, we are seeing duplicate tracking code blocks with Fooman Google Analytics+ with Magento Enterprise 1.13.1.0 (see code below). I assume Fooman should be overwriting the default tracking code block -- but it's not doing that. Outside modifying core code OR the fooman module, what is the best practice way to remove a default block?

== BEGIN GOOGLE ANALYTICS ==
google tracking code here.
== END GOOGLE ANALYTICS == 

== BEGIN GOOGLE ANALYTICS ==
google tracking code here.
== END GOOGLE ANALYTICS == 
4
  • I'm emailing them a link to the question.. Fooman Modules seem almost like Core files in the Magento Community and this seems like a question that might benefit other. However you're right.. Maybe I should rewrite the question to be more general?? The bigger question has to do with removing core blocks.. right? – JustinP Mar 13 '14 at 14:26
  • 1
    I'm normally very fast with closing this questions but I know fooman is here too, so if he answers the questions I would let them open... – Fabian Blechschmidt Mar 13 '14 at 15:06
  • 1
    @Fabian if you want to feel better about the question, you can replace Fooman with any plugin that adds blocks and outputs content. I think PhilB's answer can be used in other cases as well. – Emi Mar 13 '14 at 15:14
  • Thank you guys. in the future -- I'll stick to phrasing questions in more generic scenarios. Appreciate everyone's leniency. I was also aware Fooman trolls these waters but I appreciate the by-laws and understand they'll make this forum a better place. – JustinP Mar 13 '14 at 15:56
4

Check to see if the Fooman extension adds a layout file. More than likely, it is adding a second block that is also generating the analytics you reference. Once you find it, you can reconcile the blocks.

Solution 1:

Assuming you are using some kind of custom package, you could copy googleanalytics.xml from /app/design/frontend/base/default/layout to your /app/design/frontend/theme/default/layout folder and simply clear out the references to the googleanalytics/ga block. The Fooman extension should still output this block and this should take care of your duplication.

<default>
    <!-- REMOVE THIS -->
    <reference name="footer">
        <block type="googleanalytics/ga" name="google_analytics" as="google_analytics" template="googleanalytics/ga.phtml" />
    </reference>
    <!-- TO HERE -->
    ...
</default>

Solution 2:

Better, you can copy and modify the fooman layout file to your theme and unset references to the default analytics block by doing something like this:

<default>
    <reference name="footer">
        <action method="unsetChild"><name>google_analytics</name></action>
    </reference>
</default>

I believe both of these methods are kosher; I like the second one better because in the event that you remove the fooman extension, your analytics will automatically be restored without any further effort on your part.

1

This is actually a known issue - please see Q&A - Double Analytics Code. Essentially Magento changed the location of the GA block (from after_body_start to head) and our release available on Magento Connect does not remove this yet.

Our upcoming release available on Github supports 1.8.1 and likely the related EE version.

If you want to make the modifications yourself PhilB's solution is close - we need to unset the default block in its new location as well

<layout version="0.1.0">
    <default>
        <reference name="head">
            <action method="unsetChild">
                <name>google_analytics</name>
            </action>
        </reference>
   </default>

And this would be placed in your theme's local.xml file if you do not want to edit core our 3rd party extension code.

The below code is where the updated block is added back again (and if the removal did not happen causes the two GA blocks)

    <reference name="head">
        <block type="core/text_list" name="before_head_end" as="before_head_end"/>
    </reference>
    <reference name="before_head_end">
        <block type="googleanalytics/ga" name="google_analytics" as="google_analytics" />
    </reference>
1
  • Thanks Fooman! I did piece together Phil's answer to get to your solution. Seems I got a little heat for asking a question about a 3rd party module ;) Thank you!! – JustinP Mar 13 '14 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.