We have multiple environments such as Dev, Stage, QA, and Production. Rather than having one GTM snippet that is loaded on every page request in all the environments, we wanted to separate the GTM snippets so that the GTM snippet for Dev is only loaded for Dev, the GTM snippet for Stage is only loaded for Stage, and the production GTM script is only loaded on production.
Currently we add the GTM snippet through the use of our custom theme’s html.html.twig
template file.
How would I be able to conditionally add different scripts in a Drupal way (e.g. custom module, custom JS)?
We initially thought to create custom modules that would a load mymodule.html.html.twig
when enabled per environment. For example, the dev custom module would only be enabled on Dev, Stage custom module would only be enabled on. However that is not working.
Sponsored by SupremePR