Magento Google Analytics eCommerce Code Not Posting Data – Fix

If you’re using Magento 1.4+ or Magento EE 1.9.1, there are documented and reported bugs that prevent your Google Analytics tracking code (specifically for the eCommerce portion) from tracking your purchases and conversions. The solution is to modify (or overwrite in the /local folder) the Ga.php file that Magento uses for displaying your code within your site.

You can copy the file app/code/core/Mage/GoogleAnalytics/Block/Ga.php to app/code/local/Mage/GoogleAnalytics/Block/Ga.php – this will still allow you to update in the future because you aren’t overwriting any of the Magento core code.

Then replace the method _getPageTrackingCode with the following:

protected function _getPageTrackingCode($accountId)
        $pageName   = trim($this->getPageName());
        $optPageURL = '';
        if ($pageName && preg_match('/^\/.*/i', $pageName)) {
            $optPageURL = ", '{$this->jsQuoteEscape($pageName)}'";
        return "
	_gaq.push(['_setAccount', '{$this->jsQuoteEscape($accountId)}']);

That should do the trick! Give Google Analytics about 30 minutes or so to track using your updated code and you should be seeing Conversion rates, items, SKUs, etc all being passed from your store to GA.

Posted in Magento, Magento Enterprise, PHP