Implementation of ecommerce.js

178 Views Asked by At

Currently on our order confirmation page we have :

analytics.js :

/* Google Analytics */
(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-102324575-1', 'auto');
ga('require', 'GTM-WPS5DXR');
ga('send', 'pageview');
</script>

I want complete this code to send information about transaction in google analytics. So I add this code :

ga('require', 'ecommerce');
ga('ecommerce:addTransaction', {
  'id': 'order_number',                    
  'affiliation': 'affiliate1',   
  'revenue': 'order_amount',               
  'shipping': 'shipping_cost',                  
  'tax': 'tax_amount'                     
});  '',
  'currency': 'EUR'
});

ga('ecommerce:addItem', {
  'id': 'order_id',                     
  'name': 'product_name',    
  'price': 'product_price',                 < ! -- Unit price -- >
  'quantity': 'product_quantity'         
});

ga('ecommerce:send');

With that is it correct ?

Thanks a lot !

2

There are 2 best solutions below

4
Michele Pisani On

There is an inconsistence in this part:

});  '',
  'currency': 'EUR'
});

The currency parameter must be specified within the ecommerce:addTransaction block and the ecommerce:addItem block. See an example in the documentation below:

https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#multicurrency

0
Amelie9559 On

Sorry for my silence :) My IT team is really busy. It's online now and It's works ! Thanks a lot.

But now I would like linked the ecommerce parameters with the goals parameters. Currently I have ecommerce tracking with value of orders and one goal with 'purchase ok' defined on url of thank you page but without dynamic amount. If I put this code on my thank you page, the value of goal 'purchase' will be linked and similar with ecommerce parameters ?

gtag('event', 'purchase', {
  'value': '$value of order'
});