How to add Google Dynamic Remarketing code in Magento

Magento is an open-source e-commerce platform written in PHP for e-commerce web sites, developed by Magento Inc. Magento provided very simple options for add any custom JavaScript and HTML code on the website through admin panel.

To add normal Adword Remarketing code follow this link instructions. But, if you are hoping to implement Google Adword Dynamic Remarketing  in magento , kindly go with below instructions.

However I have mention both option (i.e using magento connect admin panel as well as FTP access) to add dynamic remarketing code on the website.

Magento Ecommerce
Magento Ecommerce

If you already have Google Remarketing code then follow below steps, otherwise follow this link to get remarketing code from adwords Account.

Steps to add remarketing code on Magento

Using admin panel:

  1. Open this link in new window/tab or search GDRT in google search engine and open first result (i.e  https://www.magentocommerce.com link).
  2. Get/copy extension key.
  3. Login to magento admin
  4. In navigation bar go to System drop down will appear.
  5. Now in drop down click on Magento Connect.
  6. Install GDRT extension on Magento .
  7. Logout and login back to Magento admin.
  8. Now in drop down click on Configuration  inside System Menu.
  9. Go to GDRT setting (Left side option).
  10. Add  conversion id, conversion label(optional) and select product Id/sku as per merchent center details.
  11. Save.

Note:- Before adding any Extension on your website, please keep complete back up of your site. 

Dynamic remarketing code using FTP:

  • Login to FTP.
  • Open footer.phtml (file path: app->design->frontend-> base->default->template->page->html->footer.phtml).
  • Add the below code in Footer.phtml.
<?php $page_type = Mage::app()->getFrontController()->getRequest()->getControllerName();
if($page_type == 'index')
{
?>
    <script type="text/javascript">
     var google_tag_params = {
       ecomm_pagetype: 'home'
     };
  </script>
<?php } elseif($page_type == 'category') { ?>
  <script type="text/javascript">
     var google_tag_params = {
       ecomm_pagetype: 'category'
     };
  </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: <?php echo $product_price; ?>
    };
  </script>
<?php 
} 
elseif($page_type == 'cart') 
{ 
    $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;
  }
   $product_id_all=substr($product_id_all, 1);
   $productPrice_all=substr($productPrice_all, 1);
?>
  <script type="text/javascript">
  var id=[<?php echo $product_id_all; ?>];
  var price=[<?php echo $productPrice_all; ?>];
  var google_tag_params = {
    ecomm_pagetype: 'cart',
    ecomm_prodid: id,
    ecomm_totalvalue: price
  };
  </script>
<?php 
} 
elseif($page_type == 'onepage') 
{ 
    $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;
  }
  $product_id_all=substr($product_id_all, 1);
  $productPrice_all=substr($productPrice_all, 1);
?>
  <script type="text/javascript">
  var id=[<?php echo $product_id_all; ?>];
  var price=[<?php echo $productPrice_all; ?>];
  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'
  };
  </script>
<?php } ?>

<script type="text/javascript">
/* <![CDATA[ */ 
var google_conversion_id = xxxxxxx; 
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/xxxxxx/?value=0&guid=ON&script=0"/>
</div>
</noscript>
  • Save Footer.pthml file and upload to server.
  • Login to magento
  • Go to System -> Cache Management.
  • Disable HTML Block.
  • Select all and  Refresh all cache.

Note :- Before editing any file on server, please keep back up of file. Base and Default directory can be change on then basis of package and template selection

1 thought on “How to add Google Dynamic Remarketing code in Magento

  1. You really make it seem really easy along with your presentation but I to find this topic to be actually one thing that I believe I’d by no means understand. It sort of feels too complex and extremely extensive for me. I’m taking a look ahead on your next publish, I will attempt to get the hold of it!

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.