mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-27 06:52:35 -04:00
fix(tracking): Controlled tracking
auto-pageviews: The `enableAutoPageviews` option (enabled by default) was also tracking specific profile views. plugin-track: The new track plugin (`plugins/track.js`) effectively replaces the autoPageview system, with a lot more customisability. Now, profile views are tracked as events rather than their specific pages.
This commit is contained in:
parent
d11c0407dd
commit
e1027cf5f8
@ -139,6 +139,7 @@ export default {
|
|||||||
{ src: '~/plugins/globals.js' },
|
{ src: '~/plugins/globals.js' },
|
||||||
{ src: '~/plugins/auth.js' },
|
{ src: '~/plugins/auth.js' },
|
||||||
{ src: '~/plugins/datepicker.js', ssr: false },
|
{ src: '~/plugins/datepicker.js', ssr: false },
|
||||||
|
{ src: '~/plugins/track.js', ssr: false }
|
||||||
],
|
],
|
||||||
components: true,
|
components: true,
|
||||||
buildModules: [],
|
buildModules: [],
|
||||||
@ -163,11 +164,16 @@ export default {
|
|||||||
},
|
},
|
||||||
plausible: {
|
plausible: {
|
||||||
domain: process.env.PLAUSIBLE_DOMAIN || translations.domain,
|
domain: process.env.PLAUSIBLE_DOMAIN || translations.domain,
|
||||||
|
// NOTE(privacy): Disables automatic tracking of page views, meaning we have to do it manually
|
||||||
|
// If it's not done manually, a privacy issue occurs, which we *do not want*
|
||||||
|
// - tecc
|
||||||
|
enableAutoPageviews: false
|
||||||
},
|
},
|
||||||
publicRuntimeConfig: {
|
publicRuntimeConfig: {
|
||||||
plausible: {
|
plausible: {
|
||||||
domain: process.env.PLAUSIBLE_DOMAIN || translations.domain,
|
domain: process.env.PLAUSIBLE_DOMAIN || translations.domain,
|
||||||
apiHost: process.env.PLAUSIBLE_API_HOST
|
apiHost: process.env.PLAUSIBLE_API_HOST,
|
||||||
|
enableAutoPageviews: false // see previous comment
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
|
49
plugins/track.js
Normal file
49
plugins/track.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
function defaultHandler({plausible, to, from}) {
|
||||||
|
// console.debug("[analytics] Tracking default handler");
|
||||||
|
plausible.trackPageview()
|
||||||
|
}
|
||||||
|
function eventHandler(eventName) {
|
||||||
|
return function ({plausible, to, from}) {
|
||||||
|
plausible.trackEvent(eventName, {}, {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const TRACKER_OVERRIDES = [
|
||||||
|
{
|
||||||
|
test(v) {
|
||||||
|
return /^\/@.+/.test(v);
|
||||||
|
},
|
||||||
|
handling: eventHandler('Profile view')
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
export const plugin = function ({app}) {
|
||||||
|
const plausible = app.$plausible;
|
||||||
|
|
||||||
|
app.router.afterEach((to, from) => {
|
||||||
|
let handler = defaultHandler;
|
||||||
|
for (const trackerOverride of TRACKER_OVERRIDES) {
|
||||||
|
if (!trackerOverride.test(to.fullPath)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trackerOverride.handling === false) {
|
||||||
|
console.debug("[analytics] Page is blocked from tracking");
|
||||||
|
} else if (typeof trackerOverride.handling === "function") {
|
||||||
|
handler = trackerOverride.handling;
|
||||||
|
} else {
|
||||||
|
throw new Error("Tracking override handling is invalid");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log("[analytics] Tracking pageview")
|
||||||
|
try {
|
||||||
|
handler({plausible, to, from});
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Error whilst trying to handle navigation: %O", e);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default plugin;
|
Loading…
x
Reference in New Issue
Block a user