diff --git a/docker/remove-analytics.mjs b/docker/remove-analytics.mjs index d97a7f6..6e5fef1 100644 --- a/docker/remove-analytics.mjs +++ b/docker/remove-analytics.mjs @@ -5,12 +5,17 @@ let source = readFileSync(appPath, "utf8"); const analyticsStart = " const [cookieSettings, setCookieSettings] = useState(localStorage.getItem(\"cookie-settings\"));"; const analyticsEnd = " const hasSpeedDial ="; -const consentStart = " {!window.isElectron && cookieSettings === null && !sidebarForceHidden && ("; +const analyticsConfig = "const GOOGLE_ANALYTICS_ID = import.meta.env.VITE_GOOGLE_ANALYTICS_ID;\n"; +const consentStarts = [ + " {!window.isElectron && cookieSettings === null && !sidebarForceHidden && (", + " {GOOGLE_ANALYTICS_ID && !window.isElectron && cookieSettings === null && !sidebarForceHidden && (", +]; const consentEnd = " source.includes(marker)); +const hasKnownConsent = consentStart !== undefined; if (hasKnownState && hasKnownConsent) { const analyticsStartIndex = source.indexOf(analyticsStart); @@ -33,6 +38,7 @@ if (hasKnownState && hasKnownConsent) { throw new Error("Cannot remove the Button import used by the upstream consent dialog."); } source = source.replace(materialImport, "Typography, Grid"); + source = source.replace(analyticsConfig, ""); console.log("Removed the upstream Google Analytics integration and consent dialog."); } else if (hasKnownAnalytics || hasKnownState || hasKnownConsent) {