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
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.
$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.

$items = $order->getAllItems();
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.

  • 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

2 thoughts on “Google Analytics ecommerce tracking in Magento

  1. You can definitely see your skills in the work you write. The world hopes for even more passionate writers like you who are not afraid to say how they believe. Always follow your heart.

  2. I’ve been surfing online more than 2 hours today, yet I never found any interesting article like yours.

    It is pretty worth enough for me. In my opinion,
    if all site owners and bloggers made good content as you did, the internet will
    be much more useful than ever before.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.