Skip to content

Instantly share code, notes, and snippets.

@oguzhanozcelik
Created June 20, 2023 07:34
Show Gist options
  • Save oguzhanozcelik/4a2be8c128857a38d7eaba459f2df7e6 to your computer and use it in GitHub Desktop.
Save oguzhanozcelik/4a2be8c128857a38d7eaba459f2df7e6 to your computer and use it in GitHub Desktop.
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({ ecommerce: null });
setTimeout(function (){
dataLayer.push({
event: "purchase",
ecommerce: {
transaction_id: {{ order.id }},
shipping: {{ order.shipping_price | money_without_currency }},
value: {{ total_price }},
tax: {{ order.tax_price | money_without_currency }},
currency: "{{ order.currency }}",
items: [
{% for line_item in line_items %}{
item_id: "{{ line_item.sku }}",
item_name: "{{ line_item.title | remove: "'" | remove: '"' }}",
index: {{ forloop.index }},
item_brand: '{{ line_item.product.vendor }}',
{% for collection in line_item.product.collections %}
{% if forloop.index == 1 %}
item_category: '{{ collection.title }}',
{% else %}
item_category{{ forloop.index }}: '{{ collection.title }}',
{% endif %}
{% endfor %}
item_variant: '{{ line_item.variant.title }}',
currency: '{{ shop.currency }}',
price: {{ line_item.final_price | times: 0.01 }},
quantity: {{ line_item.quantity }}
},
{% endfor %}
]
{% if customer %},user_id:{{ order.customer.id }}{% endif %}
}
});
},1000);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment