Home » Magento Customization, Magento Guide

Add Adwords tracking code to order confirmation page in Magento

15 October 2009 One Comment

Add Adwords tracking code to order confirmation page in Magento

Adding an Adwords tracking code to order confirmation page in Magento is relatively easy task. One that can be handled under an hour or so if you choose to implement it the proper way. Here is how.

Modify the “app/design/frontend/default/my_custom_theme/layout/checkout.xml” file. Look for section

<checkout_onepage_success>
<reference name="root">
<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
</reference>
<reference name="content">
<block name="checkout.success" template="checkout/success.phtml" type="checkout/onepage_success" />
</reference>
</checkout_onepage_success>

And turn it into

<checkout_onepage_success>
<reference name="root">
<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
</reference>
<reference name="content">
<block name="checkout.success" template="checkout/success.phtml" type="checkout/onepage_success" />
</reference>
<reference name="before_body_end">
<block name="google_adwords_tracking" template="checkout/google_adwords_tracking.phtml" type="core/template" />
</reference>
</checkout_onepage_success>
  • Create the “app/design/frontend/default/my_custom_theme/template/checkout/google_adwords_tracking.phtml” file and copy-paste the the Adwords tracking JavaScript code into it.

This code relies on


< ?php echo $this?>getChildHtml('before_body_end') ?>

block call from footer of each template (1column.phtml, 2columns-left.phtml, 2columns-right.phtml, 3columns.phtml). So, as long if haven’t removed this block call from mentioned templates, the above should work.

Thats it.

By Branko Ajzele from Inchoo.net

Related posts:

  1. Move mini-cart in the sidebar to the header (or anywhere) in Magento
  2. How to use WordPress home page in Magento home page (CMS page)
  3. Advanced search in Magento and how to use it in your own way
  4. Run Magento Code Outside of Magento
  5. Editing the Footer in a stock magento build

One Comment »

  • Juan Siesquen said:

    Hi Branko,

    Good article.

    I have a question: I have created a Payment Method what Consume a Web Service of Gateway called SafetyPay, i need to include and display \"HTML Code\" on the confirmation page (which shows the Order Number) without changing the template manually.

    Location of template:
    /app/design/frontend/default/default/template/checkout/

    Currently this is the Confirmation Message Content in success.phtml:
    <code>
    ====================================================================
    Your order has been received

    Thank you for your purchase!

    Your order # is: 100000026.
    You will receive an order confirmation email with details of your order and a link to track its progress.
    Click here to print a copy of your order confirmation.
    ====================================================================
    </code>

    I need change the template adding information from payment method:
    <code>
    ====================================================================
    Your order has been received

    Thank you for your purchase!

    Your order # is: 100000026.
    You will receive an order confirmation email with details of your order and a link to track its progress.
    Click here to print a copy of your order confirmation.

    To complete payment of this transaction, please go to your Online Banking, and use the following information:
    Your Transaction ID is: 11611
    Your Purchase Amount is: 41.27 Euro (EUR)

    You can [Click here] to go directly to SAFETYPAY Default Bank.

    IMPORTANT: This Transaction will expire in 2 hours.
    ====================================================================
    </code>

    Is it possible to do this using layouts?

    I have my XML File Layout in:
    <code>
    <?xml version=\"1.0\"?>
    <layout version=\"0.1.0\">
    <default>
    </default>

    <checkout_onepage_success>
    <reference name=\"root\">
    <action method=\"setTemplate\"><template>page/2columns-right.phtml</template></action>
    </reference>
    <reference name=\"before_body_end\">
    <block name=\"checkout.success.safetypay\" template=\"safetypay/confirmation.phtml\" type=\"safetypay/confirmation\" />
    </reference>

    <reference name=\"content\">
    <block name=\"checkout.success\" template=\"checkout/success.phtml\" type=\"checkout/onepage_success\" />
    <block name=\"checkout.success.safetypay\" template=\"safetypay/confirmation.phtml\" type=\"safetypay/confirmation\" />
    </reference>
    </checkout_onepage_success>
    </layout>
    <code>

    The content of file: confirmation.phtml
    <code>
    <?php
    /**
    * Magento Confirm Message
    ?>
    To complete payment of this transaction, please go to your Online Banking, and use the following information:
    Your Transaction ID is: <?php echo $this->getTransactionID; ?>
    Your Purchase Amount is: <?php echo $this->getPurchaseAmount; ?>

    You can [Click here] to go directly to <?php echo $this->getBankName; ?>.

    IMPORTANT: This Transaction will expire in <?php echo $this->getTimeExpire; ?>.
    </code>

    I have read that this also can be performed by Code… I hope your support….

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree

Security Code: