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
Add this code to get the sale amount:

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

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 type=”text/javascript” src=””>
<div style=”display:inline;”>
<img height=”1″ width=”1″ style=”border-style:none;” alt=”" src=”;label=KFKFKFKFKFKF&amp;guid=ON&amp;script=0″/>

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; ?>;

The source for this post is:

Leave a Reply

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