Skip to content

Instantly share code, notes, and snippets.

@lstellway
Last active October 31, 2023 17:43
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 lstellway/fa68e5164889d4b61f15bdbd3a5439f9 to your computer and use it in GitHub Desktop.
Save lstellway/fa68e5164889d4b61f15bdbd3a5439f9 to your computer and use it in GitHub Desktop.
Shopify - GTM order confirmation
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({ ecommerce: null });
{% if first_time_accessed %}
dataLayer.push({
event: "dime_purchase",
ecommerce: {
transaction_id: "{{ order.order_number }}",
value: {{ total_price | times: 0.01 }},
tax: {{ tax_price | times: 0.01 }},
shipping: {{ shipping_price | times: 0.01 }},
currency: "{{ order.currency }}",
discounts: "{{ order.currency }}",
{% if customer.orders.size > 1 %}
customer_type: "returning",
{% else %}
customer_type: "new",
{% endif %},
items: [
{% for line_item in line_items %}
{
item_id: "{{ line_item.product_id }}",
item_name: "{{ line_item.title | remove: "'" | remove: '"' }}",
currency: "{{ order.currency }}",
price: {{ line_item.final_price | times: 0.01 }},
quantity: {{ line_item.quantity }}
},
{% endfor %}
],
discounts: [
{% for discount in order.discount_applications %}
"{{ discount.title }}",
{% endfor %}
],
customer: {
has_account: {{ customer.has_account }}
}
},
});
{% endif %}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment