Emma
Emma

Reputation: 31

Google Tag Manager not firing purchase event (Shopify)

I've recently been going a GTM setup on Shopify and all has been going well apart from the purchase tracking. I'm finding that every other event tracks perfectly in GAUA, GA4 and Google Ads (Add to carts, initiate checkouts, etc) but whenever somebody completes a transaction there's no record of it.

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>
{% 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 %}
          {
            '{{ 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, thanks!

Upvotes: 3

Views: 2853

Answers (2)

Mitrodol
Mitrodol

Reputation: 21

Here's what I am using for coupon and what works for me:

 'coupon': '{% for discount_application in checkout.discount_applications %}
{{ discount_application.title }}
             {% endfor %}',

Also I am not using order object as it can't be accessed sometimes when the order status page is loaded. When user refreshing thank you page only. My items array looks like this:

{% for line_item in line_items %}
                      {
       'item_id': {{ line_item.product_id }},
       'item_name' : '{{ line_item.product.title }}',
       'item_variant': '{{ line_item.variant.title }}',
       'item_brand': '{{ line_item.product.vendor }}',
       'item_category': '{{ line_item.product.type }}',
       'item_discount': {{ line_item.line_level_total_discount | divided_by: 100 }},
       'price': {{ line_item.final_price | divided_by: 100 }},
       'quantity': {{ line_item.quantity }}
        },
      {% endfor %}

Upvotes: 0

james
james

Reputation: 1

just had this issue. I think this page is disconnected form your main site for security reasons?

either way, you need to add your GTAG and event script to the settings>checkout and account>additional scrips

add the head and body tags too.

(it wont let me post actual head and body tags)

--head-- GTAG script --end head--

--body-- GTAG body script --end body--

EVENT SCRIPT HERE

worked for me

Upvotes: 0

Related Questions