added first-guess and correct-guess umami event tracking

This commit is contained in:
George Powell
2025-12-27 11:42:15 -05:00
parent 54c7e3cdbb
commit c71170e6b3
3 changed files with 392 additions and 385 deletions

View File

@@ -1,6 +1,7 @@
<script lang="ts">
import { fade } from "svelte/transition";
import { getBookById, toOrdinal, getNextGradeMessage } from "$lib/utils/game";
import { onMount } from "svelte";
interface StatsData {
solveRank: number;
@@ -33,10 +34,10 @@
// List of congratulations messages with weights
const congratulationsMessages: WeightedMessage[] = [
{ text: "🎉 Congratulations! 🎉", weight: 1000 },
{ text: "You got it!", weight: 10 },
{ text: "🎉 Yup 🎉", weight: 5 },
{ text: "👍🏻 Very nice! 👍🏻", weight: 1 },
{ text: "Congratulations!", weight: 10 },
{ text: "You got it!", weight: 1000 },
{ text: "Yup,", weight: 100 },
{ text: "Very nice!", weight: 1 },
];
// Function to select a random message based on weights
@@ -45,9 +46,9 @@
if (guessCount === 1) {
const n = Math.random();
if (n < 0.99) {
return "🤯 First try! 🤯";
return "🌟 First try! 🌟";
} else {
return " Axios";
return "🗣 Axios! 🗣";
}
}
@@ -70,18 +71,25 @@
// Generate the congratulations message
let congratulationsMessage = $derived(getRandomCongratulationsMessage());
onMount(() => {
if (typeof window !== "undefined" && (window as any).umami) {
(window as any).umami.track("guessed-correctly", {
totalGuesses: guessCount,
});
}
});
</script>
<div
class="p-8 sm:p-12 w-full bg-linear-to-r from-green-400 to-green-600 text-white rounded-2xl shadow-2xl text-center fade-in"
>
<h2 class="text-2xl sm:text-4xl font-black mb-4 drop-shadow-lg">
<!-- <h2 class="text-2xl sm:text-4xl font-black mb-4 drop-shadow-lg">
{congratulationsMessage}
</h2>
<p class="text-lg sm:text-xl md:text-2xl">
The verse is from <span class="font-black text-xl sm:text-2xl md:text-3xl"
>{bookName}</span
>
</h2> -->
<p class="text-xl sm:text-3xl md:text-4xl">
{congratulationsMessage} The verse is from
<span class="font-black text-xl sm:text-2xl md:text-3xl">{bookName}</span>.
</p>
<p
class="text-2xl font-bold mt-6 p-2 mx-2 bg-black/20 rounded-lg inline-block"