Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code to be added to Checkout under "Additional content & scripts" in order to send transaction data to Google Analytics using Enhanced Ecommerce (Universal)
<script type="text/javascript">
{% for line_item in order.line_items %}
ga('ec:addProduct', {
'id': '{{line_item.id}}',
'name': '{{line_item.product.title}}',
'category': '{{line_item.product.type}}',
'brand': '{{line_item.vendor}}',
'variant': '{{line_item.variant.option1}} {{line_item.variant.option2}} {{line_item.variant.option3}}',
'price': '{{line_item.price | money_without_currency}}',
'quantity': {{line_item.quantity}}
});
{% endfor %}
ga('ec:setAction', 'purchase', {
'id': '{{order.order_number}}',
'revenue': '{{order.total_price | money_without_currency}}',
'tax': '{{order.tax_price | money_without_currency}}',
'shipping': '{{order.shipping_price | money_without_currency}}',
'coupon': '{% for discount in order.discounts %}{{discount.code}}{% endfor %}'
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment