Skip to content

armgit / VERT

Public Imported from GitHub
0

The next-generation file converter. Open source, fully local* and free forever.

fix plausible stats

JovannMC7c0f2c87d1d2
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index d6a28f1..e7d71ca 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -115,8 +115,19 @@
// Apply theme before DOM is loaded
let theme = localStorage.getItem("theme");
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";
+
+ if (!theme) {
+ // first time visitor
+ window.addEventListener("load", () => {
+ window.plausible("Theme set", {
+ props: { theme: theme.dark ? "dark" : "light" },
+ });
+ });
+ }
}
document.documentElement.classList.add(theme);
diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts
index 2210615..73e4c9c 100644
--- a/src/routes/+layout.ts
+++ b/src/routes/+layout.ts
@@ -1,5 +1,4 @@
import { browser } from "$app/environment";
-import { theme } from "$lib/store/index.svelte";
export const load = ({ data }) => {
if (!browser) return;
@@ -10,10 +9,6 @@ export const load = ({ data }) => {
status: 200,
});
});
- window.plausible("Theme set", {
- props: { theme: theme.dark ? "dark" : "light" },
- });
- theme.dark = localStorage.getItem("theme") === "dark";
return data;
};