Skip to content

Free & Open-Source Invoice Generator - No Sign-Up, No Ads, Instant PDF Export, 100% In-Browser, and Fully Customizable Templates.

feat: add Umami analytics integration with environment variable support (#279)

Vlad Sazonaubf336a9c3f00
diff --git a/.env.example b/.env.example
index 3fc6aa2..a9b703b 100644
--- a/.env.example
+++ b/.env.example
@@ -7,6 +7,9 @@ NEXT_PUBLIC_SENTRY_ENABLED="false"
NEXT_PUBLIC_SENTRY_DSN=""
+# Umami analytics website id (https://eu.umami.is/dashboard), script only loads in production
+NEXT_PUBLIC_UMAMI_WEBSITE_ID=""
+
# Resend (For emails) Create account and paste API keys in .env.local
RESEND_API_KEY=""
diff --git a/src/app/(components)/root-document.tsx b/src/app/(components)/root-document.tsx
index cf76eb0..f73a6ea 100644
--- a/src/app/(components)/root-document.tsx
+++ b/src/app/(components)/root-document.tsx
@@ -8,6 +8,7 @@ import { BrowserSupportNotice } from "@/components/browser-support-notice";
import { ResponsiveIndicator } from "@/components/dev/responsive-indicator";
import { SentryIndicator } from "@/components/dev/sentry-indicator";
import { PERSONAL_WEBSITE_URL, STATIC_ASSETS_URL } from "@/config";
+import { env } from "@/env";
import { JsonLdScript } from "@/lib/seo/render-json-ld";
import { buildSiteWideJsonLdGraph } from "@/lib/seo/site-entities";
@@ -72,7 +73,7 @@ export function RootDocument({ lang, children }: RootDocumentProps) {
<Script
// we proxy umami check next.config.mjs rewrites
src="/stats/script.js"
- data-website-id="1914352c-5ebb-4806-bfc3-f494712bb4a4"
+ data-website-id={env.NEXT_PUBLIC_UMAMI_WEBSITE_ID}
defer
/>
</>
diff --git a/src/app/api/generate-invoice/__tests__/test-env.ts b/src/app/api/generate-invoice/__tests__/test-env.ts
index 5b8bd4f..8e773e2 100644
--- a/src/app/api/generate-invoice/__tests__/test-env.ts
+++ b/src/app/api/generate-invoice/__tests__/test-env.ts
@@ -29,4 +29,5 @@ export const TEST_ENV = {
GOOGLE_DRIVE_PRIVATE_KEY: "private-key",
GITHUB_TOKEN: "github-token",
NEXT_PUBLIC_SENTRY_DSN: "https://sentry.test",
+ NEXT_PUBLIC_UMAMI_WEBSITE_ID: "umami-website-id",
} as const;
diff --git a/src/env.ts b/src/env.ts
index 1a41bb7..c95cf5c 100644
--- a/src/env.ts
+++ b/src/env.ts
@@ -37,10 +37,13 @@ export const env = createEnv({
},
client: {
NEXT_PUBLIC_SENTRY_DSN: z.string(),
+ // Umami website id, used by the analytics script in `root-document.tsx`
+ NEXT_PUBLIC_UMAMI_WEBSITE_ID: z.string(),
},
// If you're using Next.js < 13.4.4, you'll need to specify the runtimeEnv manually
runtimeEnv: {
NEXT_PUBLIC_SENTRY_DSN: process.env.NEXT_PUBLIC_SENTRY_DSN,
+ NEXT_PUBLIC_UMAMI_WEBSITE_ID: process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID,
AUTH_TOKEN: process.env.AUTH_TOKEN,