How do you add conversion tracking to OpenCart when it has a shared success page?
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.