AdWords
4.7K members online now
4.7K members online now
Use AdWords conversion tracking and reporting to measure your results. Have a question about Google Analytics? Post it here, on the Google Analytics Community!
Guide Me
star_border
Reply

AdWords Conversion with Google Tag manager - Magento (Ecommerce)

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I've implemented Google Tag Manager  to my entire Magento website through Tag Manager Extension plugin. Linked Google Analytics with Google Tag Manager. Linked Google Analytics with Google Adwords to pull Adwords Conversion data to Analytics Goal.

 

---- My question ---

  • Do I need to add Google Adwords Conversion tracking code separately in sucess.phtml file of Magento Website? Or, Do the Google Tag Manager will do it as I've linked Google Analytics with Google Adwords account & GTM with Google Analytics?

 

---- My Present Success.phtml file Code ---- Is there any error? - As the transactions are Not showing in Google Analytics Ecommerce Transactions Neither in Goals Nor in Google Adwords Conversions

 

 

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @copyright   Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<div class="page-title">
    <h1><?php echo $this->__('Your order has been received.') ?></h1>
</div>
<?php echo $this->getMessagesBlock()->toHtml() ?>
<h2 class="sub-title"><?php echo $this->__('Thank you for your purchase!') ?></h2>

<?php if ($this->getOrderId()):?>
<?php if ($this->getCanViewOrder()) :?>
    <p><?php echo $this->__('Your order # is: %s.', sprintf('<a href="%s">%s</a>', $this->escapeHtml($this->getViewOrderUrl()), $this->escapeHtml($this->getOrderId()))) ?></p>
<?php  else :?>
    <p><?php echo $this->__('Your order # is: %s.', $this->escapeHtml($this->getOrderId())) ?></p>
<?php endif;?>
    <p><?php echo $this->__('You will receive an order confirmation email with details of your order and a link to track its progress. If you chose to check out as a guest, we have created an account for your convenience. You will receive an email with login details shortly.') ?></p>
<?php if ($this->getCanViewOrder() && $this->getCanPrintOrder()) :?>
    <p>
        <?php echo $this->__('Click <a href="%s" onclick="this.target=\'_blank\'">here to print</a> a copy of your order confirmation.', $this->getPrintUrl()) ?>
        <?php echo $this->getChildHtml() ?>
    </p>
<?php endif;?>
<?php endif;?>

<?php if ($this->getAgreementRefId()): ?>
    <p><?php echo $this->__('Your billing agreement # is: %s.', sprintf('<a href="%s">%s</a>', $this->escapeHtml($this->getAgreementUrl()), $this->escapeHtml($this->getAgreementRefId())))?></p>
<?php endif;?>

<?php if ($profiles = $this->getRecurringProfiles()):?>
<p><?php echo $this->__('Your recurring payment profiles:'); ?></p>
<ul class="disc">
<?php foreach($profiles as $profile):?>
<?php $profileIdHtml = ($this->getCanViewProfiles() ? sprintf('<a href="%s">%s</a>', $this->escapeHtml($this->getProfileUrl($profile)), $this->escapeHtml($this->getObjectData($profile, 'reference_id'))) : $this->escapeHtml($this->getObjectData($profile, 'reference_id')));?>
    <li><?php echo $this->__('Payment profile # %s: "%s".', $profileIdHtml, $this->escapeHtml($this->getObjectData($profile, 'schedule_description')))?></li>
<?php endforeach;?>
</ul>
<?php endif;?>

<div class="buttons-set">
    <button type="button" class="button" title="<?php echo $this->__('Continue Shopping') ?>" onclick="window.location='<?php echo $this->getUrl() ?>'"><span><span><?php echo $this->__('Continue Shopping') ?></span></span></button>
</div>
<!-- Google Code for Google Tracking Conversion Page -->
<?php
$orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getModel('sales/order')->load($orderId);
$total =  number_format($order->getGrandTotal(),2);
?>

<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 1XXXXXXXXX;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "WtXCCOCJtwgQwP2B5AM";
var google_remarketing_only = false;
if (<?php echo $total?>) {
    var google_conversion_value = <?php echo $total?>;
}
/* ]]> */
</script>
<script type="text/javascript" src="https://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt=""
src="https://www.googleadservices.com/pagead/conversion/1015054016/?value=<?php echo $total?>&amp;label=WtXCCOCJtwgQwP2B5AM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

<?php /* google tag manager 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'];
$shippingVal=$order->getShippingAmount();
$taxAmount=$order->getTaxAmount();
?>
<script>
dataLayer.push({
    'event' :'order_success',
    'transactionId': '<?php echo $order_id; ?>',
    'transactionAffiliation': '',
    'transactionTotal': <?php echo $gtotal; ?>,
    'transactionTax': <?php echo $shippingVal; ?>,
    'transactionShipping': <?php echo $taxAmount; ?>,
    'transactionProducts': [
	<?php 
	$i=0;
$items = $order->getAllItems();
$itemcount=count($items);
$name=array();
$unitPrice=array();
$sku=array();
$ids=array();
$qty=array();
foreach ($items as $itemId => $item)
{
$i++;
if($i > 1)
{
echo ",";
}
?>
	{
        'sku': '<?php echo $item->getSku(); ?>',
        'name': "<?php echo $item->getName(); ?>",
        'category': '',
        'price': <?php echo $item->getPrice(); ?>,
        'quantity': <?php echo $item->getQtyToInvoice(); ?>
    }
	<?php 
}
?>
	
	]
});
</script>  






<?php /* google tag manager success.phtml*/ ?>

 

 

 

 

2 Expert replyverified_user

AdWords Conversion with Google Tag manager - Magento (Ecommerce)

Community Manager
# 2
Community Manager

Hi Arnav,

Thanks for posting to the Community.

 

This question appears to be more AdWords Script related. In regards, I'd suggest posting your question in the AdWords Script Forum, which has experts that can help answer your query faster.

 

I hope this helps!

 

Best,

Spencer

Re: AdWords Conversion with Google Tag manager - Magento (Ecommerce)

Top Contributor
# 3
Top Contributor

Hi @Arnav L,

 

To your question-

 

Yes, you need to have AdWords Tracking setup on Success page, either a direct code implementation as you have now, or through GTM tag. As you are using GTM already, the best would be set it up through a GTM tag itself. 

 

Next, use GTM in debug/preview mode and place a test order to see if all your tags and DataLayers are working properly. 

 

Additionally, you can test your implementation through Google Tag Assistant and Google Analytics Dubug extensions for Chrome browser. 

 

All the best!

Thanks
Ratan Jha
Join me on Google+   |   Twitter