Aktualisiere Metriken-Logik in App.svelte zur Verwendung von $effect und verbessere die Lesbarkeit

This commit is contained in:
2025-03-27 17:32:55 +00:00
parent a72780873a
commit ffcded42f3

View File

@@ -16,9 +16,12 @@
}
// metrics
let oldPath: string
$: if (metricCall && typeof window !== "undefined" && oldPath !== $location.path) {
const ref = oldPath ? document.location.protocol + "//" + document.location.host + oldPath : document.referrer
let oldPath = $state("")
$effect(() => {
if (metricCall && typeof window !== "undefined" && oldPath !== $location.path) {
const ref = oldPath
? document.location.protocol + "//" + document.location.host + oldPath
: document.referrer
oldPath = $location.path
const fetchPath = oldPath + (oldPath.includes("?") ? "&" : "?") + "metrics"
fetch(fetchPath, {
@@ -31,6 +34,7 @@
},
})
}
})
</script>
<h1>Tibi Svelte Starter</h1>