Open ghost opened 4 years ago
Thanks for the issue, for the moment I haven't got a lot of time to develop and test this feature but you can open a pull request.
Thanks
This is a common issue with SPAs, because the default link setup registers event listeners for all the links, but any dynamic re-rendering will lose those event listeners, so you still need to set it up anyway.. This is all assuming enableLinkTracking is true (which is currently the default in this library).
I suggest disabling this as the default and then adding your own onClick handler, so React will still keep it on re-render. (unless there is a good way for this library to pick up on it and you can do a PR).
I created issue #26 to be more explicit.
Links won't be tracked as the DOM changes on each render in React and according to the Matomo (earlier Piwik) documentation it must be rescanned by calling
_paq.push(['enableLinkTracking']);
However this lib is only calling it only once at initing. https://github.com/guillaumeparis2000/react-piwik/blob/d5e8b08105cbac477895d64e63b3da11dd2c5717/src/React-Piwik.js#L39
Not sure where you'd rescan the DOM because every component is changing it in React. Maybe adding a function to add tracking in the
onClick
handler of each link is an alternative.