My website is built with nextjs so pages are never refreshed.
i am using tag manager with page view as action but i cant get it to track all pages
My website is built with nextjs so pages are never refreshed.
i am using tag manager with page view as action but i cant get it to track all pages
Hi,
Since your site is built with Next.js (SPA), page reloads do not happen, so Matomo does not automatically track page views.
You need to manually trigger a page view on route change.
If you are using Matomo Tag Manager, do the following:
Use a History Change or Custom Event trigger
Fire a Page View tag on every route change
Update document.title and window.location.pathname before sending the page view
If you are using the JS tracker directly, call:
_paq.push([‘setCustomUrl’, window.location.pathname]);
_paq.push([‘setDocumentTitle’, document.title]);
_paq.push([‘trackPageView’]);
This is the correct way to track dynamic URLs in SPA frameworks like Next.js.