Acquia Source CMS provides HTML snippets to insert custom Hypertext Markup Language (HTML), JavaScript, and tracking code into site <head> and <body> sections without theme file modification or code deployment. Third-party integrations require script tags or meta tags on a site. The HTML snippets configuration form provides a secure method to perform these additions in Content Security Policy (CSP) constraints.
To add HTML snippet:
On the left navigation menu, click Configuration.
The system displays the Configuration menu.
Start of <head>: Use this field for scripts that must load early such as consent managers, Search Engine Optimization (SEO) verification tags, or analytics base scripts.
Allowed tags include script, style, meta, link, title, and noscript.
End of <body>: Use this field for scripts that render User Interface (UI) elements such as chat widgets, feedback tools, or accessibility overlays.
Allowed tags include script, div, span, noscript, iframe, and img.
Acquia Source CMS enforces a strict CSP to protect sites from Cross-Site Request Forgery (CSRF) and Cross-Site Scripting (XSS) attacks. When you add <script> tags through HTML snippets, the system assigns a cryptographic nonce to each script tag. This nonce enables script execution without a reduction in site security.
Scripts that inject dynamically at runtime such as those through Google Tag Manager (GTM) Custom HTML tag types do not receive a nonce. CSP blocks these scripts to maintain site security.
Insert code for third-party tools such as chat widgets, accessibility tools, or consent banners, directly through HTML Snippets.
If you use external tools such as GTM to inject these scripts, you must configure your tags to pass the CSP nonce. Otherwise, the browser's Content Security Policy (CSP) will block the script injection to protect the site from Cross-Site Scripting (XSS) attacks. Standard market analysis tags and analytics in GTM work without additional configuration.
Script type determines the selection between GTM and HTML snippets.
When configuring Google Tag Manager on Acquia Source CMS, you must choose how to handle custom inline scripts so they comply with the platform's Content Security Policy (CSP).
Choose the approach that best fits your implementation:
The nonce passthrough method captures the platform-generated CSP nonce at runtime. This method makes the nonce available to all Custom HTML tags in GTM container to execute them securely.
The nonce passthrough method captures the platform-generated CSP nonce at runtime and makes it available to all Custom HTML tags in the GTM container to execute them securely.
Acquia Source CMS applies a CSP nonce to the GTM snippet when you add it through HTML snippets. The document.currentScript.nonce property captures this nonce at execution time before the browser removes it from the Document Object Model (DOM). GTM templates the nonce value into every Custom HTML tag that references the {{csp-nonce}} variable. This method ensures all Custom HTML tags remain in the GTM container with intact page-specific triggers and sequences.
GTM Custom JavaScript variables do not work on Acquia Source CMS sites. GTM executes these variables with eval() and new Function(), which the platform's CSP policy blocks because it does not allow unsafe-eval.
Instead, Acquia recommends using Custom Variable Templates. Because these templates run in a sandboxed JavaScript environment, they bypass the need for eval() and function securely without requiring any CSP changes.
To create a template:
The nonce passthrough configuration workflow consists of the following tasks:
| S.No. | Task | Description |
|---|---|---|
| 1. | Replace the standard GTM snippet in HTML snippets to capture the platform-generated nonce. | |
| 2. | Create a specific variable in the GTM workspace to store the captured nonce. | |
| 3. | Add the nonce attribute to each Custom HTML tag that contains inline scripts. |
To update the GTM snippet in HTML snippets:
Replace the standard GTM snippet in the HTML snippets form at /admin/config/search/html-snippets with the following version. This snippet captures the platform-generated nonce and pushes it to the dataLayer:
<script>
(function(w,d,s,l,i){
w[l]=w[l]||[];
var currentNonce = d.currentScript ? d.currentScript.nonce : '';
w[l].push({'csp_nonce': currentNonce});
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-XXXXXX');
</script>To create a Data Layer Variable in GTM:
csp_nonce as the Data Layer Variable Name.csp-nonce to name the variable.To update Custom HTML tags:
In each Custom HTML tag that contains inline scripts, add the nonce attribute with the variable created previously in task: Create a Data Layer Variable in GTM:
<script nonce="{{csp-nonce}}">
// your existing inline JavaScript here
</script>Start of <head>: Use this field for scripts that must load early such as consent managers, Search Engine Optimization (SEO) verification tags, or analytics base scripts.
Allowed tags include script, style, meta, link, title, and noscript.
End of <body>: Use this field for scripts that render User Interface (UI) elements such as chat widgets, feedback tools, or accessibility overlays.
Allowed tags include script, div, span, noscript, iframe, and img.
Acquia Source CMS enforces a strict CSP to protect sites from Cross-Site Request Forgery (CSRF) and Cross-Site Scripting (XSS) attacks. When you add <script> tags through HTML snippets, the system assigns a cryptographic nonce to each script tag. This nonce enables script execution without a reduction in site security.
Scripts that inject dynamically at runtime such as those through Google Tag Manager (GTM) Custom HTML tag types do not receive a nonce. CSP blocks these scripts to maintain site security.
Insert code for third-party tools such as chat widgets, accessibility tools, or consent banners, directly through HTML Snippets.
If you use external tools such as GTM to inject these scripts, you must configure your tags to pass the CSP nonce. Otherwise, the browser's Content Security Policy (CSP) will block the script injection to protect the site from Cross-Site Scripting (XSS) attacks. Standard market analysis tags and analytics in GTM work without additional configuration.
Script type determines the selection between GTM and HTML snippets.
When configuring Google Tag Manager on Acquia Source CMS, you must choose how to handle custom inline scripts so they comply with the platform's Content Security Policy (CSP).
Choose the approach that best fits your implementation:
The nonce passthrough method captures the platform-generated CSP nonce at runtime. This method makes the nonce available to all Custom HTML tags in GTM container to execute them securely.
The nonce passthrough method captures the platform-generated CSP nonce at runtime and makes it available to all Custom HTML tags in the GTM container to execute them securely.
Acquia Source CMS applies a CSP nonce to the GTM snippet when you add it through HTML snippets. The document.currentScript.nonce property captures this nonce at execution time before the browser removes it from the Document Object Model (DOM). GTM templates the nonce value into every Custom HTML tag that references the {{csp-nonce}} variable. This method ensures all Custom HTML tags remain in the GTM container with intact page-specific triggers and sequences.
GTM Custom JavaScript variables do not work on Acquia Source CMS sites. GTM executes these variables with eval() and new Function(), which the platform's CSP policy blocks because it does not allow unsafe-eval.
Instead, Acquia recommends using Custom Variable Templates. Because these templates run in a sandboxed JavaScript environment, they bypass the need for eval() and function securely without requiring any CSP changes.
To create a template:
The nonce passthrough configuration workflow consists of the following tasks:
| S.No. | Task | Description |
|---|---|---|
| 1. | Replace the standard GTM snippet in HTML snippets to capture the platform-generated nonce. | |
| 2. | Create a specific variable in the GTM workspace to store the captured nonce. | |
| 3. | Add the nonce attribute to each Custom HTML tag that contains inline scripts. |
To update the GTM snippet in HTML snippets:
Replace the standard GTM snippet in the HTML snippets form at /admin/config/search/html-snippets with the following version. This snippet captures the platform-generated nonce and pushes it to the dataLayer:
<script>
(function(w,d,s,l,i){
w[l]=w[l]||[];
var currentNonce = d.currentScript ? d.currentScript.nonce : '';
w[l].push({'csp_nonce': currentNonce});
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-XXXXXX');
</script>To create a Data Layer Variable in GTM:
csp_nonce as the Data Layer Variable Name.csp-nonce to name the variable.To update Custom HTML tags:
In each Custom HTML tag that contains inline scripts, add the nonce attribute with the variable created previously in task: Create a Data Layer Variable in GTM:
<script nonce="{{csp-nonce}}">
// your existing inline JavaScript here
</script>If this content did not answer your questions, try searching or contacting our support team for further assistance.
If this content did not answer your questions, try searching or contacting our support team for further assistance.