FROM CACHE - en_header

Shopify Plus + GTM Integration for Checkout

8 0 1

We're launchign a new website but keeping Shopify for checkout purposes. Thus, we're going to have checkout.liquid but not theme.liquid.

Right now GTM works on the checkout pages because I've stripped the <script> </script> part of the snippet and placed it into the preferences section (this is just a hack workaround for the moment) but no matter what I try in terms of configuration, the data layer never comes to life.

The data layer message WILL pop up in debug mode, but none of the ecommerce or product information comes up.

Anyone encounter this issue workign with Shopify Plus and GTM?

Here's my set up:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<html lang="{{ locale }}" dir="{{ direction }}" class="{{ checkout_html_classes }}">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, height=device-height, minimum-scale=1.0, user-scalable=0">
    <meta name="referrer" content="never">

    <title>{{ }} - {{ page_title }}</title>
        window.dataLayer = window.dataLayer || [];
    <!-- Google Tag Manager -->
    new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    <!-- End Google Tag Manager -->
          var SUB_TOTAL = {{ checkout.subtotal_price | money_without_currency }};
    <!-– Oracle Maxymiser Script Start -->
    <script type="text/javascript" src="//"></script>
    <!–- Oracle Maxymiser Script End -->
    {{ content_for_header }

    {{ checkout_stylesheets }}
    {{ checkout_scripts }}
    <!-- Google Tag Manager (noscript) -->
    <noscript><iframe src=""
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <!-- End Google Tag Manager (noscript) -->

Additional scripts:

 {% if first_time_accessed %}
            'ecommerce': {
              'purchase': {
                'actionField': {
                  'id': {{ checkout.order_number }},                         // Transaction ID. Required for purchases and refunds.
                  'affiliation': 'Online Store',
                  'revenue': '{{ checkout.total_price | money_without_currency }}',                     // Total transaction value (incl. tax and shipping)
                  'tax': '{{ checkout.tax_price | money_without_currency }}', 
                  'shipping': '{{ checkout.shipping_price | money_without_currency }}',
                  {% for discount in checkout.discounts %}
                      'coupon': {{ discount.code }},
                  {% endfor %}
                'products': [
                {% for item in checkout.line_items %} 
                     'name': {{ item.product.title | strip_html | json }},        
                     'id': "{{ }}",
                     'price': {{ item.price | money_without_currency }},
                     'brand': {{ item.vendor }},
                     'quantity': {{ item.quantity }}
                {% endfor %} 
{% else %}
console.log("GTM NOT FIRED!");
{% endif %}

Preferences: (Note: I realize the below is a hack intended for non-Plus customers to workaround GTM)

new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],

Replies 2 (2)
New Member
2 0 0

This is what worked for us, to get GTM on the shop and checkout pages

  • Log in to the Admin interface
  • Go to the “Online Store” option and select “preferences”
  • Under the “Google Analytics” section, Select “Additional Google Analytics Javascript”
  • Add your GTM code, and be sure to exclude the script tags (Shopify will enclose the content you enter in script tags by default)

Description with images:

New Member
4 0 0

So if using GTM to track purchases,( I currently use the additional scripts with the first_time_accessed without GTM), but to use GTM what you are doing is sending all that info to an ecommerce that GTM can now access. 

So I'd basically need to check for that ecommerce variable in my custom GTM script. Even if I am not using shopify plus, I should still be able to put that in additional scripts