Adwords conversion tracking in OpenCart
18th January 2013
,18th January 2013
,A client asked me to add some Google Adwords conversion tracking code to their OpenCart website's success page that is shown after someone completes an order.
However, OpenCart doesn't have one file for that - it has catalog/view/theme/xxx/template/common/success.tpl which acts as a success page for everything that needs a success message on the site - such as the contact form for example. And it would skew your results if everytime someone sent you a contact message Adwords thought you'd converted a sale!
But thanks to a tip from storm-cloud on the OpenCart support forum, I think I've worked around it.
You just need to wrap some PHP around the tracking code, telling it to only show / be counted if the success message is the result of a sale. That PHP is:
<?php if (isset($this->request->get['route']) && $this->request->get['route'] == 'checkout/success') { ?>
<!-- tracking code goes here -->
<?php } ?>
Personally I put all of this just above:
<?php echo $content_bottom; ?></div>
Google says to make sure it's within body tags.
Since uploading that, I've sent a test message from the contact page, viewed the source of the success message, and not been able to see the tracking code. And placed a test order, viewed the source of the success message, and been able to see the tracking code. So whilst I'm awaiting to hear back from the people checking my client's Adwords account, all seems to be OK!
If you wish to track something other than completed purchases - perhaps account sign ups - then you need to change 'checkout/success' accordingly.
29.02.24
We are delighted to announce that 18a has been recognised for its outstanding work in the "Web Design Agency of the Year - UK" category at… Read →
27.02.24
I recently had an interesting problem to solve. I'd built a brand new author website on a shiny installation of Laravel 10, utilising its out-of-the-box… Read →
15.02.24
WordPress is the incredibly popular blogging-come-full-website platform that powers over 835 million websites* in 2024. It's functionality is extended by plugins, and one such very… Read →