I need some help.How could I use the Matomo in the single page web application?
The way to do that on your website is to listen to hashChange.But it seem that it didn’t work, because most of the SPA are using the window.history to control the router.Is there any better solution?
Yes,
The hashchange listener in Single-Page Application Tracking: Integrate - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3 is just a simple example.
The better way to track page changes is simply integrating the
_paq.push(['setCustomUrl', '/' + window.location.hash.substr(1)]);
_paq.push(['setDocumentTitle', 'My New Title']);
_paq.push(['trackPageView']);
into your router. Every SPA router I know has the possibility to execute JS on page view and that’s where you should call Matomo
Ok,I will try it later, thank you!
If you use a common SPA there is very likely already an implementation: