fix plausible stats

i think
This commit is contained in:
JovannMC 2025-01-17 21:17:48 +03:00
parent 8ea970a495
commit 7c0f2c87d1
No known key found for this signature in database
2 changed files with 12 additions and 6 deletions

View File

@ -115,8 +115,19 @@
// Apply theme before DOM is loaded // Apply theme before DOM is loaded
let theme = localStorage.getItem("theme"); let theme = localStorage.getItem("theme");
if (theme !== "light" && theme !== "dark") { if (theme !== "light" && theme !== "dark") {
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches; const prefersDark = window.matchMedia(
"(prefers-color-scheme: dark)",
).matches;
theme = prefersDark ? "dark" : "light"; theme = prefersDark ? "dark" : "light";
if (!theme) {
// first time visitor
window.addEventListener("load", () => {
window.plausible("Theme set", {
props: { theme: theme.dark ? "dark" : "light" },
});
});
}
} }
document.documentElement.classList.add(theme); document.documentElement.classList.add(theme);

View File

@ -1,5 +1,4 @@
import { browser } from "$app/environment"; import { browser } from "$app/environment";
import { theme } from "$lib/store/index.svelte";
export const load = ({ data }) => { export const load = ({ data }) => {
if (!browser) return; if (!browser) return;
@ -10,10 +9,6 @@ export const load = ({ data }) => {
status: 200, status: 200,
}); });
}); });
window.plausible("Theme set", {
props: { theme: theme.dark ? "dark" : "light" },
});
theme.dark = localStorage.getItem("theme") === "dark";
return data; return data;
}; };