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

Disable hook conditionally #37

Closed olarcher closed 1 year ago

olarcher commented 3 years ago

I would like to use this library in a larger project. On certain (dev) environments data should not be sent to GTM. Is it possible to disable GTM integration completely, e.g. by checking the value of an environment variable (if GTM_CONTAINER_ID is set then activate, else don't)? To my understanding, since useGTMDispatch is a hook it cannot be called conditionally. Is there any way to deactivate the dispatch anyway?

doodlemoonch commented 3 years ago

I'd recommend you set up dev/staging/prod GTM environments, it's worth it

elgorditosalsero commented 3 years ago

Hi @olarcher,

as @doodlemoonch suggested, I think you could achieve your goal with GTM environments.

Just disable in some environments the tags where you want data to not be collected 😄

olarcher commented 3 years ago

Thanks for the suggestion! Any ideas how this could be solved technically without the need to set up separate GTM envs?

elgorditosalsero commented 3 years ago

Thanks for the suggestion! Any ideas how this could be solved technically without the need to set up separate GTM envs?

I think the only way you have at the moment, is wrapping into ifs the dispatcher based on your environments.

But I can think to add a variable to enable/disable dispatching in the future.

elgorditosalsero commented 2 years ago

Hi @olarcher ,

could you try 2.2.0?

42 should help you

elgorditosalsero commented 1 year ago

Closing due inactivity