Categories: Google Analytics and Ecommerce Tracking

Google Analytics ecommerce tracking in Magento

What is Magento Ecommerce?

Magento is an open-source e-commerce platform written in PHP for e-commerce web sites.
Magento is the provider of two distinct platforms, Magento Community Edition and Magento Enterprise Edition.
Magento Community Edition is an open-source content-management system. Fitted with bundle of features, anyone can modify the core system of Community version. Developers can implement the core files and extend its functionality by adding new plug-in modules provided by other developers.

Magento Ecommerce

How to add Google Analytics e-commerce tracking in Magento

Magento have too many commonly added features, Google API is one of them. To add Google Analytics on Magento you can use Google API module .

Steps to add Google Analytics e-commerce in Magento using Google API:

  1. Login to Magneto admin panel
  2. Go to system -> configurations.
  3. Click on Google API.
  4. Select yes in drop down and place UA Id (UA-XXXXXX-XX) in below given box and save it

By adding Google Analytics using Google API, Google Analytics e-commerce will be enable.

Steps to add Google Analytics e-commerce in Magento using FTP:

  • Login to FTP.
  • Open footer.phtml (file path: app->design->frontend-> yourPackage->yourTheme->template->checkout->success.phtml).
  • Add the below code( for Universal Analytics) in bottom of success.phtml.
<?php
$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId()); 
$subtotal = $order->getSubtotal();
$order_id = $order->getId(); //the id of the order
//$order->getIncrementId();//the increment id of the order
$gtotal = $order->getGrandTotal();//grand total of the order 
$address = $order->getBillingAddress()->getData();
$city = $address['city'];
$state = $address['region'];
$country = $address['country_id'];
?>
<script type="text/javascript">
ga('require', 'ecommerce');

ga('ecommerce:addTransaction', {
  'id': '<?php echo $order_id; ?>',                     // Transaction ID. Required.
  'affiliation': '',   // Affiliation or store name.
  'revenue': '<?php echo $gtotal;?>',               // Grand Total.
  'shipping': '0',                  // Shipping.
  'tax': '0'                     // Tax.
});

<?php 
$items = $order->getAllItems();
$itemcount=count($items);
$name=array();
$unitPrice=array();
$sku=array();
$ids=array();
$qty=array();
foreach ($items as $itemId => $item)
{?>
ga('ecommerce:addItem', {
  'id': '<?php echo $order_id; ?>',                     // Transaction ID. Required.
  'name': '<?php echo $item->getName(); ?>',    // Product name. Required.
  'sku': '<?php echo $item->getSku(); ?>',                 // SKU/code.
  'category': '',         // Category or variation.
  'price': '<?php echo $item->getPrice(); ?>',                 // Unit price.
  'quantity': '<?php echo $item->getQtyToInvoice(); ?>'                   // Quantity.
});
<?php 
}
?> 
ga('ecommerce:send');

</script>
  • Save and upload success.phtml file on server.

Note :- Above mentioned code will work on Magento 1.x.  and before editing any file on server, please keep back up of file

Notes On Click

Share
Published by
Notes On Click
Tags: Ecommerce trackingmagento

Recent Posts

  • Adword Conversion Tracking
  • Google Adwords Remarketing

Conversion and Remaketing code in BigCommerce

In this blog, you will see how to add Adwords Conversion Tracking and Remarkeing Code in BigCommerce.BigCommerce is one of…

8 years ago
  • Google Analytics and Ecommerce Tracking

Ecommerce Tracking in OpenCart 2.3

Around 6 months back, I had published an article on “How to add GA e-commerce tracking in Opencart“. I am really thankful…

8 years ago
  • Google Analytics and Ecommerce Tracking

Google Analytics Definition and Common Terms

 If you have gone through our previous blog about Google Analytics, you might have sound understanding about Google Analytics and how it…

8 years ago
  • Google Analytics and Ecommerce Tracking

What is Google Analytics and it’s Features?

Do you want to know more about your visitors and how your content is performing?​ Whether you run a website…

8 years ago
  • Google Analytics and Ecommerce Tracking

How to Add Google Analytics in BigCommerce

In this blog, you will see how to add Google Analytics and E-commerce Tracking Code  in BigCommerce. BigCommerce is one of the…

8 years ago
  • Google Analytics and Ecommerce Tracking

Google Analytics and E-commerce Tracking in Miva Merchant

If you have gone through some of previous blog, you might have seen how to install google analytics, e-commerce tracking…

8 years ago