Last active
October 31, 2023 17:43
-
-
Save lstellway/fa68e5164889d4b61f15bdbd3a5439f9 to your computer and use it in GitHub Desktop.
Shopify - GTM order confirmation
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({ 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