I have added the following script in my Magento website’s order confirmation page, but still, I am unable to track e-commerce data. Please help me to track e-commerce data in Google Analytics.
<script async src="https://www.googletagmanager.com/gtag/js?id=UA 000000000-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'thansactionId' : '<?php echo $orderId; ?>',
'currency': 'GBP',
'event' : 'conversion',
'Grandtotal': '<?php echo $grandtotal; ?>',
'status': '<?php echo "$status";?>',
'storename': '<?php echo "$storename";?>',
'shippingmethod': '<?php echo "$shipping";?>',
'shippinamount': '<?php echo "$shippingamount";?>'
});
</script>
I am not using the Google Tag Manager, So I want the solution for Google Analytics only.
2
Answers
After hours of research I have found following script for my case as I am using analytics.js for my website. Let me know is it correct or not?
You are not using Google Tag Manager (GTM), but you are using data format of GTM. As per GTAG documentation, the (standard ecommerce) transaction tracking code is the following for gtag():
You can fill in the variables from your PHP code, and optionally include product data as well.
Enhanced ecommerce format is available here.