elgorditosalsero / react-gtm-hook

Easily manage the Google Tag Manager via Hook
https://elgorditosalsero-react-gtm-hook.netlify.app/
MIT License
220 stars 28 forks source link

[QUESTION] Is there any way to use multiple GTM tags? #85

Closed sin-to-jin closed 3 months ago

sin-to-jin commented 3 months ago

I'm trying to set up multiple GTM containers right now, can I do the following?

import { GTMProvider } from '@elgorditosalsero/react-gtm-hook'

const App = () => {
  const gtmParams1 = {
    id: 'GTM-ID1',
    dataLayerName: 'customDataLayerName1'
  }
  const gtmParams2 = {
    id: 'GTM-ID2',
    dataLayerName: 'customDataLayerName2'
  }

  return (
    <GTMProvider state={gtmParams1}>
      <GTMProvider state={gtmParams2}>
        <p>My awesome app</p>
      </GTMProvider>
    </GTMProvider>
  )
}

I thought it would be possible to use multiple containers by specifying each dataLayerName when actually sending the GTM, but can this kind of approach be done with this library?