In your code, copy app/code/core/Mage/GoogleAnalytics/Block/Ga.php to
app/code/local/Mage/GoogleAnalytics/Block/Ga.php.
Change the appropriate section to this
foreach ($order->getAllVisibleItems() as $item) {
// Category for Google Analytics fix
$product = Mage::getModel('catalog/product')->loadByAttribute('sku',
$item->getSku());
$categoryIds = $product->getCategoryIds();
$categoryName = '';
if (isset($categoryIds[0])){
$category = Mage::getModel('catalog/category')->setStoreId(
Mage::app()->getStore()->getId())->load($categoryIds[0]);
$categoryName = $category->getName();
}
$result[] = sprintf("_gaq.push(['_addItem', '%s', '%s', '%s', '%s',
'%s', '%s']);",
$order->getIncrementId(),
$this->jsQuoteEscape($item->getSku()),
$this->jsQuoteEscape($item->getName()),
$categoryName,
$item->getBasePrice(), $item->getQtyOrdered()
);
}
That should be it!I found a lot of help at http://www.magentocommerce.com/boards/viewthread/291153/ from
tzyganu and a few other comments.
is it ok for magento 1.7.0.2 , i have make it in magento code , but it thogh not catch category in google anlytics code.
ReplyDeletePlease suggest me what should to do
Hi, sorry for the late comment, I don't go on my blog too often. You can try it, if it doesn't work for you, you can try something else. Not sure if this fix still works.
ReplyDelete