How to apply the page-hiding snippet for Google Optimize? I'm trying to use Google Optimize on a Drupal 8 site through Google Tag Manager.  I have set up the tags in Google Tag Manager through Google's UI and used the Google Tag Manager module to add the snippets to my site on path /test/*.

However, according to the Google Optimize documentation, I should also add a "page-hiding snippet":

&lt;HEAD&gt;
&lt;!-- Page hiding snippet (recommended)  --&gt;
&lt;style&gt;.async-hide { opacity: 0 !important} &lt;/style&gt;
&lt;script&gt;(function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date;
h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')};
(a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;
})(window,document.documentElement,'async-hide','dataLayer',4000,
{'GTM-XXXXXX':true});&lt;/script&gt;


There are three requirements here.


The snippet needs to come before the Google Tag Manager tag in the HEAD of the page.
The snippet should only be shown on pages with path /test/*
Inside the snippet, the GTM-XXXXXX needs to be different for dev/staging/live environments.


Is there a way to standard way to set this up?  I assumed that Google Optimize/Analytics is popular enough there would be some information for integrating it with Drupal, but all I found was this DrupalCon 2019 seminar that hasn't happened yet.

Setting up Google Tag Manager was fine, but I'm lost at how to get this final bit in the right place.
Well, since posting my question, there is now a Google Optimize Hide Page module, which provides a code example of how to do this.

There is also a patch to add this functionality to the Google Tag Manager module.