5

After upgrading Googles Universal Analytics, magento orders are not tracked / converted. We have checked the following options

  1. added the track informations in app/design/frontend/base/default/page/html/head.phtml
  2. Sytem/Configuration-> Sales->Google Api -> Enabled and Account number is given and
  3. Ecommerce Tracking is on status in Google Analytics. But the orders not tracked by google.

we are using magento 1.7. Shall we need to add any other things?

2 Answers 2

9

I have added the code in success.phtml file, it is workging fine.

$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$total = $order->getGrandTotal();
$shipping = $order->getShippingAmount();
$tax = $order->getTaxAmount();
$store = Mage::app()->getStore();
$name = $store->getName();

$items = $order->getAllItems();
$item_details = array() ;
foreach($items as $item) {
$det = array() ;
$det['sku'] = $item->getSku() ;
$det['name'] = $item->getName() ;
$det['category'] = get_category_name($item->getProductId()) ;
$det['price'] = $item->getPrice() ;
$det['quantity'] = number_format($item->getQtyOrdered(), 0) ; 
array_push($item_details, $det) ; 

}

function get_category_name($productId) { 
$product = Mage::getModel('catalog/product')->load($productId);
$category_name = "" ;
$cats = $product->getCategoryIds();

$cnt = 0 ;
foreach ($cats as $category_id) {
$_cat = Mage::getModel('catalog/category')->load($category_id) ;
$cnt++ ;
if($cnt == count($cats)) 
$category_name.=$_cat->getName() ;
else 
$category_name.=$_cat->getName()."," ; 
} 
return $category_name ; 
}

function getItemJs(&$transId, &$item) {
return <<<HTML
ga('ecommerce:addItem', {
'id': '$transId',
'name': '{$item['name']}',
'sku': '{$item['sku']}',
'category': '{$item['category']}',
'price': '{$item['price']}',
'quantity': '{$item['quantity']}'
});
HTML;
}

?>
<script type="text/javascript">

ga('require', 'ecommerce', 'ecommerce.js'); // Load GA ecommerce plug-in.
ga('ecommerce:addTransaction', {
'id': '<?php echo $this->getOrderId(); ?>', // Transaction ID. Required
'affiliation': '<?php echo $name ?>', // Affiliation or store name
'revenue': '<?php echo $total; ?>', // Grand Total
'shipping': '<?php echo $shipping; ?>', // Shipping
'tax': '<?php echo $tax; ?>' // Tax
});
// to get items
<?php
foreach ($item_details as &$item) {
echo getItemJs($this->getOrderId(), $item);
}
?>
ga('ecommerce:send');
</script>
3

see How do I add universal analytics to my magento store?

Personally I'm using the fooman google analtics plus extension

4
  • I have followed the the link and checked which you gave. Is it really need the extension?
    – alamelu
    Commented Mar 6, 2014 at 13:04
  • It's probably the easiest way. It's on Connect if you're more comfortable with that, and the fooman homepage has a manual that tells you how to set up goal tracking in your analytics profile
    – Richard
    Commented Mar 6, 2014 at 13:15
  • Is google tag manager content is needed for universal analytics?
    – alamelu
    Commented Mar 6, 2014 at 13:51
  • I have added the tracking code in success.phtml, using google analytics dev guide then it works good.
    – alamelu
    Commented Mar 10, 2014 at 5:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.