MatteoGabriele / vue-gtag

Global Site Tag plugin for Vue (gtag.js)
https://matteo-gabriele.gitbook.io/vue-gtag/
MIT License
864 stars 66 forks source link

onBeforeTrack handler returning false cancels tracking #563

Open martsyn opened 6 months ago

martsyn commented 6 months ago

pageTrackerExcludedRoutes array is insufficient for large lists of routes. A custom logic is needed to be able to filter out the pages with no tracking, e.g.:

app.use(
  VueGtag,
  {
    id: measurementId,
    onBeforeTrack: to => !to.meta?.hidden,
  },
  router,
)
martsyn commented 6 months ago

I can offer two alternatives:

a) Make pageTrackerExcludedRoutes optionally a function b) add explicit function isRouteExcluded to options

Please let me know if either of these is preferred instead of this PR.