Tutorial and code to add Matomo to a nuxt 3 project (very easy)
in your terminal enter the following command
npm install --save vue-matomo
Add file your-project/plugins/super-matomo-plugin.js to the project with this :
import { defineNuxtPlugin } from '#app'
import VueMatomo from 'vue-matomo'
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(VueMatomo, {
host: 'https://your-matomo-domain-address.com',
siteId: 1,
// Enables automatically registering pageviews on the router
router: nuxtApp.$router,
enableLinkTracking: true,
requireConsent: false,
trackInitialView: true,
disableCookies: true,
requireCookieConsent: false,
})
})
If you are using Server Side Rendering (SSR) you have to add '.client' in your file name.
exemple : your-project/plugins/super-matomo-plugin.client.js
change the line host: 'https://your-matomo-domain-address.com',
Nuxt 3 auto-import your plugin, so it's done
That it, your are a boss