Random behavior of visitor log

Hi,
i have a problem with random behavior of logging visitors. I have an application where login is required to use it, so I always have user id. Login page has no tracking.
After user log in, application is sending userid and custom variables on every page but in Piwik i can see two visitor log entry for one person. One is where user id is filled, and second with no user id. On some pages it update activity in anonymous log entry, and on some pages it works fine and update activity in this user log entry.
Is there any reason for this behavior of Piwik? How to track every activities of user with correct userId and variables? Is there any posibility to force tracking only by user Id ?

best regards, Przemek

hi there,

This bug should be fixed in latest piwik beta: I would like to test early beta and RC releases, how do I enable automatic updates to use these development versions? - Analytics Platform - Matomo

see When a User Id is set, try to attach User ID to existing visit before user logged in · Issue #6313 · matomo-org/matomo · GitHub