Adding Google Adwords sale conversion tracking code to a magento site.

Google Adwords conversion tracking can be a useful tool.  Some of the data can be found and or linked in from Google Analytics, but it’s not always as reliable or as easy to read as straight sale conversion tracking.

To add sale conversion follow these steps.
1. Open the template file at
/app/design/frontend/{interface}/{layout}/checkout/success.phtml
Add this code to get the sale amount:

[code language=”php”]
<?php
$order_details = Mage::getModel(‘sales/order’)->loadByIncrementId(Mage::getSingleton(‘checkout/session’)->getLastRealOrderId());
$google_saleamt = $order_details->subtotal;
?>
[/code]

2. Get your adwords conversion tracking code from your adwords account and paste it in the bottom of the template file. We want to modify if so if we have a value, we pass that value to Google Adwords, so modify it so it looks like this:
[code language=”javascript”]
<!– Google Code for Sale Conversion Page –>
<script type=”text/javascript”>
<!–
var google_conversion_id = 0987654321;
var google_conversion_language = “en”;
var google_conversion_format = “3″;
var google_conversion_color = “ffffff”;
var google_conversion_label = “KFKFKFKFKFKF”;
var google_conversion_value = 0;
if (<?php echo $adwords_saleamt; ?>) {
google_conversion_value = <?php echo $google_saleamt; ?>;
}
//–>
</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/0987654321/?value=150&amp;label=KFKFKFKFKFKF&amp;guid=ON&amp;script=0″/>
</div>
</noscript>
[/code]

Note the only new lines are below the setting of google_conversion_value to 0 where we add:
[code language=”javascript”]
if (<?php echo $google_saleamt; ?>) {
google_conversion_value = <?php echo $google_saleamt; ?>;
}
[/code]

The source for this post is: http://www.noamdesign.com/blog/magento-how-to-setup-google-adwords-conversion-tracking/

Leave a Reply

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