diff --git a/env.example b/env.example
index 3e0e270..4731fb2 100644
--- a/env.example
+++ b/env.example
@@ -1,4 +1,7 @@
NEXT_PUBLIC_SANITY_PROJECT_ID=mmqlu667
NEXT_PUBLIC_SANITY_DATASET=production
-SANITY_REVALIDATE_SECRET=your-super-secret-webhook-token-here
\ No newline at end of file
+SANITY_REVALIDATE_SECRET=your-super-secret-webhook-token-here
+
+NEXT_PUBLIC_UMAMI_SRC=https://umami.uiogaming.no/script.js
+NEXT_PUBLIC_UMAMI_WEBSITE_ID=1e985053-9158-4d62-be07-0fe83a9dce6e
\ No newline at end of file
diff --git a/src/app/layout.tsx b/src/app/layout.tsx
index 1b60f61..65aa98a 100644
--- a/src/app/layout.tsx
+++ b/src/app/layout.tsx
@@ -1,5 +1,9 @@
import "@/app/globals.css"
+import UmamiAnalytics from "@/components/umamiAnalytics"
+
+import { getAnalyticsConfig } from "@/lib/analyticsConfig"
+
import type { Metadata } from "next"
export const metadata: Metadata = {
@@ -18,10 +22,19 @@ export default function RootLayout({
}: Readonly<{
children: React.ReactNode
}>) {
+ const analyticsConfig = getAnalyticsConfig()
+
return (
{children}
+ {analyticsConfig?.enabled && (
+
+ )}
)
diff --git a/src/components/umamiAnalytics.tsx b/src/components/umamiAnalytics.tsx
new file mode 100644
index 0000000..afc8931
--- /dev/null
+++ b/src/components/umamiAnalytics.tsx
@@ -0,0 +1,50 @@
+"use client"
+
+import Script from "next/script"
+
+interface UmamiAnalyticsProps {
+ websiteId: string
+ src?: string
+ domains?: string[]
+}
+
+export default function UmamiAnalytics({
+ websiteId,
+ src = "https://analytics.umami.is/script.js",
+ domains,
+}: UmamiAnalyticsProps) {
+ if (!websiteId) {
+ console.warn("Umami: Website ID is required")
+ return null
+ }
+
+ // Only load analytics in production or if explicitly enabled
+ if (process.env.NODE_ENV !== "production") {
+ return null
+ }
+
+ // Domain validation (client-side check as additional layer)
+ if (domains && typeof window !== "undefined") {
+ const currentDomain = window.location.hostname
+ const isAllowedDomain = domains.some(
+ domain => currentDomain === domain || currentDomain.endsWith(`.${domain}`)
+ )
+
+ if (!isAllowedDomain) {
+ console.warn(
+ `Umami: Domain ${currentDomain} not in allowed list:`,
+ domains
+ )
+ return null
+ }
+ }
+
+ return (
+
+ )
+}
diff --git a/src/lib/analyticsConfig.ts b/src/lib/analyticsConfig.ts
new file mode 100644
index 0000000..e1b74d8
--- /dev/null
+++ b/src/lib/analyticsConfig.ts
@@ -0,0 +1,29 @@
+interface AnalyticsConfig {
+ websiteId: string
+ src: string
+ domains: string[]
+ enabled: boolean
+}
+
+export function getAnalyticsConfig(): AnalyticsConfig | null {
+ const websiteId = process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID
+ const src =
+ process.env.NEXT_PUBLIC_UMAMI_SRC || "https://analytics.umami.is/script.js"
+
+ if (!websiteId) {
+ return null
+ }
+
+ // Define allowed domains
+ const domains = ["uiogaming.no", "www.uiogaming.no"]
+
+ // Additional environment-based checks
+ const enabled = process.env.NODE_ENV === "production"
+
+ return {
+ websiteId,
+ src,
+ domains,
+ enabled,
+ }
+}