title: NuxtServerInit: Add Google-Tag-Manager scripts to head an body
body: <p>I use one nuxt instance to serve several domains with different languages. For each domain I use a different Google-Tag-Manager account. </p>
  
  <p>Within nuxtServerInit I add to the store the hostname and also the Google-Tag-Manager ID.</p>
  
  <p>Now I am looking for a way to add the Javascript snippets to my nuxt project.</p>
  
  <p>This one needs to be in the head</p>
  
  <pre><code>&lt;!-- Google Tag Manager --&gt;
  &lt;script&gt;(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),dl=l!='dataLayer'?'&amp;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-XXX);&lt;/script&gt;
  &lt;!-- End Google Tag Manager --&gt;
  </code></pre>
  
  <p>And that one at the beginning of the body</p>
  
  <pre><code>&lt;!-- Google Tag Manager (noscript) --&gt;
  &lt;noscript&gt;&lt;iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXX"
  height="0" width="0" style="display:none;visibility:hidden"&gt;&lt;/iframe&gt;&lt;/noscript&gt;
  &lt;!-- End Google Tag Manager (noscript) --&gt;
  </code></pre>
  
  <p>My first idea is it to add this code programmatically to the document, but I don't know how.</p>
  
  <p>Any suggestions or better idea to accomplish this?</p>
  
  <p>I already tried to use the community solution.  But it does not support different ID's. 
  <a href="https://stackoverflow.com/questions/59236239/can-anyone-help-implementing-nuxt-js-google-tag-manager-with-function-based-id/59248140?noredirect=1#comment104712087_59248140">Can anyone help implementing Nuxt.js Google Tag Manager with function based id</a>
  The main problem of this solution is the module which is used itself. A module is only called once but it needed to be something else to be called on each request.</p>