Magento: How To Setup Google Adwords Conversion Tracking

Conversions

Setting up Google Adwords Conversion Tracking on your Magento store is relatively easy – but it’s not a built-in Magento feature, so you’ll have to edit a template file. Here are the 4 simple steps  that need to be done:

1. Open this file:

/app/design/frontend/default/yourskinname/template/checkout/success.phtml

2. At the bottom of the file, insert this code:

<?php
$order_details = Mage::getModel(‘sales/order’)->loadByIncrementId(Mage::getSingleton(‘checkout/session’)->getLastRealOrderId());
$adwords_saleamt = $order_details->subtotal;
?>

3. Login to your Google Adwords account

Under the “Reporting’ tab, click on “Conversions” and follow the steps to get the code that you’ll also need to add to the success.phtml page. It will look something like this:

<!– 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 $adwords_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>

4. Copy Google’s code

And paste it at the very bottom of the page (below the php code from step 2).

Alternatively, you can also install Luka Google AdWords Conversion Tracking Magento extension from MagentoConnect. But I haven’t tested that extension myself – and in general it’s better to not load up your Magento installation with too many modules and extensions. If you can keep it simple, it’s better!

Questions? Feel free to post them in the comments below!

14 Comments

  • Rich
    This blog is so awesome… keep up the good work!!!!
  • Neil Wigman
    Great post!
  • Jon
    Hi and thanks for the advice. Not sure that code is 100% though.

    This variable is never used:

    $adwords_saleamt = $order_details->subtotal;

    This next if() condition is always true (because 200 is treated as true):

    if (200) {
    google_conversion_value = 200;
    }

    I think it should probably be something like:

    var google_conversion_value =

    So the conversion value equals the amount for the sale. Let me know if that’s wrong.

    Cheers
    Jon

  • Jon
    Oops, the blog has removed the PHP from my comment. I’ll try again:

    Hi and thanks for the advice. Not sure that code is 100% though.

    This variable is never used:

    $adwords_saleamt = $order_details->subtotal;

    This next if() condition is always true (because 200 is treated as true):

    if (200) {
    google_conversion_value = 200;
    }

    I think it should probably be something like:

    var google_conversion_value = <?echo $adwords_saleamt ?>

    So the conversion value equals the amount for the sale. Let me know if that’s wrong.

    Cheers
    Jon

    Noam -

    Hi Jon – Thanks so much for commenting and I’m sorry some of the PHP code got stripped from the comment. You are right and I updated the code to use to properly track conversions with Google Adwords and Magento.

    Thanks!

  • SJ
    If you generate this code in AdWords you will get different values, so be sure to check your attributes. The code from Jon is pasted below to pass the right values to Google:

    loadByIncrementId(Mage::getSingleton(‘checkout/session’)->getLastRealOrderId());
    $adwords_saleamt = $order_details->subtotal;
    ?>

    <!–
    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 = ;
    //–>

    Noam -

    Hi SJ – thanks for the contribution and sorry some of the code got stripped from the comment. I updated the post with the correct code to use.
  • Nick
    Hi Noam,

    I think the success.phtml has moved.

    I found it at:
    /app/design/frontend/base/default/template/checkout

    Using Magento 1.4.2

    Thanks for the post.

  • Ron Peled
    Nice! Thanks for the tip and modification to their java script. Google certainly does not make this easy to understand. Such an easy thing to add right into Magento Core.
  • Alastair Battrick
    Hello, and thank you.

    Note that the apostrophes in the code above appear to have been converted to not valid PHP apostrophes, and need to be changed from
    ‘sales/order’
    to
    ‘sales/order’

  • Alastair Battrick
    And of course the commenting mechanism converts them again.
    From ‘ to '
  • Kudos
    Thanks for this. I’ve added the conversion tracking script from Google to success.phtml and it works fine. I’m wondering what the php code in step 2 is for?
    I’m not a web developer so please explain.
  • Rajesh N.Rao
    Yes Its working fine. Thanks
  • Jens Mikkelsen
    Does this example works with Magento 1.4.xx ?

Leave a Reply

Sorry - this blog is now closed to new comments.