Skip to content

Instantly share code, notes, and snippets.

@Antoinebr
Last active January 22, 2019 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Antoinebr/08d03594f748ae90ab70cc8b8957812b to your computer and use it in GitHub Desktop.
Save Antoinebr/08d03594f748ae90ab70cc8b8957812b to your computer and use it in GitHub Desktop.
<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>
<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