Last active
June 21, 2024 02:14
-
-
Save benjaminmangold/1944b3656ba38c5a26b930cf8f28e7b2 to your computer and use it in GitHub Desktop.
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
<!-- Google tag (gtag.js) --> | |
<script async src="https://www.googletagmanager.com/gtag/js?id=G-EXAMPLE"></script> | |
<script> | |
window.dataLayer = window.dataLayer || []; | |
function gtag(){dataLayer.push(arguments);} | |
gtag('js', new Date()); | |
gtag('config', 'G-EXAMPLE'); | |
{% if first_time_accessed %} | |
gtag("event", "purchase", { | |
transaction_id: "{{ checkout.order_id }}", | |
value: {{ total_price | times: 0.01 }}, | |
tax: {{ tax_price | times: 0.01 }}, | |
shipping: {{ shipping_price | times: 0.01 }}, | |
currency: "{{ checkout.currency }}", | |
items: [ | |
{% for line_item in line_items %} | |
{ | |
item_id: "{{ line_item.product_id }}", | |
item_name: "{{ line_item.title | remove: "'" | remove: '"' }}", | |
currency: "{{ checkout.currency }}", | |
price: {{ line_item.original_price | times: 0.01 }}, | |
quantity: {{ line_item.quantity }} | |
}, | |
{% endfor %} | |
] | |
}); | |
{% endif %} | |
</script> |
Yeah I don't think that help page is right any more. Check your store orders for anything with a confirmation number in the order activity and then check to see if that order was tracked by GA4.
Mine all have an order number, but feel free to customize as you need.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It’s based on Shopify’s own recommendation for conversion tracking on the order status page. See https://help.shopify.com/en/manual/orders/status-tracking/customize-order-status/add-conversion-tracking
So if their documentation isn’t right, you might want to customize it, but it works for my Shopify store.