Add production specific check in Next.js
To add production specific code, you can add a small utility function for the same:
let isProduction = Boolean(process?.env.NODE_ENV === 'production')
export { isProduction }
Now use this while adding the check, for example:
import GoogleAnalytics from './google-analytics'
export default function App({ Component, pageProps }) {
return (
<>
<Head>
<title>jsbisht.in</title>
<meta name="description" content="jsbisht.in" />
<link rel="icon" href="/favicon.ico" />
</Head>
{isProduction && <GoogleAnalytics />}
<Component {...pageProps} />
</>
)
}