Not in production for now, but it works pretty well so far: in my Matomo container I have a tag (e.g. Matomo Analytics) with two triggers: ‘Pageview’ - for the initial page request on the server (SSR/static site) and ‘History change’ for all further requests when nuxt switches to SPA mode.
In nuxt I have a plugin (plugins/matomo.client.js):
/* eslint-disable */
export default () => {
// manually add the script to the DOM
const script = document.createElement('script')
script.innerHTML = `
<!-- Your Matomo Tag Manager Code -->
`
document.head.appendChild(script)
}
Then add the plugin to nuxt.config.js.
I think a better and more elegant way would be to write something that triggers _mtm.push({‘event’: ‘mtm.PageView’}); everytime a route changes, but for now I’m happy to have something.