mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-23 20:54:48 -04:00

instances for hashes which show up in plausible include #google_vignette (from ads), pronouns after profile or search filters in lists
33 lines
950 B
TypeScript
33 lines
950 B
TypeScript
import * as Sentry from '@sentry/vue';
|
|
import type { Plugin } from '@nuxt/types';
|
|
|
|
const USER_AT = /^\/@.+/;
|
|
const USER_SUBPAGE = /^\/(u|card)\/.*/;
|
|
|
|
export const normalizeUrl = (page: URL): URL => {
|
|
if (USER_AT.test(page.pathname)) {
|
|
page.pathname = page.pathname.replace(USER_AT, '/@--redacted--');
|
|
}
|
|
if (USER_SUBPAGE.test(page.pathname)) {
|
|
page.pathname = page.pathname.replace(USER_SUBPAGE, '/$1/--redacted--');
|
|
}
|
|
page.hash = '';
|
|
return page;
|
|
};
|
|
|
|
const plugin: Plugin = ({ app }) => {
|
|
app.router?.afterEach((to) => {
|
|
try {
|
|
const url = normalizeUrl(new URL(to.fullPath, window.location.href));
|
|
console.debug('[analytics] tracking page view:', url.toString());
|
|
app.$plausible.trackPageview({
|
|
url: url.toString(),
|
|
});
|
|
} catch (error) {
|
|
Sentry.captureException(error);
|
|
}
|
|
});
|
|
};
|
|
|
|
export default plugin;
|