Use user ID for umami identify when authenticated

This commit is contained in:
George Powell
2026-02-05 17:46:14 -05:00
parent 24a5fdbb80
commit 86f81cf9dd

View File

@@ -174,7 +174,8 @@
if (!browser) return; if (!browser) return;
anonymousId = getOrCreateAnonymousId(); anonymousId = getOrCreateAnonymousId();
if ((window as any).umami) { if ((window as any).umami) {
(window as any).umami.identify(anonymousId); // Use user id if logged in, otherwise use anonymous id
(window as any).umami.identify(user ? user.id : anonymousId);
} }
const statsKey = `bibdle-stats-submitted-${dailyVerse.date}`; const statsKey = `bibdle-stats-submitted-${dailyVerse.date}`;
statsSubmitted = localStorage.getItem(statsKey) === "true"; statsSubmitted = localStorage.getItem(statsKey) === "true";
@@ -264,7 +265,7 @@
(async () => { (async () => {
try { try {
const response = await fetch( const response = await fetch(
`/api/submit-completion?anonymousId=${anonymousId}&date=${dailyVerse.date}`, `/api/submit-completion?anonymousId=${user ? user.id : anonymousId}&date=${dailyVerse.date}`,
); );
const result = await response.json(); const result = await response.json();
console.log("Stats response:", result); console.log("Stats response:", result);
@@ -294,7 +295,7 @@
async function submitStats() { async function submitStats() {
try { try {
const payload = { const payload = {
anonymousId, anonymousId: user ? user.id : anonymousId,
date: dailyVerse.date, date: dailyVerse.date,
guessCount: guesses.length, guessCount: guesses.length,
}; };
@@ -455,7 +456,7 @@
<div class="mt-4 flex flex-col items-center gap-3"> <div class="mt-4 flex flex-col items-center gap-3">
<div class="flex gap-3"> <div class="flex gap-3">
<a <a
href="/stats?anonymousId={anonymousId}" href="/stats?{user ? `userId=${user.id}` : `anonymousId=${anonymousId}`}"
class="inline-flex items-center px-4 py-2 bg-amber-600 text-white rounded-lg hover:bg-amber-700 transition-colors text-sm font-medium shadow-md" class="inline-flex items-center px-4 py-2 bg-amber-600 text-white rounded-lg hover:bg-amber-700 transition-colors text-sm font-medium shadow-md"
> >
📊 View Stats 📊 View Stats