We recently added some Google Event Tracking code to a client’s site in order to monitor the relative success of various on site banners. Event Tracking being the Google Analytics way of adding script calls to log an event that has happened when the visitor clicks on an element on the site; in this case an image banner.
The important thing toÂ understandÂ is that the GA tracking code must appear in the <head> section to allow the _qaq object to be created before the event tracking tracking code is output, this means updating our Magento code so the tracking is output in the correct place. This involves the following steps:
1. Update the Ga.php file in: app/code/core/Mage/GoogleAnalytics/Block
At line 164 replace the script block containing the old GA code with the new async code.
2. Update the googleanalytics.xml file in: app/design/frontend/default/default/layout
At line 37 change the reference name to “before_head_end”
3. Update the page.xml file in: app/design/frontend/default/default/layout
At line 36 at the line of code: <block type=”core/text_list” name=”before_head_end” as=”before_head_end”/>Â Â
after the: <block type=”page/html_head”>
4. Refresh the Magento cache and reload your site. you should now see the old instances of the GA tracking code removed and the new ones placed within the section.
Simple and straightforward, no?