The discussion revolves around resolving an issue where a GTM script is being blocked by a Content Security Policy (CSP).
Initial Issue and Setup tyf shared a screenshot of the blocked script and provided the GTM script code, which was set up following instructions to add GTM to Discourse. The https://www.googletagmanager.com domain was added to the allowlist.
Potential Solutions Lilly pointed to a similar topic discussing GTM script loading issues due to CSP, while tyf mentioned following the linked documentation but still experiencing issues. MarkDoerr suggested adding more scripts to the CSP allowlist, handling nonce errors in GTM, and using the wildcard domain https://*.googletagmanager.com instead.
Follow-up and Remaining Issues tyf thanked MarkDoerr for the suggestions and will reach out to the team to address the nonce handling and additional blocked scripts. Despite allowlisting the GTM domain, CSP-related errors persist in Chrome and Firefox, but not in Brave or Safari.
<!-- 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-XXXX');</script>
<!-- End Google Tag Manager -->
I’m following the instructions here to add GTM to discourse. I’ve removed the GA ID as stated in the article, as well as added https://www.googletagmanager.com to our allowlist.
Hey @Lilly! I didn’t see that topic in particular, but I did follow the documentation that it links to. I’ve allowlisted https://www.googletagmanager.com
I’ll need to reach out to the team that handles these scripts and mention nonce handling as well, thanks for pointing these out!
Odd, with either https://www.googletagmanager.com or https://*.googletagmanager.com allowlisted there aren’t any CSP related errors for the GTM script in particular in Brave nor Safari, just Chrome and Firefox.