From f60cade344b295356c3fbb6ac83d97c71437e9fb Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Mon, 11 Aug 2025 02:35:32 +0200 Subject: [PATCH] track id check events --- src/app/layout.tsx | 9 +++++++++ src/app/page.tsx | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 1c7f28f..5a199ca 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -24,6 +24,15 @@ export default function RootLayout({ }>) { return ( + + {process.env.UMAMI_SCRIPT_URL && process.env.UMAMI_WEBSITE_ID && ( + + )} + diff --git a/src/app/page.tsx b/src/app/page.tsx index c482115..3f3279b 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -70,6 +70,20 @@ async function lookupSession(sessionId: string) { return res.json(); } +declare global { + interface Window { + umami?: { + track: (eventName: string, eventData?: Record) => void; + }; + } +} + +const trackEvent = (eventName: string, eventData?: Record) => { + if (typeof window !== "undefined" && window.umami) { + window.umami.track(eventName, eventData); + } +}; + function HomeInner() { const [session, setSession] = useState(null); const [scannedCodes, setScannedCodes] = useState>(new Set()); @@ -91,6 +105,7 @@ function HomeInner() { if (data && typeof data.age === "number") { setSession(data); setScannedCodes((prev) => new Set(prev).add(variables)); + trackEvent("id-check"); } pendingCodeRef.current = null; },