Skip to content

Commit

Permalink
fix: only add gtag script to prod environments (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
akevinge authored Oct 12, 2023
1 parent 13f5477 commit 798f958
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/env/schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ export const serverSchema = z.object({
* To expose them to the client, prefix them with `NEXT_PUBLIC_`.
*/
export const clientSchema = z.object({
NEXT_PUBLIC_NODE_ENV: z.enum(['development', 'test', 'production']),
NEXT_PUBLIC_UMAMI_URL: z.string(),
NEXT_PUBLIC_UMAMI_WEBSITE_ID: z.string(),
NEXT_PUBLIC_VALIDATOR: z.string(),
// NEXT_PUBLIC_BAR: z.string(),
});

/**
Expand All @@ -52,8 +52,8 @@ export const clientSchema = z.object({
* @type {{ [k in keyof z.infer<typeof clientSchema>]: z.infer<typeof clientSchema>[k] | undefined }}
*/
export const clientEnv = {
NEXT_PUBLIC_NODE_ENV: process.env.NODE_ENV,
NEXT_PUBLIC_UMAMI_URL: process.env.NEXT_PUBLIC_UMAMI_URL,
NEXT_PUBLIC_UMAMI_WEBSITE_ID: process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID,
NEXT_PUBLIC_VALIDATOR: process.env.NEXT_PUBLIC_VALIDATOR,
// NEXT_PUBLIC_BAR: process.env.NEXT_PUBLIC_BAR,
};
23 changes: 13 additions & 10 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,20 @@ const NebulaApp: AppType<{ session: Session | null }> = ({
/>
)}
</Head>
{env.NEXT_PUBLIC_NODE_ENV === 'production' && (
<>
<Script async src="https://www.googletagmanager.com/gtag/js?id=G-5V674KK1JX" />
<Script id="google-analytics">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
<Script async src="https://www.googletagmanager.com/gtag/js?id=G-5V674KK1JX" />
<Script id="google-analytics">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-5V674KK1JX');
`}
</Script>
gtag('config', 'G-5V674KK1JX');
`}
</Script>
</>
)}
<ScreenSizeWarnModal
open={displayScreenSizeWarning && !hasWarned}
onClose={() => setHasWarned(true)}
Expand Down

0 comments on commit 798f958

Please sign in to comment.