The page view is being tracked, but the wrong page title is logged: the previous route title (in other words the old title).
The issue is that the HistoryChange is triggered before my hook to update the title.
What can I do? I tried _paq.push(["setDocumentTitle", document.title]); inside the useEffectHook but it’s not seems to work.
For the guys working with React SPAs: what’s the best way to track page views in MTM with the correct title?
The hook is specific for Matomo so I can re-implement the whole update of document title.
Hi PauRij,
Sadly, nope; I couldn’t find a fix for this issue, the only way I found to track the correct title is to turn off the History Change tag, sob.
Then I choose to track page views on my own programmatically with a custom event, e.g.: _mtm.push({ event: "my-page-view" });
I also asked on Stack Overflow, a few days ago I got an answer: they advised me to add a delay in the tag’s Advanced Settings, but I haven’t tried it yet.
It’s a bit strange that there’s no best practice or solution in the guides or on the web. This should be a fairly common issue, unless I’m missing something obvious.
Thanks for your quick answer! I thought the same… I tested the delay but with me it didn’t work unless I missed something as well. I’m now checking it with Matomo support.