I am trying to track product category from magento to GA, (under Conversions>Ecommerce>overview), but with magento default core GA.php file dosent including this part: /app/code/core/Mage/GoogleAnalytics/Block/Ga.php
foreach ($order->getAllVisibleItems() as $item) {
$result[] = sprintf("_gaq.push(['_addItem', '%s', '%s', '%s', '%s', '%s', '%s']);",
$order->getIncrementId(),
$this->jsQuoteEscape($item->getSku()), $this->jsQuoteEscape($item->getName()),
null, // there is no "category" defined for the order item
$item->getBasePrice(), $item->getQtyOrdered()
);
}
*see, they commend out category field and put null right there.
I am looking for a solution that do not modify the magento in the /core, but solve the problem in /local.
BTW, I am using magento 1.7
hopefully someone could help me out, many thx :D
I had the exactly same situation The proper way to do this job the to extend the functionality of block class. I had created the module for that have a look for that if you want to add more items in Google Analytics for reporting purpose: I had created the module MyGoogleAnalytics under the directory Renegade: Have a look on file: Renegade_MyGoogleAnalytics.xml (module file)
block file Ga.php in (app\code\local\Renegade\MyGoogleAnalytics\Block\GoogleAnalytics)
configuration file in app\code\local\Renegade\MyGoogleAnalytics\etc
config.xml
Compare _getOrdersTrackingCode with original file function you will find the and understand the difference.
I don't know much about Magento but I believe all you have to do is copy that whole file from core over to your /local folder and change it to include the category. Magento will always look for a file in /local before going to core, but the path have to match. So the file should live in:
Another problem you'll have is that Magento products can have several categories. so you probably want to grab just the first one and pass to GA.
So here's what the file should look like:
Based in