2024-10-31 19:24:40 +00:00
|
|
|
/* eslint prefer-rest-params: 0 */
|
|
|
|
|
|
2024-10-25 21:36:33 +00:00
|
|
|
import {page} from "$app/stores"
|
2026-06-08 22:33:38 +00:00
|
|
|
import {getSetting} from "@app/settings"
|
2024-10-25 21:36:33 +00:00
|
|
|
|
|
|
|
|
const w = window as any
|
|
|
|
|
|
|
|
|
|
w.plausible =
|
|
|
|
|
w.plausible ||
|
|
|
|
|
function () {
|
|
|
|
|
;(w.plausible.q = w.plausible.q || []).push(arguments)
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-10 16:26:54 +00:00
|
|
|
// Modals live in page state, so the page store also emits when one opens or closes
|
|
|
|
|
export const setupAnalytics = () => {
|
|
|
|
|
let prevHref: string | undefined
|
|
|
|
|
|
|
|
|
|
return page.subscribe($page => {
|
|
|
|
|
if ($page.route && getSetting("report_usage") && $page.url.href !== prevHref) {
|
|
|
|
|
prevHref = $page.url.href
|
|
|
|
|
|
2024-10-25 21:36:33 +00:00
|
|
|
w.plausible("pageview", {u: $page.route.id})
|
|
|
|
|
}
|
|
|
|
|
})
|
2026-09-10 16:26:54 +00:00
|
|
|
}
|