Warning: Your browser is very out-of-date. You should upgrade to a better browser.

Simple single script to add Google’s conversion tracking to your Magento ecommerce website. The code should be added into the footer.phtml file within your current template. The code includes tracking of catalogue browsing, checkout and new orders.

Simply replace all the $googleConversionId with your actual Google Conversion ID.

<!-- Google Conversion Tracking -->
<?php $googleConversionId = ""; // Your conversion ID goes here ?>
<?php $page_type = Mage::app()->getFrontController()->getRequest()->getControllerName();
if($page_type == 'index') { ?>
 <script type="text/javascript">
 var google_tag_params = {
 ecomm_pagetype: 'home',
 ecomm_prodid: '',
 ecomm_totalvalue: 0
 };
 </script>
<?php } elseif($page_type == 'category') { ?>
 <script type="text/javascript">
 var google_tag_params = {
 ecomm_pagetype: 'category',
 ecomm_prodid: '',
 ecomm_totalvalue: 0
 };
 </script>
<?php } elseif($page_type == 'product') {
 $product_id = Mage::registry('current_product')->getId();
 $product_id = Mage::getModel('catalog/product')->load($product_id)->getSku();
 $product_price = Mage::registry('current_product')->getPrice();
 ?>
 <script type="text/javascript">
 var google_tag_params = {
 ecomm_pagetype: 'product',
 ecomm_prodid: '<?php echo $product_id; ?>',
 ecomm_totalvalue: parseFloat('<?php echo $product_price; ?>')
 };
 </script>
<?php } elseif($page_type == 'cart') { ?>
 <script>
 var id = new Array();
 var price = new Array();
 </script>
 <?php
 $cart = Mage::getModel('checkout/session')->getQuote();
 foreach ($cart->getAllItems() as $item) {
 $product_id = $item->getProductId();
 $product_id = $item->getSku();
 $product_id_all = $product_id_all.','.$product_id ;
 $productPrice = $item->getProduct()->getPrice();
 $productPrice_all = $productPrice_all.','.$productPrice;
 ?>
 <Script>
 id.push('<?php echo $product_id; ?>');
 price.push(parseFloat('<?php echo $productPrice; ?>'));
 </Script>
 <?php
 }
 $product_id_all=substr($product_id_all, 1);
 $productPrice_all=substr($productPrice_all, 1);
 ?>
 <script type="text/javascript">
 var google_tag_params = {
 ecomm_pagetype: 'cart',
 ecomm_prodid: id,
 ecomm_totalvalue: price
 };
 </script>
 <?php } elseif($page_type == 'onepage') { ?>
 <script>
 var id = new Array();
 var price = new Array();
 </script>
 <?php
 $cart = Mage::getModel('checkout/session')->getQuote();
 foreach ($cart->getAllItems() as $item)
 {
 $product_id = $item->getProductId();
 $product_id = $item->getSku();
 $product_id_all = $product_id_all.','.$product_id ;
 $productPrice = $item->getProduct()->getPrice();
 $productPrice_all = $productPrice_all.','.$productPrice;
 ?>
 <Script>
 id.push('<?php echo $product_id; ?>');
 price.push(parseFloat('<?php echo $productPrice; ?>'));
 </Script>
 <?php } 
 $product_id_all=substr($product_id_all, 1);
 $productPrice_all=substr($productPrice_all, 1);
 ?>
 <script type="text/javascript">
 var google_tag_params = {
 ecomm_pagetype: 'purchase',
 ecomm_prodid: id,
 ecomm_totalvalue: price
 };
 </script>
 <?php }else{ ?>
 <script type="text/javascript">
 var google_tag_params = {
 ecomm_pagetype: 'other',
 ecomm_prodid: '',
 ecomm_totalvalue: 0
 };
 </script>
 <?php } ?>
<script type="text/javascript">
 /* <![CDATA[ */
 var google_conversion_id = <?php echo $googleConversionId; ?>;
 var google_custom_params = window.google_tag_params;
 var google_remarketing_only = true;
 /* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
 <div style="display:inline;">
 <img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/<?php echo $googleConversionId; ?>/?value=0&guid=ON&script=0"/>
 </div>
</noscript>
<!-- End Google Conversion Tracking -->

Magento

Magento is a feature-rich ecommerce platform built on open-source technology that provides online merchants with unprecedented flexibility and control over the look, content and functionality of their ecommerce store.

About Magento Ecommerce · Magento Posts

Related Magento Posts

Magento July 2021

Magento 2 Blog Extensions

While Magento isn't the go-to platform for blogs it can be useful for store owners to have a quick and easy way to post updated...
Magento April 2021

Notes: Magento 2 Directory Structure

## Magento 1 A brief reminder of the Magento 1 folder structure: * **app/code** followed by either * **/core** for core files * **/community** for...
Magento March 2021

Magento 2.4.2

The latest version of [Magento](/magento-ecommerce) has been released - Magento version 2.4.2 is the usual mix of security updates, performance and some improvements to the...

More MagentoSEO Posts...

Related SEO Posts

Notes SEO June 2019

Remove outdated content from Google Search Results

From time to time unwanted pages can appear in Google Search Results. Could be a temporary page, old content or even a test page that's...
Magento SEO November 2016

All-in-one Google Analytics tracking in Magento

Simple single script to add Google’s conversion tracking to your Magento ecommerce website. The code should be added into the footer.phtml file within your current template....
Magento SEO November 2016

All-in-one Facebook Pixel Code for Magento ecommerce

Simple single script to add Facebook’s Pixel Code tracking to your Magento ecommerce website. The code should be added into the head.phtml file within your...

More MagentoSEO Posts...