Custom Loader power-up
Updated Nov 17, 2026
The Custom Loader power-up minimizes the impact of ad blockers on your GTM and GA4 scripts by routing them through a path that turns all cookies into first-party cookies.
Custom Loader is available on the Free subscription plan and higher. To check your current plan or upgrade, go to your sGTM container settings.
How to set up Custom Loader
1. Log in to your Stape account and select your sGTM container from the dashboard.

2. Go to Power-ups and click on the Custom Loader panel in the Track and Recovery section.

3. Toggle the Custom Loader switch to enable it.

4. If you want to encode tracking requests sent from the browser to your sGTM container, toggle the Enhanced ad blocker protection. By masking recognizable URL patterns and tracking signatures, it prevents ad blockers from identifying and intercepting those requests.
5. Click Save changes.

6. In the Code & Setup information section, choose the Platform - here you can either:
- Select your CMS platform (such as Shopify, Wordpress, etc.). In this case, you’ll be required to install and configure a Stape app.
- Select Other to receive a JS snippet in case you’re using another platform or a custom website.
Testing
To verify the setup is working:
- 1.Open any page on your website.
- 2.Right-click → Inspect → open the Network tab.
- 3.Filter requests by your custom subdomain or same-origin path.
- 4.Look for the GTM request URL - it should return a
200 OKstatus code.

Note:
With Custom Loader and enhanced ad blocker protection enabled, GA4 request URLs will appear encrypted.
How to use Custom Loader with GTM Environments
GTM Environments let you load a specific version of your container (e.g., staging or development) instead of the published version. If you use environments, you need to manually add the environment parameters to your Custom Loader code.
1. Get your environment parameters.
- In web GTM, go to Admin → Environments.

- Find your environment and click Actions → Get Snippet.

- Copy the three parameters from the snippet URL: gtm_auth, gtm_preview, and gtm_cookies_win.

2. Add the environment parameters to the head snippet.
Where you add the parameters depends on whether your Custom Loader snippet uses Cookie Keeper.
3. Add the environment parameters to the body snippet.
Do the same for the body snippet:

Append the same parameters to the iframe URL in the body snippet (replace the gtm_auth, gtm_preview, and gtm_cookies_win in the example with your own respective parameters):
<noscript><iframe src="https://your-subdomain.stape.work/ns.html?id=GTM-XXXXXX>m_auth=XXXX>m_preview=env-N>m_cookies_win=x" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>| Environment parameters are tied to a specific environment. If you regenerate your Custom Loader snippet (e.g. after changing settings), you'll need to re-add the environment parameters manually, since they are not saved by Custom Loader. |
How to use Custom Loader with a custom dataLayer
There are cases where you might need a custom dataLayer. This is usually when the standard eCommerce events from a CMS apps aren't enough, for example when you need extra events or extra data in existing events, or when the platform is fully custom. The Stape CMS apps can't help you with this, so instead open the Custom Loader power-up in your Stape container, select Other as the platform, and generate the code.
This article uses customDataLayer as an example. Replace it with your actual data layer name.
1. Find the function call at the end of your Custom Loader snippet, and replace dataLayer with customDataLayer:
})(window,document,'script','dataLayer','YOUR_EXISTING_ENCODED_VALUE');2. Append &l=customDataLayer to the existing encoded value. YOUR_EXISTING_ENCODED_VALUE is a placeholder. Keep the original encoded value from your generated Stape snippet. The updated function call should look like this:
})(window,document,'script','customDataLayer','YOUR_EXISTING_ENCODED_VALUE&l=customDataLayer');Important:
- Use a lowercase letter
lin&l=. - The name after
&l=must exactly match the name in the fourth argument, including capitalization.
Here's the example of an original Custom Loader code:

Here's how the snippet looks like when modified with a custom data layer name:

3. Add the modified Custom Loader code to all pages of your website, as high up as possible in the <head> section.
Replace any existing GTM or Custom Loader installation for the same container to avoid loading it twice.
4. Update your website scripts and integrations to send events to the custom data layer. Initialize the array before its first use. Continue using .push() to add events and values without clearing existing data.
window.customDataLayer = window.customDataLayer || [];
window.customDataLayer.push({
event: 'custom_event',
custom_parameter: 'value'
});
5. Test the setup:
5.1. Open your website and go to Developer Tools → Network.
5.2. Find the Custom Loader script request. Confirm that its URL includes &l=customDataLayer and that it returns 200 OK.
5.3. Open Preview mode in your GTM container, and run the event push example above in your website’s browser console.
If the event does not appear, check that the loader and event pushes use exactly the same data layer name.
How to use Custom Loader with a CSP nonce
If your website uses a nonce-based Content Security Policy (CSP), you need to add the nonce to your Custom Loader snippet. Open the Custom Loader power-up in your Stape container, select Other as the platform, and generate the code.
1. Your website’s backend must generate a random, unpredictable nonce for each HTML response. The same value must appear in the CSP header and the Custom Loader’s <script> tag. See Google’s guidance on GTM and CSP.
For example, the nonce entry in the CSP header may look like this:
Content-Security-Policy: script-src 'nonce-{{CSP_NONCE}}';Ask your developer to merge the nonce entry into your website’s existing policy. If the policy defines script-src-elem, include the nonce in that directive.
Important:
{{CSP_NONCE}} is a placeholder for a value inserted by your backend. Use your framework’s template syntax and generate a fresh value for each response. Read more About nonce generation.
2. Make two changes to your existing Custom Loader snippet:
- Add
nonce="{{CSP_NONCE}}"to the opening<script>tag.
- Copy that nonce to the dynamically created script before inserting it into the page.
The updated snippet should follow this structure:
<script nonce="{{CSP_NONCE}}">
(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),
n = d.currentScript;
j.async = true;
j.src = "https://YOUR_TRACKING_DOMAIN/YOUR_LOADER_FILE.js?" + i;
// Pass the nonce to the external Custom Loader script.
if (n && n.nonce) {
j.setAttribute('nonce', n.nonce);
}
f.parentNode.insertBefore(j, f);
})(window,document,'script','dataLayer','YOUR_EXISTING_ENCODED_VALUE');
</script>
Keep the tracking domain, script filename, and encoded value from your own generated Stape snippet.
The code reads the nonce from the currently executing inline script through document.currentScript and applies it to the external script.
Example:

