Google Ecommerce Tracking Opencart 3.0

07/28/2020

Google Ecommerce Tracking is used to track the Ecommerce related information to your Google Analytics Account. Opencart by default comes with Google Analytics using which you can track:

- Audiences
- Acquistion
- Behaviour etc

Basic Analytics Code ( Default with Opencart ):

<! - Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-XXXXXXXX-X');
</script>

Ecommerce Tracking Code ( It is not default with Openart ):

<! - Google Analytics Ecommerce Tracking Code -->

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<?php echo $ga_account_num;?>']);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
'<?php echo $grand_total;?>', // total - required
'<?php echo empty($shipping_total) ? 0 : $shipping_total;?>', // shipping
'<?php echo $city;?>', // city
'<?php echo $zone;?>', // state or province
'<?php echo $country;?>', // country
]);

// add item might be called for every item in the shopping cart
// where your Ecommerce engine loops through each item in the cart and
// prints out _addItem for each
<?php foreach($products as $product) { ?>
_gaq.push(['_addItem',
'<?php echo $order_id;?>', // transaction ID - required
'<?php echo $product["model"];?>', // SKU/code - required
'<?php echo $product["name"];?>', // product name
'<?php echo $product["price"];?>' // unit price - required
]);
<?php } ?>
_gaq.push(['_trackTrans']); //submits transaction to the Analytics servers

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == wnd.fe.Location.protocol ? 'https://ssl' : 'https://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

<! - Google Analytics Ecommerce Tracking Code -->

To make Google Ecommerce tracking to work you need to add both the codes which are only possible through the help of extension which is ready and well tested also during install your default file did not overwrite.

URL: https://www.purchasetheme.com/product/google-ecommerce-tracking-opencart/
Extension Cost: $35
Installation/Support: FREE ( Life Time )