This tutorial will show you how to load the Google Tag Manager (GTM) library (gtm.js) using GTM Server as a proxy, and configuring a custom request path like sgtm.yourdomain.com/yourgtm.js.
- Proxy / load the gtm.js library from the Google servers under your own domain.
- Adjust the request path (
/gtm.js) to any path you like.
- Using a custom Google Tag Manager Server client template (provided in this article).
Why use a custom path for gtm.js?
Google Tag Manager Server already has a perfectly functioning client template (
Google Tag Manager: Web Container) that will proxy the
gtm.js Google Tag Manager library from the Google servers. This makes sure the Google Tag Manager library can be loaded from your first-party domain (also see this article).
However, the default template currently doesn't provide the option to adjust the pathname (
/gtm.js). The problem here is that certain adblockers (like AdBlock or uBlock) that are using the EasyList or Disconnect.me filters, by default block requests to
your-domain.com/gtm.js. Therefore Google Tag Manager is not loaded.
Since Google Tag Manager in itself is not collecting any data but can be used for functional / non-tracking stuff as well (think of A/B testing, content injection, cookie consent), adjusting the pathname with make sure that the
gtm.js library and therefore GTM is loaded in certain cases..
The default client however, is not able to adjust the path (e.g.
whatever.js). Therefore I've written a simple custom GTM Server client that does exactly the same as the default one, but with the additional option to adjust the path. The template is also using a GTM Container-ID whitelist, so only the specified container-IDs can be loaded using your proxy.
Be aware that this client template doesn't prohibit adblockers to load the
gtag.jslibraries (that do track stuff), since this custom client only proxies gtm.js and not scripts like analytics.js or gtag.js).
The GTM template
You can find the template in our GitHub repository.
template.tplfrom the GitHub repo
- Create a new custom client template in Google Tag Manager Server, and import the
- Add a new client using the template you just added and configure correctly.