Search code examples
javascriptgoogle-analyticsanalyticstracking

Google ecommerce analytics not working


First of all, I am a beginner to analytics and JavaScript.

I am trying to add Google analytics for my e-commerce shopping website implemented in Opencart.

The idea is to get details of most viewed products, products added to cart, most ordered product, top category, demographics etc.

In the first step to test e-commerce analytics, I copied the tracking code snippet to Extentions > Analytics > Google analytis (Installed) > 'Google analytics code' in Opencart console.

snippet:

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-xxxxx-y', 'auto');
ga('require', 'ecommerce', 'ecommerce.js');

ga('ecommerce:addTransaction', {
    'id': '1000',
    'affiliation': 'something',
    'revenue': '200',
    'shipping': '10',
    'tax': '33.32'
});

ga('ecommerce:addItem', {
    'id': '1000',
    'name': 'red-shoes',
    'sku': 'RS-M',
    'category': 'Mens Shoes',
    'price': '100',
    'quantity': '2'
});

ga('ecommerce:send');
ga('send', 'pageview');

</script>

I have enabled E-commerce in Admin > E-commerce settings > 'Enable e-commerce' in Google analytics console.

But no e-commerce data is been displayed in google analytics reporting console. Only the informations like, Real-time overview, Active users now, locations, Top active pages are showing in the reporting page.

E-commerce report overview

Is there any settings that i missed? or did i do it wrong?


Solution

  • Your code is from classic GA E-commerce but report you're checking is from enhanced e-commerce (they're slightly different, enhanced e-commerce has more reports and data). Implement full enhanced e-commerce on site (docs: https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce) or disable "Enhanced E-commerce Reporting" in admin panel and leave code you already have.

    You can also check here great demo how to implement enhanced e-commerce: https://enhancedecommerce.appspot.com