nuxt-modules / plausible

🎟️ Plausible Analytics integration for Nuxt
https://plausible.io
MIT License
102 stars 5 forks source link

Question: Usage without `autoPageviews: true` #19

Open madebyfabian opened 4 months ago

madebyfabian commented 4 months ago

Hi there! I wanted to use Plausible in a Nuxt project and exclude some of my routes from being automatically tracked as pageview.

Since this is currently not possible with the plausible-tracker, I thought of setting autoPageviews: false and manually tracking them, excluding the paths I don't want to manually.

But where would be the best option to do that? In a Nuxt client middleware? Or in a route watcher in app.vue? Or maybe the page:finish hook? From the implementation of this nuxt module, it wasn't super clear for me on how to do it.

Appreciate your input!

Barbapapazes commented 4 days ago

Hey @madebyfabian, I think the easier way is to add manually the tracker in each page you want to track using https://github.com/nuxt-modules/plausible#usetrackpageview

<script setup>
useTrackPageview()
</script>

See usage in the UnJS website: https://github.com/unjs/website/blob/main/pages/index.vue#L21

Do not hesite if you have more question!

madebyfabian commented 4 days ago

Thanks for your answer! I think there is now a native way to do that in the Plausible settings directly: https://plausible.io/docs/top-pages#block-traffic-from-specific-pages-or-sections