Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Google Analytics Category Tracking
 
jjbigfish
Sr. Member
 
Total Posts:  109
Joined:  2010-01-30
 

/app/code/core/Mage/GoogleAnalytics/Block - Ga.php

Change;

<code>
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()
);
}
</code>

To;

<code>
foreach ($order->getAllVisibleItems() as $item) {
$productCat = ‘’;
$product = Mage::getModel(’catalog/product’)->load($item->getProductId());
$categoryIds = $product->getCategoryIds();
foreach($categoryIds as $categoryId) {
$category = Mage::getModel(’catalog/category’)->load($categoryId);
$productCat = $category->getName();
}
$result[] = sprintf("_gaq.push([’_addItem’, ‘%s’, ‘%s’, ‘%s’, ‘%s’, ‘%s’, ‘%s’]);”,
$order->getIncrementId(),
$this->jsQuoteEscape($item->getSku()),
$this->jsQuoteEscape($item->getName()),
$productCat,
$item->getBasePrice(),
$item->getQtyOrdered()
);
}
</code>

Hope This Helps!

 
Magento Community Magento Community
Magento Community
Magento Community
 
parasharia
Jr. Member
 
Total Posts:  13
Joined:  2011-08-28
 

I tried this for a client who is running CE1.6.1 and the category was not picked up. The rest of the eCommerce metrics continue to be reported by GA but category still says Not Set.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top