Skip to content

Commit f6ed166

Browse files
committed
Disable Vercel Analytics at build time for testing
Fixes #21
1 parent e8666a6 commit f6ed166

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ jobs:
5757

5858
- name: Build project
5959
run: pnpm run build
60+
env:
61+
VITE_DISABLE_VERCEL_ANALYTICS: "true"
6062

6163
- name: Install Caddy
6264
run: |

src/main.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ const sanitizedBrowserLanguageIfSupportedOrEnglish =
1414
getSanitizedBrowserLanguageIfSupportedOrEnglish();
1515
await dynamicActivate(sanitizedBrowserLanguageIfSupportedOrEnglish);
1616

17+
const isAnalyticsEnabled =
18+
import.meta.env.VITE_DISABLE_VERCEL_ANALYTICS !== "true";
19+
1720
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1821
createRoot(document.getElementById("root")!).render(
1922
<StrictMode>
20-
<Analytics />
23+
{isAnalyticsEnabled && <Analytics />}
2124
<I18nProvider i18n={i18n}>
2225
<App />
2326
</I18nProvider>

src/vite-env.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
/// <reference types="vite-plugin-pwa/react" />
33
/// <reference types="vite-plugin-pwa/pwa-assets" />
44

5+
// Define env variables used in the project
6+
// https://vite.dev/guide/env-and-mode.html#intellisense-for-typescript
7+
8+
interface ViteTypeOptions {
9+
strictImportMetaEnv: unknown;
10+
}
11+
12+
interface ImportMetaEnv {
13+
readonly VITE_DISABLE_VERCEL_ANALYTICS: string;
14+
}
15+
16+
interface ImportMeta {
17+
readonly env: ImportMetaEnv;
18+
}
19+
520
// TODO: Remove when no longer needed
621
// https://developer.mozilla.org/en-US/docs/Web/API/LaunchParams
722
// These types are not yet included in TypeScript's standard lib as of v4.9

0 commit comments

Comments
 (0)