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

feat (InjectScript): Provide way to conditionally inject script #42

Closed jafin closed 2 years ago

jafin commented 2 years ago

Introduce prop injectScript: boolean

The default value is true, to avoid changing existing API surface.

tcarter8 commented 2 years ago

I have a need to inject the GTM script only after the home page video has loaded, for performance reasons. Can anyone provide an example of how this injectScript prop can be used? If it provides a way to delay script injection, I can find no examples. It's obvious injectScript: false would be declared in the initial gtmParams. But I can't visualize how I would tell the GTMProvider that injectScript should toggle to true after getting my video onLoadedData event. Thanks in advance!