fixed build when NEXT_PUBLIC_GTM_ID is not defined

This commit is contained in:
Deepak Prabhakara 2022-03-01 13:31:28 +00:00
parent 8f9a31bfd4
commit 73c1bdc813
2 changed files with 3 additions and 3 deletions

View File

@ -8,5 +8,5 @@ PUBLIC_KEY=
# Base64 encoded value of private key `cat key.pem | base64` # Base64 encoded value of private key `cat key.pem | base64`
PRIVATE_KEY= PRIVATE_KEY=
# Google Tag Manager ID # Google Tag Manager ID. Leave as blank because removing this causes next.js build to fail.
NEXT_PUBLIC_GTM_ID= NEXT_PUBLIC_GTM_ID=""

View File

@ -6,7 +6,7 @@ import { useEffect } from 'react';
function MyApp({ Component, pageProps }: AppProps) { function MyApp({ Component, pageProps }: AppProps) {
useEffect(() => { 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 }); TagManager.initialize({ gtmId: process.env.NEXT_PUBLIC_GTM_ID });
} }
}, []); }, []);