Advertisement
Vojkovic

Purshase event on Thank you page

Dec 27th, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. <script>
  2. window.dataLayer = window.dataLayer || [];
  3. {% if first_time_accessed %}
  4. window.dataLayer.push({ ecommerce: null });
  5. window.dataLayer.push({
  6. event: "purchase",
  7. ecommerce: {
  8. transaction_id: "{{ order.order_number }}" || "{{ checkout.id }}",
  9. value: {{ total_price | times: 0.01 }},
  10. tax: {{ tax_price | times: 0.01 }},
  11. shipping: {{ shipping_price | times: 0.01 }},
  12. currency: "{{ shop.currency }}",
  13. items: [
  14. {% for line_item in line_items %}
  15. {
  16. item_id: "{{ line_item.product_id }}",
  17. item_name: "{{ line_item.title | remove: "'" | remove: '"' }}",
  18. currency: "{{ shop.currency }}",
  19. price: {{ line_item.original_price | times: 0.01 }},
  20. quantity: {{ line_item.quantity }}
  21. },
  22. {% endfor %}
  23. ]
  24. }
  25. });
  26. {% endif %}
  27. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement