Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I've done testing myself by firing purchases in different ways:
and every single time my own purchases track and the Datalayer fires & fills perfectly. However it seems whenever there's a real customer order it doesn't track. I can see that the GTM container must be active, as in GAUA I can see that they have landed on the order confirmation page at the end of their journey, it just seems as though the datalayer never fills.
Here's my DataLayer code that is in Shopify's additional checkout scripts (not a plus store):
<script>
// GTM Purchase Tracking
{% if first_time_accessed %}
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push({
'event': 'EEPurchase',
'pagePath': '/checkout/thank_you',
'pageTitle': 'Purchase',
'ecommerce':{
'purchase':{
'actionField':{
'id': '{{order.name}}',
'revenue': {{ order.total_price | money_without_currency | replace: ",", "" }},
'tax': {{order.tax_price | money | money_without_currency | replace: ",", "" }},
'shipping': {{order.shipping_price | money_without_currency | replace: ",", "" }},
'coupon': [
{% for discount_application in order.cart_level_discount_applications %}
{
'couponcode': '{{ discount_application.title }}'
},
{% endfor %}
]
},
'products':[
{% for line_item in line_items %}
{
'name': '{{line_item.title}}',
'id': '{{line_item.product_id}}',
'price':{{line_item.original_price | money_without_currency | replace: ",", "" }},
'brand': '{{line_item.vendor}}',
'category': '{{line_item.product.type}}',
{% unless line_item.variant.title == 'Default Title' %}'variant': '{{line_item.variant.title}}', {% endunless%}
'quantity': {{line_item.quantity}}
},
{% endfor %}
]
}
}
})
{% endif %}
</script>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-TRACKING-CODE');</script>
<!-- End Google Tag Manager -->
Any insight is appreciated!
Place the Analytics or GTM code inside the <head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-YOURTAG"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-YOURTAG');
{% if first_time_accessed %}
gtag('event', 'purchase', {
"transaction_id": "{{order.order_number}}",
"value": {{total_price | times: 0.01}},
"currency": "{{ order.currency }}",
"tax": {{tax_price | times: 0.01}},
"shipping": {{shipping_price | times: 0.01}},
"items": [
{% for line_item in line_items %}{
"id": "{{line_item.product_id}}",
"name": "{{line_item.title}}",
"quantity": {{line_item.quantity}},
"price": {{line_item.line_price | times: 0.01}}
},{% endfor %}
]
});
{% endif %}
</script>
Everything I've read so far has suggested this isn't possible without Shopify Plus/access to checkout.liquid and that the only way to track purchases is via Checkout > Shopify Additional Scripts. If I place it within the <head> of my theme.liquid it won't be on the order confirmation page.
Could I also ask why you prefer to use the gtag instead of just datalayer for google tag manager?
You place it in the header.liquid and it should work. It reads the thank-you page.
Whichever the customer perfers I use 🙂
Sorry but could you explain further? I don't think this is the case. The GTM tag I currently have in the <head> doesn't pull in on the thank you page, only the one I have in additional scripts shows in the inspect. Other scripts that I also have in the <head> unrelated to this issue don't pull in on the thank you page so how would it be able to track a user reaching this page if it's not there? All documentation I've read insists this has to go into the additional checkout scripts.
You put the GTAG or GTM inside the <head></head> wrapper and the additional script (in my prev. post) inside the additional scripts. And it tracks the purchases.
My GTM code is in both the <head> (for other event tracking like add to cart, product views etc) and is also in the additional scripts. The code in my original post is in the additional scripts. I unfortunately cannot use the code you provided as like I said I am going through Google Tag Manager.
My issue isn't that I don't know where to put the code, my issue is that my datalayer doesn't fire when a user reaches order confirmation. Thank you for your help but I don't think this is my issue.
Emma - Did you solve this? I'm having a similar problem for a client who doesnt have access to the checkout.liquid file - so we've put GTM code in the theme.liquid but the thank you page isn't pinging the Google Tag Manager Tag and not registering any conversions
Emma, my problem seems identical to yours. Have you found a solution?
Hi Emma, same problem here!
Did you find any solutions for that?
Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025