Skip to content

Instantly share code, notes, and snippets.

@bani
Last active August 29, 2015 14:04
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 bani/4e3fd2d4b462a8499c89 to your computer and use it in GitHub Desktop.
Save bani/4e3fd2d4b462a8499c89 to your computer and use it in GitHub Desktop.
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