mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-23 04:34:15 -04:00
(bug) plausible not counting initial page view
This commit is contained in:
parent
a0b8959749
commit
9bc7ba399a
@ -1,5 +1,6 @@
|
|||||||
import * as Sentry from '@sentry/vue';
|
import * as Sentry from '@sentry/vue';
|
||||||
import { defineNuxtPlugin, useRouter } from 'nuxt/app';
|
import { defineNuxtPlugin, useRouter } from 'nuxt/app';
|
||||||
|
import type { RouteLocationNormalized } from 'vue-router';
|
||||||
|
|
||||||
const USER_AT = /^\/@.+/;
|
const USER_AT = /^\/@.+/;
|
||||||
const USER_SUBPAGE = /^\/(u|card)\/.*/;
|
const USER_SUBPAGE = /^\/(u|card)\/.*/;
|
||||||
@ -16,16 +17,12 @@ export const normalizeUrl = (page: URL): URL => {
|
|||||||
return page;
|
return page;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default defineNuxtPlugin(() => {
|
export default defineNuxtPlugin((nuxtApp) => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
router.afterEach((to, from) => {
|
|
||||||
|
const trackPageview = (route: RouteLocationNormalized): void => {
|
||||||
try {
|
try {
|
||||||
const toUrl = normalizeUrl(new URL(to.fullPath, window.location.href));
|
const toUrl = normalizeUrl(new URL(route.fullPath, window.location.href));
|
||||||
const fromUrl = normalizeUrl(new URL(from.fullPath, window.location.href));
|
|
||||||
if (toUrl.toString() === fromUrl.toString()) {
|
|
||||||
// same page, but different search param
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.debug('[analytics] tracking page view:', toUrl.toString());
|
console.debug('[analytics] tracking page view:', toUrl.toString());
|
||||||
useTrackPageview({
|
useTrackPageview({
|
||||||
data: {
|
data: {
|
||||||
@ -35,5 +32,22 @@ export default defineNuxtPlugin(() => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
Sentry.captureException(error);
|
Sentry.captureException(error);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Track the initial page load
|
||||||
|
nuxtApp.hook('app:mounted', () => {
|
||||||
|
trackPageview(router.currentRoute.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Track client-side navigation
|
||||||
|
router.afterEach((to: RouteLocationNormalized, from: RouteLocationNormalized) => {
|
||||||
|
const toUrl = normalizeUrl(new URL(to.fullPath, window.location.href));
|
||||||
|
const fromUrl = normalizeUrl(new URL(from.fullPath, window.location.href));
|
||||||
|
if (toUrl.toString() === fromUrl.toString()) {
|
||||||
|
// Same page, but different search param
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
trackPageview(to);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user