Arnaud73 / ngx-matomo

Matomo (aka. Piwik) web analytics for Angular applications
MIT License
102 stars 47 forks source link

Matomo initilization hangs when Heatmap & Session Recording plugin is enabled on Matomo server #37

Open ddelabru opened 4 years ago

ddelabru commented 4 years ago

When the the Heatmap & Session Recording plugin is enabled on the Matomo server, the ngx-matomo initialization method retrieves and attempts to execute a configs.php file from the Matomo server containing a single line of JavaScript which class a method of the Piwik object. This call tends to hang indefinitely, driving up CPU usage and crashing our Angular app. Indeed, if I simply try to inspect the Piwik object from the JavaScript console in Firefox while this is happening, that also hangs until Firefox allows me to forcefully stop the script; once I do that the details of the Piwik object do print to the console. This happens only when the plugin mentioned above is enabled.

ddelabru commented 4 years ago

Upon further investigation we determined that the trackPageView() method was being called very close to the time that the initialization was performed, and that if we stopped calling this method altogether the issue stopped.

Ultimately, for our own project we resolved the issue by following the instructions for single-page application tracking with the Heatmaps & Session Recording plugin, using disableAutodetectNewPageView() and setNewPageView(): https://developer.matomo.org/guides/spa-tracking

By the time we manually implemented these measures there didn't seem much point in using ngx-matomo library anymore so we're currently connecting to Matomo without it.

I'm happy to share some code snippets but I'm not sure I'm ready to write a pull request as I don't know how well our workarounds will work for general cases.

alvaromartmart commented 2 years ago

Upon further investigation we determined that the trackPageView() method was being called very close to the time that the initialization was performed, and that if we stopped calling this method altogether the issue stopped.

Ultimately, for our own project we resolved the issue by following the instructions for single-page application tracking with the Heatmaps & Session Recording plugin, using disableAutodetectNewPageView() and setNewPageView(): https://developer.matomo.org/guides/spa-tracking

By the time we manually implemented these measures there didn't seem much point in using ngx-matomo library anymore so we're currently connecting to Matomo without it.

I'm happy to share some code snippets but I'm not sure I'm ready to write a pull request as I don't know how well our workarounds will work for general cases.

Hey @ddelabru, sorry to bring this up again but I'm facing a similar issue and I don't know if it may be related to this one. Could you just clarify one thing, if you remember about it: did this happen using the cloud version of Matomo or some on-premises installation? Thanks!

piwpio commented 2 years ago

@alvaromartmart I had the same issue about 6 months ago when implemented it to one of my project. Because of this error we stopped work and we planned to start write down own plugin... then we dropped idea of implementing matomo at all. Now the topic is back and I will be looking on it again. If @ddelabru will no respond I will look here in some days and will try to help you investigate it. For now I need read documentation again and get little bit deeper inside it. P.S. What a coincidence you responding to 2 years old bug just when I need this to work :)