Conversion tracking is code sends data to google analytics to keep track of ROI of your marketing campaign. The code snippet is configured in order confirmation page of your online store checkout. Some marketing professionals will call this page as 'Thank You' page too.
Google Analytics updates this code snippet on time to time basis and this code snippet illustrates how it works. The fundamentals of configuration remains the same even if the code updates.
How to configure Google Analytics Conversion code
- Go to Dashboard > Settings > Seo & Analytics > Tracking codes
- Click on 'Code for thank you page'
- Copy the conversion code in text field
- Hit Save changes
- Google Analytics ID: This is your Google Analytics unique ID e.g. UA-12345678-1 (replace this id with your own id)
- Currency: The code has USD as currency. You can change it to your relevant currency code such as GBP, INR, etc..
<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','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-12345678-1', 'auto', {'allowLinker': true}); ga('require', 'linkid', 'linkid.js'); ga('require', 'linker'); ga('linker:autoLink', ['Yourstorename.com'] ); ga('require', 'displayfeatures'); ga('require', 'ecommerce', 'ecommerce.js'); ga('send', 'pageview'); $(function(){ ga('ecommerce:addTransaction', {'id': '{{order.number}}', // Transaction ID. Required. 'revenue': '{{order.grand_total_amount}}', // Grand Total. 'shipping': '{{order.order_shipping_charge}}', // Shipping. {% if order.order_tax_amount != "All applicable taxes included in total amount" %} 'tax': '{{order.order_tax_amount}}', {% endif %} 'currency': 'USD' // local currency code. }); {% for item in order.order_line_items %} ga('ecommerce:addItem', { 'id': '{{order.number}}', // Transaction ID. Required. 'name': '{{item.name}}', // Product name. Required. 'sku': '{{item.sku}}', // SKU/code. 'price': '{{item.price}}', // Unit price. 'quantity': '{{item.quantity}}' // Quantity. }); {% endfor %} ga('ecommerce:send'); }); </script>
Configure Dynamic values in code
Google analytics captures dynamic values such as value of an order, product name etc to give you valuable insights to improve your marketing campaigns. In the above given example, following dynamics values are configured.
Data Type | Data Tag |
Transaction ID | {{order.number}} |
Grand Total | {{order.grand_total_amount}} |
Shipping | {{order.order_shipping_charge}} |
Tax | {{order.order_tax_amount}} |
Product name | {{item.name}} |
SKU/code | {{item.sku}} |
Unit price | {item.price}} |
Quantity | {{item.quantity}} |