The following code is to be inserted in checkout.liquid immediately before {{ checkout_scripts }}


<!-- Google Tag Manager App Start -->
    <script>
if (window.location.href.includes('thank_you') !== true) { 
var Shopify = [];
      Shopify["shop"] = "{{ shop.permanent_domain }}";
function loadjQuery(url, success){
     var script = document.createElement('script');
     script.src = url;
     var head = document.getElementsByTagName('head')[0],
     done = false;
     head.appendChild(script);
    
script.onload = script.onreadystatechange = function() {
    if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
         done = true;
         success();
         script.onload = script.onreadystatechange = null;
         head.removeChild(script);        
    }
};
}

if (typeof jQuery == 'undefined'){

loadjQuery('https://code.jquery.com/jquery-3.6.1.min.js', function() {
jQuery('head').append('<script src="https:\/\/gtmfsstatic.getgoogletagmanager.com\/js\/gtmfsv2.js?shop={{ shop.permanent_domain }}"><\/script>');
      });

 } else {
jQuery('head').append('<script src="https:\/\/gtmfsstatic.getgoogletagmanager.com\/js\/gtmfsv2.js?shop={{ shop.permanent_domain }}"><\/script>');

 }
}
</script>
 <!-- Google Tag Manager App End -->