Last active
November 8, 2022 18:17
-
-
Save janhenriklambrechts/f834079c006bd393136dc099afe6ecdf to your computer and use it in GitHub Desktop.
Correct Purchase Event Tracking
This file contains 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 that tracks Purchase events at Shopify checkout to forward in GTM | |
// From GTM it can be sent to Google Ads, where Google Ads will process currency conversion | |
// However, ~20% of events will be blocked by ad-blockers, if you want to capture all events you will need a tool like Converge | |
// Contact me at jan [at] runconverge [dot] com to learn more. | |
<script> | |
window.dataLayer = window.dataLayer || []; | |
dataLayer.push({ ecommerce: null }); | |
dataLayer.push({ | |
event: "purchase", | |
ecommerce: { | |
transaction_id: "{{ checkout.order_number}}", | |
value: {{ checkout.subtotal_price | money_without_currency | replace:',','.' }}, | |
tax: {{ tax_price | times: 0.01 }}, | |
shipping: {{ shipping_price | times: 0.01 }}, | |
currency: "{{ order.currency }}", // Make sure you send the currency variable so Google Ads can convert themselves | |
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 %} | |
] | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment