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

How to trigger preview mode with the associated environment in the code? #72

Open vidrepar opened 1 year ago

vidrepar commented 1 year ago

Is it possible to open preview mode in GTM for the environment specified in the code?

Currently, I have to select the environment via GTM UI (see images) to debug the specific environment. The code doesn't seem to force the preview mode to the desired environment (eg. staging).

Initialization code:

  const { init, UseGTMHookProvider } = useGTM();

  useEffect(() => {
    init({
        id: process.env.REACT_APP_GTM as string,
        environment: {
          gtm_auth: '<GTM_AUTH_STRING>',
          gtm_preview: 'env-128',
        };,
      });
    }, []);

image image

Thanks for the lib @elgorditosalsero 🙏

elgorditosalsero commented 1 year ago

Hey @vidrepar, I'll try to take a look soon, but if someone wants to help, is welcome.

Sorry for the late answer.