Magento Themes and Magento Extensions

Add Adwords tracking code to order confirmation page in Magento

Share

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

1.<checkout_onepage_success>
2.<reference name="root">
3.<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
4.</reference>
5.<reference name="content">
6.<block name="checkout.success" template="checkout/success.phtml" type="checkout/onepage_success" />
7.</reference>
8.</checkout_onepage_success>

And turn it into

01.<checkout_onepage_success>
02.<reference name="root">
03.<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
04.</reference>
05.<reference name="content">
06.<block name="checkout.success" template="checkout/success.phtml" type="checkout/onepage_success" />
07.</reference>
08.<reference name="before_body_end">
09.<block name="google_adwords_tracking" template="checkout/google_adwords_tracking.phtml" type="core/template" />
10.</reference>
11.</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

1.< ?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.

Leave a Reply

You must be logged in to post a comment.