Clarification on GTM snippet within Additional Google Analytics Javascript

Solved
Tourist
9 1 0

I understand that the "Additional Google Analytics Javascript" field has been locked down.  However, I believe this field is still available for GA related JS.  I have been trying to add in a GTM snippet to this field but am getting a Content

Security Policy error:

 

Refused to load the script 'https://tagmanager.google.com/debug' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval' cdn.shopify.com cdn.shopify.cn cdn.shopifycloud.com app.shopify.com checkout.shopifycs.com maps.googleapis.com ajax.googleapis.com storage.googleapis.com apis.google.com pay.google.com www.google-analytics.com ssl.google-analytics.com www.gstatic.com www.googleadservices.com www.googletagmanager.com googleads.g.doubleclick.net connect.facebook.net connect.facebook.com www.paypal.com www.paypalobjects.com sandbox.paypal.com api-cdn.amazon.com payments.amazon.com eu.account.amazon.com apac.account.amazon.com payments-de.amazon.com payments-uk.amazon.com payments-jp.amazon.com static-na.payments-amazon.com static-eu.payments-amazon.com static-fe.payments-amazon.com". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

I can clearly see that www.googletagmanager.com is supported, but the fact that tagmanager.google.com is not looks like an oversight.  Is this something that can get added to the CSP?  Or alternatively, can someone explain why GTM snippets are not supported within this field?

0 Likes
Shopify Expert
96 17 12

@hthakkar1 - Can you explain what you are trying to achieve? It is fairly straight-forward to implement GTM within Shopify (as well as additional js), so thought we could start there and see what solution we can come up with :)

0 Likes
Tourist
9 1 0

Sure - given that GTM still appears to be allowed, I was simply trying to initialize my GTM snippet in the additional scripts box:

 

(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-XXXXXXX');

When I navigate to a checkout page with GTM preview enabled, I get the CSP error I mentioned.  When I navigate to a checkout page with the GTM container published, none of my GTM tags appear to be firing - it doesn't look like the snippet has even loaded on the checkout pages.  I'm looking to use GTM to fire GA enhanced ecommerce tags, as Shopify's support for that functionality is not comprehensive.

0 Likes
Shopify Expert
96 17 12

@hthakkar1 - Gotcha.  Couple things:

 

1) Have you checked out the Shopify guide on implementing GA?  It includes the ability for "Enhanced eCommerce" w/o the need for GTM

2) As you may have found out, the "Additional Scripts" box gives you access to the order confirmation page (typically used for conversion tracking snippets) but not the checkout module.  No way around that unless you are on a Shopify Plus plan. 

 

That said, we lean on this more comprehensive guide for the Shopify <--> GA integration and HIGHLY recommend based on it capturing the KPI's you're mentioning:

 

https://www.digitaldarts.com.au/google-analytics-shopify (updated frequently).

 

Hope this help and if so, feel free to mark this as "solved" so the next merchant can access the info :)

0 Likes
Tourist
9 1 0

Thanks.

 

1.  Yes, I'm familiar with the Shopify guide on implementing GA.  Unfortunately, the "Enhanced Ecommerce" checkbox doesn't actually implement all of the tags that are a part of the Google Analytics Enhanced Ecommerce suite.  That is not the main purpose of this post, but I'm happy to elaborate if you'd like.

 

2.  To be clear, I am talking about the scripts box located at Online Store > Preferences and not the one located at Settings > Checkout.  The screenshot of the one I'm referring to is included.

 

GA.png

 

Thanks for sharing the other link, I've seen this guide before and can spend some more time with it.

 

I'd like to see if there are any other comments from others on the box I'm referring to prior to closing the post.

0 Likes
Highlighted

Success.

New Member
1 1 0

@hthakkar1 same issue here. That method of integrating GTM works on all pages except for the checkout. Once you hit the checkout page you run into the errors you mentioned. 

 

Looks like the workaround for implementing GTM without a Shopify Plus plan is no longer working properly. Shopify Plus is the only plan that officially supports GTM so I'm not surprised this is happening. Since GTM has become the standard for implementing tags with media partners and teams you would think they would support it on non-enterprise level plans. Until they support GTM on all plans it seems the only method of tracking the checkout page is via standard GA. 

0 Likes
Tourist
9 1 0

@18Below  - thanks for the confirmation.  I've tried a few different methods to try and get it working but agree that this workaround is no longer available.

 

It is unfortunate, as the need to use GTM applies to all merchants and shouldn't be limited to the ones that can afford a Shopify Plus subscription.  Without this it becomes difficult to implement some of the analytics and other functionality that one could argue would help smaller merchants grow into Shopify Plus subscriptions.  Specifically in my case, we are now having to resort to other pages/workarounds to fire checkout tags as part of the GA enhanced ecommerce funnel.

0 Likes