Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not asynchronous enough #14097

Open
indeyets opened this issue Feb 13, 2019 · 11 comments
Open

Not asynchronous enough #14097

indeyets opened this issue Feb 13, 2019 · 11 comments
Labels
c: Performance For when we could improve the performance / speed of Matomo. Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.

Comments

@indeyets
Copy link

Matomo tracker-code itself is loaded asynchronously, but the problem is, that sometimes JS is loaded fast and is executed before document is ready. JS calls piwik.php to be loaded as a GIF file which, somehow, blocks execution of other JS on the page.

I saw this in high-load scenario when database was overloaded and answered really slow:

  1. page loads
  2. matomo is loaded asynchronously
  3. banners-code is loaded asynchronously
  4. matomo starts loading piwik.php as a GIF
  5. (~20 seconds paus)
  6. banners are rendered

I was able to mitigate this by delating matomo initialisation till page's onLoad event.

It would be much better if matomo delayed image-call until onLoad instead. this way matomo code would be up and running earlier, gathering info, but it still wouldn't lock execution of other js-code.

I did my tests in Google Chrome 72

@tsteur
Copy link
Member

tsteur commented Feb 13, 2019

See https://matomo.org/blog/2017/04/different-ways-embedding-piwik-tracking-code-faster-website-performance/ that maybe helps? Let me know if anything needs to be done.

@tsteur tsteur closed this as completed Feb 13, 2019
@tsteur tsteur added the answered For when a question was asked and we referred to forum or answered it. label Feb 13, 2019
@tsteur
Copy link
Member

tsteur commented Feb 13, 2019

If you use the content tracking feature, you can also just load the tracker regularly (to track as many pageviews as possible), and onload for example call the tracker method trackAllContentImpressions again (so far we only execute it onReady).

@indeyets
Copy link
Author

Thanks @tsteur. I did something like this already. But this is suboptimal. Matomo could act better in this regard by queueing requests until DOM is ready.

This issue was not a question or request for help. I believe code should be fixed to handle these situation better

@tsteur
Copy link
Member

tsteur commented Feb 13, 2019

Not sure exactly what you mean? From your message I assume you are using content tracking? So we could check for new content impressions onLoad ...

@indeyets
Copy link
Author

@tsteur first blocking request is a tracking pixel. Pageview I believe. Content tracking happens later on

Anyway, what I mean is: default configuration of matomo should not block normal page loading process. No matter if matomo server is under load or slow for another reason. UX should not be harmed.

One way to achieve this is to delay any network requests from piwik.js until page's DOM is in "ready" state

@tsteur
Copy link
Member

tsteur commented Feb 13, 2019

Anyway, what I mean is: default configuration of matomo should not block normal page loading process. No matter if matomo server is under load or slow for another reason. UX should not be harmed.

Some would for sure argue differently but for sure UX is key :)

One way to achieve this is to delay any network requests from piwik.js until page's DOM is in "ready" state

So far it's sending it right away. You could influence it though basically by just putting the JS code at the end of the DOM </body>? When loaded async and deferred the Matomo footprint should be tiny.

@indeyets
Copy link
Author

You could influence it though basically by just putting the JS code at the end of the DOM

sure, I could. but that's a workaround that should be done by me again. I advocate for robust behaviour on matomo side so that users are not forced to think about it.

Compare this with google-analytics which works just fine in similar scenarios.

@tsteur I really believe this is a bug in matomo

@tsteur
Copy link
Member

tsteur commented Feb 14, 2019

I'll reopen it for now. UX definitely is more important than anything else these days. At the same time delaying the tracking request to onReady is not going to do too much. Because when you load the piwik.js everything will be already parsed and loaded etc. and all you save is a wee tiny request.

@tsteur tsteur reopened this Feb 14, 2019
@tsteur tsteur added Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself. and removed answered For when a question was asked and we referred to forum or answered it. c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself. labels Feb 14, 2019
@tsteur
Copy link
Member

tsteur commented Feb 24, 2019

BTW: When the script is loaded defered as suggested in our default code, it should maybe also execute only after the page is parsed?

@mattab
Copy link
Member

mattab commented Jan 21, 2020

Compare this with google-analytics which works just fine in similar scenarios.

It would be interesting to know what logic GA uses to not experience this issue?

@mattab mattab added the c: Performance For when we could improve the performance / speed of Matomo. label Jan 21, 2020
@qcho
Copy link

qcho commented Nov 5, 2020

GA uses service workers and postpones everything after load afaik

Source: https://developers.google.com/web/showcase/2016/service-worker-perf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Performance For when we could improve the performance / speed of Matomo. Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Projects
None yet
Development

No branches or pull requests

5 participants