Support configurable upstream analytics
This commit is contained in:
@@ -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 = " <SimpleBar ";
|
||||
|
||||
const hasKnownAnalytics = source.includes("G-SLZ5TY9MVN");
|
||||
const hasKnownAnalytics = source.includes("G-SLZ5TY9MVN") || source.includes(analyticsConfig);
|
||||
const hasKnownState = source.includes(analyticsStart);
|
||||
const hasKnownConsent = source.includes(consentStart);
|
||||
const consentStart = consentStarts.find(marker => 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) {
|
||||
|
||||
Reference in New Issue
Block a user