Skip to content

A self-hosted media server and file management system

fix: plausible doesnt react to spa routing

aminnausinb30ac9cd9db5
diff --git a/resources/js/global.d.ts b/resources/js/global.d.ts
index d704106a..009a9b90 100644
--- a/resources/js/global.d.ts
+++ b/resources/js/global.d.ts
@@ -3,10 +3,15 @@ import type { Broadcaster } from '@/types/types';
import Pusher from 'pusher-js';
import Echo from 'laravel-echo';
+interface PlausibleEvent {
+ (event: 'pageview' | string, options?: { u?: string; props?: Record<string, any> }): void;
+}
+
declare global {
interface Window {
axios: AxiosStatic;
Pusher: typeof Pusher;
Echo: Echo<keyof Broadcaster> | null;
+ plausible?: PlausibleEvent;
}
}
diff --git a/resources/js/router/index.ts b/resources/js/router/index.ts
index a5943910..fc88346b 100644
--- a/resources/js/router/index.ts
+++ b/resources/js/router/index.ts
@@ -237,6 +237,10 @@ router.beforeEach(async (to, from, next) => {
router.afterEach((to) => {
nProgress.done(true);
+ if (typeof window.plausible === 'function') {
+ window.plausible('pageview', { u: to.fullPath });
+ }
+
// Scroll to top on every spa page load
if (to?.name === 'home') return;