diff --git a/.env.example b/.env.example index 25823b4..732c8a2 100644 --- a/.env.example +++ b/.env.example @@ -8,5 +8,5 @@ PUBLIC_KEY= # Base64 encoded value of private key `cat key.pem | base64` PRIVATE_KEY= -# Google Tag Manager ID -NEXT_PUBLIC_GTM_ID= \ No newline at end of file +# Google Tag Manager ID. Leave as blank because removing this causes next.js build to fail. +NEXT_PUBLIC_GTM_ID="" diff --git a/pages/_app.tsx b/pages/_app.tsx index 868167b..d411f62 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -6,7 +6,7 @@ import { useEffect } from 'react'; function MyApp({ Component, pageProps }: AppProps) { useEffect(() => { - if (process.env.NEXT_PUBLIC_GTM_ID) { + if (process.env.NEXT_PUBLIC_GTM_ID && process.env.NEXT_PUBLIC_GTM_ID.length > 0) { TagManager.initialize({ gtmId: process.env.NEXT_PUBLIC_GTM_ID }); } }, []);