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

I've tried to support multiple GTMs. Without breaking the existing interface, it can also be specified as an array. #86

Closed sin-to-jin closed 3 months ago

sin-to-jin commented 3 months ago

Summary

Support for multiple GTMs by allowing state to be specified as an array as well

Fix https://github.com/elgorditosalsero/react-gtm-hook/issues/85

Sample code

const param1 = {
  id: 'GTM-XXXXXXX',
  dataLayerName: 'dataLayerFirst',
}
const param2 = {
  id: 'GTM-XXXXXXX',
  dataLayerName: 'dataLayerSecond',
}
<GTMProvider states={[param1, param2]}>
 <p>foo-bar</p>
</GTMProvider>

Or,

<GTMProvider states={param1}>
 <p>foo-bar</p>
</GTMProvider>