How could I use the Matomo on the single page web application?

(Bruce975) #1

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?

(Lukas Winkler) #2

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']);

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

(Bruce975) #3

Ok,I will try it later, thank you!

(Fabian Dellwing) #4

If you use a common SPA there is very likely already an implementation: