I’m working on adding a custom pixel script to my Shopify store that pushes purchase event data, including detailed line items, to Google Tag Manager. I’ve written the following Liquid code to achieve this:
{% assign items = '' %}
{% for line_item in order.line_items %}
{% assign variant = '' %}
{% if line_item.title contains 'Mini' %}
{% assign variant = 'Mini' %}
{% elsif line_item.title contains 'Small' %}
{% assign variant = 'Small' %}
{% elsif line_item.title contains 'Standard' %}
{% assign variant = 'Standard' %}
{% endif %}
{% capture current_item %}
{
"item_id": "{{ line_item.variant.sku }}",
"item_name": "{{ line_item.title }}",
"variant": "{{ variant }}",
"coupon": "{{ order.discount_codes.first.code }}",
"discount": {{ line_item.total_discount | money_without_currency }},
"item_brand": "Kori Krill Oil",
"item_category": "{{ line_item.product.type }}",
"price": {{ line_item.price | money_without_currency }},
"quantity": {{ line_item.quantity }}
}
{% endcapture %}
{% if forloop.first %}
{% assign items = current_item %}
{% else %}
{% assign items = items | append: ',' | append: current_item %}
{% endif %}
{% endfor %}
var items = [{% raw %}{{ items }}{% endraw %}];
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'purchase',
event_category: 'purchase',
event_action: 'purchase',
currency: "{{ order.currency }}",
transaction_id: "{{ order.order_number }}",
value: {{ order.total_price | money_without_currency }},
tax: {{ order.tax_total | money_without_currency }},
shipping: {{ order.shipping_price | money_without_currency }},
coupon: "{{ order.discount_codes.first.code }}",
items: items
});
Same error we are facing with installing other pixels.

