matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.71k stars 2.62k forks source link

Order of events doesn't seem to be honored #21313

Open luukdv opened 1 year ago

luukdv commented 1 year ago

Environment: Matomo Cloud

When sending multiple events in a certain order, the order in which they end up in Matomo seems arbitrary.

Example

_paq.push(['trackEvent', 'Event 1', 'action', undefined, 3000]);
_paq.push(['trackEvent', 'Event 2']);
_paq.push(['trackEvent', 'Event 3', 'action', undefined, 1000]);
_paq.push(['trackEvent', 'Event 4']);

The event order is sometimes correct, but a lot of times they are inserted as follows:

It seems like the order in which trackEvent is called is not respected.

sgiehl commented 11 months ago

Hi @luukdv Thanks for creating this issue. Actually I guess any type of tracking request might not be processed in their order. As those requests are in most cases sent in parallel it can happen that the tracking server processes a later request faster than an earlier. If the order matters I guess the only possible solution at the moment would be to somehow wait for previous tracking request before sending new ones. Is there any specific reason why the order would matter when the requests are sent at the same time anyway?

luukdv commented 10 months ago

If the order matters I guess the only possible solution at the moment would be to somehow wait for previous tracking request before sending new ones.

That's not currently possible right?

Is there any specific reason why the order would matter when the requests are sent at the same time anyway?

Well, the requests aren't sent at the same time - although quite close to each other. When you'd sent an event First event and an event Second event shortly after, it's confusing when that specific order is not respected in Matomo. Sometimes the second event will be processed before the first one in Matomo, as you indicated above.

heurteph-ei commented 10 months ago

Introducing an event counter (reset at each page view) could solve this kind of issue...

z1ad commented 10 months ago

Im facing the same issue - when I submit 2 events at the same second (e.g. click and then open), it will sometimes appear the other way around when displayed on Matomo. Ive attached some screenshots to illustrate the problem.

Both events were sent at the same second (18:11:45) and in the correct sequence (click first, open second) Notice the first request (click) completed 17ms after the second request (open) image

Matomo is showing them the other way around image

The database entries are reversed image

@sgiehl the order definitely matters if we would like to track the sequence of events. is it possible to pass our own timestamp? e.g. with milliseconds included? or possibly some kind of sequence id?