Can I insert a Google Tag Manager Pixel using the Shopify Script Tag?

Highlighted
Tourist
9 0 0

Hi All,

I want to insert a GTM tag on a website using a custom app.

Can I insert the GTM Tag using the ScriptTag Post method given(https://shopify.dev/docs/admin-api/rest/reference/online-store/scripttag#create-2020-01)?

If Yes, What should be the content of the JS file that i am loading on the website, as the GTM tag has two parts (one to be inserted in the head and the other one in the body section)?

Can someone please help me with the same.

PFB Sample GTM code:

<!-- 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-*******');</script>
<!-- End Google Tag Manager -->

After opening of body tag:
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-*******"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

 
 
Can someone please help me out with how to insert a GTM code(above mentioned) using the Script Tag method of Shopify.
 
Thanks.
Ashlesha Deshpande
0 Likes