diff --git a/studio/next.config.mjs b/studio/next.config.mjs index 0ddbd8c7ce..96e44e03ae 100644 --- a/studio/next.config.mjs +++ b/studio/next.config.mjs @@ -3,6 +3,7 @@ import { withSentryConfig } from "@sentry/nextjs"; import pkg from "./package.json" with { type: "json" }; const isPreview = process.env.VERCEL_ENV === "preview"; +const isProduction = process.env.NODE_ENV === "production"; // Allow it only for development once https://github.com/vercel/next.js/issues/23587 is fixed const allowUnsafeEval = true; // Report CSP violations to the console instead of blocking them @@ -54,19 +55,29 @@ const lightweightCspHeader = ` object-src 'none'; base-uri 'self'; font-src 'self' data:; - frame-src 'self' https://js.stripe.com https://hooks.stripe.com ${ + frame-src 'self' https://js.stripe.com https://hooks.stripe.com https://www.googletagmanager.com ${ isPreview ? "https://vercel.live/ https://vercel.com" : "" }; img-src 'self'${ isPreview ? " https://vercel.live/ https://vercel.com *.pusher.com/ data: blob:" : "" - } *.ads.linkedin.com; + } *.ads.linkedin.com *.google.com; script-src 'report-sample' 'self' 'unsafe-inline' ${ allowUnsafeEval ? "'unsafe-eval'" : "" } https://*.wundergraph.com https://js.stripe.com https://maps.googleapis.com https://plausible.io https://wundergraph.com https://static.reo.dev${ isPreview ? " https://vercel.live https://vercel.com" : "" - } https://www.googletagmanager.com https://snap.licdn.com; + } ${ + isProduction + ? [ + "https://www.googletagmanager.com", + "https://snap.licdn.com", + "https://cmp.osano.com", + "https://googleads.g.doubleclick.net", + "https://*.clarity.ms", + ].join(" ") + : "" + }; manifest-src 'self'; media-src 'self'; worker-src 'self' ${isSentryFeatureReplayEnabled ? "blob:" : ""}; diff --git a/studio/src/components/layout/analytics/gtm-script.tsx b/studio/src/components/layout/analytics/gtm-script.tsx index 23fb73b72f..eaf2919348 100644 --- a/studio/src/components/layout/analytics/gtm-script.tsx +++ b/studio/src/components/layout/analytics/gtm-script.tsx @@ -1,11 +1,17 @@ -import Script from "next/script"; +export interface GtmScriptProps { + gtmId: string | undefined; +}; -export function GtmScript() { - const gtmId = process.env.NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID; +export function GtmScript({ gtmId }: GtmScriptProps) { + if (!gtmId) { + return null; + } return ( <> - + ` + }} + /> - + `}}/> ); } -export function GtmNoScript() { - const gtmId = process.env.NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID; - if (!gtmId || process.env.NODE_ENV !== 'production') { +export function GtmNoScript({ gtmId }: GtmScriptProps) { + if (!gtmId) { return null; } diff --git a/studio/src/pages/_document.tsx b/studio/src/pages/_document.tsx index 5bb944d940..7ca683c3c2 100644 --- a/studio/src/pages/_document.tsx +++ b/studio/src/pages/_document.tsx @@ -35,7 +35,8 @@ export default function Document() { )} {gtmId && ( - + + )} )} - {isProduction && } - {isProduction && } + {isProduction && }