Last active
January 22, 2019 12:10
-
-
Save Antoinebr/08d03594f748ae90ab70cc8b8957812b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
// more documentation : https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce | |
ga('require', 'ecommerce'); // You have to require the ecommerce Addon | |
ga('ecommerce:addTransaction', { | |
'id': '{{orderId}}', // Transaction ID. Required. | |
'revenue': '{{orderToal}}', // Grand Total. | |
'currency': 'EUR' | |
}); | |
// We add each item to the order | |
{{#each items}} | |
ga('ecommerce:addItem', { | |
'id': '{{orderId}}', // Transaction ID. Required. | |
'name': '{{items.name}}', // Product name. Required. | |
'sku': '{{items.sku}}', // SKU/code. | |
'price': '{{items.price}}', // Unit price. | |
'quantity': '{{items.quantity}}' // Quantity. | |
}); | |
{{/each}} | |
ga('ecommerce:send'); // send the data to GA | |
ga('ecommerce:clear'); // clear | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
window.dataLayer = window.dataLayer || [] | |
dataLayer.push({ | |
'transactionId': '1234', // the transaction id | |
'transactionTotal': 38.26, // the transaction total | |
'transactionTCurrency':'EUR', // the transaction currency | |
'transactionProducts': [ | |
// Put in an array of object all the products of the order | |
{ | |
'sku': 'DD44', | |
'name': 'T-shirt', | |
'category': 'Vêtement', | |
'price': 11.99, | |
'quantity': 1 | |
},{ | |
'sku': 'AA1243544', | |
'name': 'Chaussettes', | |
'category': 'Vêtement', | |
'price': 9.99, | |
'quantity': 2 | |
} | |
] | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment