Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matomo: track client-side navigation page views #360

Closed
Siilwyn opened this issue Jan 20, 2025 · 3 comments
Closed

Matomo: track client-side navigation page views #360

Siilwyn opened this issue Jan 20, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@Siilwyn
Copy link

Siilwyn commented Jan 20, 2025

🆒 Your use case

Using the Matomo script I would like client-side navigation (through <NuxtLink>) to send page view events to Matomo.

🆕 The solution you'd like

Perhaps only if trackPageView is truthy the integration hooks into the vue router to send events.

🔍 Alternatives you've considered

No response

ℹ️ Additional info

No response

@Siilwyn Siilwyn added the enhancement New feature or request label Jan 20, 2025
@Siilwyn Siilwyn changed the title Matomo track client-side navigation page views Matomo: track client-side navigation page views Jan 20, 2025
@joaopedrodcf
Copy link

joaopedrodcf commented Jan 24, 2025

I think this seems a bit unrelated with the nuxt/scripts as it's more how can you do a tracking in a custom library.

I would suggest maybe using route middleware: https://nuxt.com/docs/getting-started/routing#route-middleware to send the event everytime the route changes

// pseudo code

export default defineNuxtRouteMiddleware(async(to, from) => {
const {proxy} = await useScript({src: 'https://your-matomo-domain/matomo.js'});
},{
 {
   use() {
      return { paq: window._paq };
  },
})



proxy._paq.push(['setCustomUrl', to.fullPath]);
proxy._paq.push(['trackPageView']);
export default defineNuxtConfig({
  router: {
    middleware: ['matomo'],
  },
});

@Siilwyn
Copy link
Author

Siilwyn commented Jan 24, 2025

Hmm possibly? I expect an 'official' integration from nuxt/scripts that is about plug-and-play to cover this for me. But I can see this being out of scope too... I'm curious if this is considered in scope or not.

@Siilwyn
Copy link
Author

Siilwyn commented Jan 29, 2025

Because of #322 can't use the proxy either 😓 and getting the correct page title is also an issue in middleware.

Using the useScriptMatomoAnalytics composable and onLoaded in app.vue works:

<script setup lang="ts">
const { onLoaded } = useScriptMatomoAnalytics();

useScriptEventPage(({ title, path }) => {
  onLoaded((matomo) => {
    matomo._paq.push(['setCustomUrl', path]);
    matomo._paq.push(['setDocumentTitle', title]);
    matomo._paq.push(['trackPageView']);
  });
});
</script>

@Siilwyn Siilwyn closed this as completed Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants