title: Can anyone help implementing Nuxt.js Google Tag Manager with function based id
body: <p>I installed and add this code to my nuxt.config.js and it works perfectly fine. (Link to <a href="https://github.com/nuxt-community/modules/tree/master/packages/google-tag-manager" rel="nofollow noreferrer">package</a>)</p>
  
  <pre><code>  modules: [
     ['@nuxtjs/google-tag-manager', { id: 'GTM-XXXXXXX' }],
    ]
  </code></pre>
  
  <p>Now I am trying to implement instead of a static ID a function which will return an ID.</p>
  
  <p>I tried to add this lines into my nuxt.config. js but it is not working. Obviously I have to put it somewhere else or so...</p>
  
  <p><strong>This is what I tried</strong></p>
  
  <p><strong>nuxt.config.js</strong></p>
  
  <pre><code>const code = '1234567'
  id: () =&gt; {
    return 'GTM-' + code
  }
  
  export default {
  ...
  
  modules: [
     ['@nuxtjs/google-tag-manager', { id: id }],
    ]
  ...
  }
  </code></pre>
  
  <p>What would be the correct way implementing this?</p>
  
  <p>I would like to do something like that at the end.</p>
  
  <pre><code>modules: [
     ['@nuxtjs/google-tag-manager', { 
         id: ({ req }) =&gt; {
           if (req.headers.referer == "exmple.com")
             return 'GTM-156'
           if (req.headers.referer == "exmple.it")
             return 'GTM-24424'
           if (req.headers.referer == "exmple.es")
             return 'GTM-2424'
         }
     }]]
  </code></pre>
  
  <p><strong>EDIT:</strong>
  I solved my problem by rewriting the whole module. It is not possible to use this Module because it is loaded only on build time. I rewrote the module and moved the code into nuxtServerInit. </p>
  
  <p>nuxtServerInit is called on each request (modules only onetime). In the request I asked from which domain the request is coming. Depending on the domain I add different google-tag-manager id's to the head and the plugin.</p>