How to track conversions and their value in OpenCart
In this article we will explain how to track the conversions of an OpenCart store and pass conversion values to Google Analytics (GA4) and Google Ads. Detailed information about conversions allows you…
In this article we will explain how to track the conversions of an OpenCart store and pass conversion values to Google Analytics (GA4) and Google Ads.
Detailed information about conversions allows you to monitor the effectiveness of an advertising campaign or search engine optimization strategy of your online store. Statistics on the dynamics of conversion values over a certain period make it possible to assess overall revenue and return on advertising or optimization spend.
You can track the overall website statistics by inserting the "gtag" tracking code. In OpenCart it can be added through the standard module, which can be found under Extensions > Extensions > select the extension type "Analytics" > Google Analytics.
In order to track events such as conversions, you need to additionally integrate the event code into buttons or pages. For this you can use ready-made modules or add the code yourself.
To track conversions in OpenCart and pass their value to Google Analytics and related services, you need to determine exactly where each conversion takes place. As the first example, we will track a successful order checkout and pass order data — such as the list of products, their prices, and quantities — to GA4. The conversion page in this case will be the OpenCart order success page, to which the buyer is automatically redirected after paying for the order. It is worth noting that for various configurations of payment methods and checkout modules, the order success page on your site may be a different, non-standard page. We are giving an example for the standard order success page, which usually has the URL index.php?route=checkout/success or its SEO-friendly version.
How to pass OpenCart conversion values
So let's move on to the instructions for integrating the "order" conversion tracking code and show how to pass the conversion value. This guide is for OpenCart 3 and OpenCart 4, however it will also work in OpenCart 2 if you convert the twig code into PHP.
1. In the file catalog/controller/checkout/success.php
right after the line:
if (isset($this->session->data['order_id'])) { you need to add:
$this->load->model('checkout/order');
$data['order_info'] = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$data['products'] = $this->model_checkout_order->getOrderProducts($this->session->data['order_id']); 2. In the file catalog/view/theme/template/template/common/success.twig
before the line:
{{ footer }} you need to add:
{% if order_info %}
{% endif %} In this case we are sending the "purchase" conversion, which is one of the standard ones. If needed, you can change the conversion name.
If you want to send only orders with a certain order status, modify the previous code by "wrapping" it in an order status check:
{% order_info and order_info.order_status_id == '5' %}
event script goes here
{% endif %} 3. After this you need to refresh all possible caches you have. This can be done in the admin panel: modifications cache, twig template cache (theme cache), and the cache of any dedicated caching modules.
As you can see, it is not difficult at all. Using this method you can track various conversions in OpenCart.