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!

ABOUT THE AUTHOR

Next generation websites that work on all devices, feature award winning web design, state-of-the-art web technologies, and powerful administration tools to edit and manage your site anytime, anywhere! Follow us on Twitter and subscribe to the feed to stay tuned.

21 Comments

  1. Rich
    April 27, 2010 at 8:31 pm

    This blog is so awesome… keep up the good work!!!!

    Reply
  2. Neil Wigman
    September 27, 2010 at 9:03 pm

    Great post!

    Reply
  3. Jon
    September 28, 2010 at 4:41 pm

    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

    Reply
  4. Jon
    September 28, 2010 at 4:42 pm

    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

    Reply
    • Noam
      February 18, 2011 at 3:28 pm

      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!

      Reply
  5. SJ
    December 14, 2010 at 10:08 am

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

    Reply
    • Noam
      February 18, 2011 at 3:26 pm

      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.

      Reply
  6. Nick
    May 24, 2011 at 8:29 am

    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.

    Reply
  7. Ron Peled
    June 22, 2011 at 7:51 pm

    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.

    Reply
  8. Alastair Battrick
    July 25, 2011 at 3:58 am

    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’

    Reply
  9. Alastair Battrick
    July 25, 2011 at 3:59 am

    And of course the commenting mechanism converts them again.
    From ‘ to '

    Reply
  10. Kudos
    September 14, 2011 at 5:30 am

    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.

    Reply
  11. Rajesh N.Rao
    September 14, 2011 at 9:22 am

    Yes Its working fine. Thanks

    Reply
  12. Jens Mikkelsen
    October 21, 2011 at 6:22 am

    Does this example works with Magento 1.4.xx ?

    Reply
  13. Hayden
    October 6, 2012 at 7:36 am

    Might be worth an edit to the article just to say that in the current version of google ads the reporting tab is gone and conversions is now under tools + analysis.

    Reply
  14. Adam
    October 16, 2012 at 6:00 am

    Weve just released a Free extension should anyone need it http://www.magentocommerce.com/magento-connect/catalog/product/view/id/14817/

    Reply
  15. Sharad Gupta
    August 20, 2013 at 4:02 pm

    I am getting error on line 66 which is the first line of the first code you mentioned before Google Ads code.

    Reply
  16. Giorgio
    October 10, 2013 at 7:11 am

    The actual location of your success.phtml file is /app/design/frontend/yourskinname/default/template/checkout/success.phtml instead of /default/yourskinname/. If the success.phtml file appears to be missing you can copy it from the base template located app/design/frontend/base/default/template/checkout/ and paste it in your skin.

    Reply
  17. randyschneider227
    March 12, 2014 at 11:48 pm

    One of the best kinds of PPC ads available today are Google’s remarketing display ads. What’s great about them is that you can segment them by behavior, so if people have been to your home page but not your sales page, you can direct them there. If people land on your shopping cart but don’t buy, you can run ads to send them back to the shopping cart and complete checkout. The power to segment is one of the most powerful advancements in marketing technology in the past century. I didn’t know this when I started but I called Simon (302-401-4478) and I got help. Now I make 22.37% more on my display advertising than I did before and I’ve been selling a lot more product.

    Reply
  18. randyschneider227
    March 13, 2014 at 11:13 am

    I’m gonna drop the ultimate Adwords PPC secret right here: Individual sitelinks differentiated, tagged, and tracked within Google Analytics. Yep, I’m serious – that’s the secret. Are you doing it? If so, you know what I’m talking about. If not, I bet Simon can help you over the phone, give him a ring at 302-401-4478. You can do all kinds of powerful testing and optimization when you’ve got sitelink tracking in place and it can really set you ahead of your competition.

    Reply
  19. NINO
    April 3, 2014 at 4:45 pm

    Here is my Code what I added in success.phtml file

    loadByIncrementId(Mage::getSingleton(‘checkout/session’)->getLastRealOrderId());
    $totalamount = number_format($order->getGrandTotal(),2); ?>

    /* <![CDATA[ */
    var google_conversion_id = [my_ID];
    var google_conversion_language = “en”;
    var google_conversion_format = “2”;
    var google_conversion_color = “ffffff”;
    var google_conversion_label = [my_label];
    if () {
    var google_conversion_value =
    }
    /* ]]> */

    but when I’m checking conversions on google adwords it shows 0 for conversions and for value as well, but we have sales so it shouldn’t be 0

    Reply

Leave a Reply

Web Analytics