3. Replace your existing Custom Loader snippet with the modified code on all pages where it's installed. Place it as high up as possible in the <head> element.
Note:
Ensure that your backend replaces the nonce placeholder with the value used in that page response’s CSP header.
4. Test the setup:
4.1. Open Developer Tools → Network and reload your website.
4.2. Check the main HTML response’s CSP header and confirm that it contains the generated nonce.
4.3. Confirm that the Custom Loader script loads successfully and returns 200 OK.
4.4. Check Console for CSP errors related to the inline snippet or the external loader.
4.5. Open Preview mode in your GTM container to confirm that the container loads and your tags work as expected.
Note:
A nonce authorizes script execution. Your CSP must also allow the connections and other resources required by your tags, including your tracking domain where applicable. See Google’s CSP requirements for GTM and Google tags.
How to add a fallback to Custom Loader
This implementation loads your web Google Tag Manager container through the Custom Loader. If a network or DNS issue prevent successful delivery, it automatically falls back to loading directly from www.googletagmanager.com.
This example is applicable for a Custom Loader installation without Cookie Keeper. Open the Custom Loader power-up in your Stape container, select Other as the platform, and generate the code.
1. Replace these three values at the top of the code:
| Setting | What to enter |
gtmContainerId | Your web GTM container ID. |
trackingServerUrl | The domain used by your Custom Loader, including https://. |
customLoaderPath | Everything after the domain in your generated Custom Loader URL, including the .js filename and the complete query string. |
For example, if your generated URL is:
https://track.example.com/abcdef.js?xyz=ENCODED_VALUE
Use https://track.example.com as trackingServerUrl and /abcdef.js?xyz=ENCODED_VALUE as customLoaderPath. Copy paste the values exactly as they are.
2. Replace your existing Custom Loader snippet with this code. Add it to all pages of your website, as high up as possible in the <head> element.
If you use a custom data layer name, in the last line replace dataLayer with that name and use the same name in your event pushes.
<script>
(function(w,d,s,l){
// Replace these three values with your own.
var gtmContainerId = 'GTM-XXXXXXX';
var trackingServerUrl = 'https://track.example.com';
var customLoaderPath = '/YOUR_LOADER_FILE.js?YOUR_ENCODED_QUERY_STRING';
w[l] = w[l] || [];
w[l].push({'gtm.start': new Date().getTime(), event: 'gtm.js'});
var firstScript = d.getElementsByTagName(s)[0];
var layerParam = l !== 'dataLayer' ? '&l=' + encodeURIComponent(l) : '';
var script = d.createElement(s);
script.async = true;
script.onerror = function(){
script.onerror = null;
var fallback = d.createElement(s);
fallback.async = true;
fallback.src = 'https://www.googletagmanager.com/gtm.js?id=' +
encodeURIComponent(gtmContainerId) + layerParam;
firstScript.parentNode.insertBefore(fallback, firstScript);
};
script.src = trackingServerUrl.replace(/\/+$/, '') + '/' +
customLoaderPath.replace(/^\/+/, '') + layerParam;
firstScript.parentNode.insertBefore(script, firstScript);
})(window,document,'script','dataLayer');
</script>
3. Test the fallback:
3.1. Open Developer Tools → Network and reload your website. Confirm that the Custom Loader script loads successfully.
3.2. Temporarily block only the Custom Loader script URL using your browser’s request blocking feature.
3.3 Reload the page and confirm that a request to www.googletagmanager.com/gtm.js?id=YOUR_GTM_ID appears.
3.4. Remove the request blocking rule after testing.
Note:
The fallback starts when the browser reports a script loading failure. It doesn't detect errors inside a successfully downloaded script. This fallback restores only the loading of the container. If your tags send events to an unavailable tracking server, those requests will still fail.
Use case
A sample scenario is an eCommerce store that sees significant data loss because a large share of its users have ad blockers installed. By enabling Custom Loader, all GTM and GA4 scripts load from a first-party domain, so ad blockers no longer recognize and block them.
You can spot the data loss this way:
- 1.Compare the order count in your backend against Purchase events in GA4 for the same period. If your backend shows 500 purchases but GA4 only reports 380, the gap could be caused by ad blockers preventing the GTM script from loading in users' browsers entirely.
- 2.Enable Custom Loader. This reroutes GTM and GA4 scripts through your first-party domain, so ad blockers can no longer identify and block them by URL pattern.
- 3.Monitor your GA4 Purchase event count over the same time window and compare it against your backend again.
If the gap persists after enabling Custom Loader, turn on the Enhanced ad blocker protection as well. This encrypts the request URLs so that blocking rules can't match them.
Was this article helpful?
🍽 Table of content:
Comments