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.85k stars 2.64k forks source link

Error in Matomo: Visitor could not be found #16359

Closed ghost closed 3 years ago

ghost commented 4 years ago

Hello everyone,

My matomo generates lots of error_log entries when I click to view a visitor's profile:

Error in Matomo: Visitor could not be found
Error in Matomo: Visitor could not be found
Error in Matomo: Visitor could not be found
Error in Matomo: Visitor could not be found

Unfortunately, these errors are not consistent, they may appear 1 out of 50 profiles. In the 49 cases the profile modal window opens fine, but in the 1 broken case, the modal window does not open. The only consistency, is that the profile that causes the error never works, it will always remain broken no matter what.

I am running matomo 3.14.0 on a CentOS 8 server with php 7.3.5.

Thank you.

tsteur commented 4 years ago

Hi @robo2bobo thanks for creating this issue. This would be expected behaviour when a requested visitor cannot be found. How exactly do you trigger this error?

ghost commented 4 years ago

It happens when I click on the "profile" icon (marked in the screenshot below)

matomo-error-profile

If I keep clicking on the icon, it just generates more of those errors. Every other profile on the page works fine and their profile details modal window appears fine.

Eventually the "broken" user will disappear from the dashboard, as new users visit the site. But, after a few weeks or so, I'll find another profile that does not open and produces the same error.

tsteur commented 4 years ago

Are you maybe using Matomo's userId feature? or have a consent screen on the page and dynamically enable/disable cookies in the JavaScript tracker? It's possible that the visitorId changed and then the link ends up broken until the next refresh.

ghost commented 4 years ago

I managed to find another case that causes this error. I've gathered the following information:

visitor id: 33a6888c3a641432 visit id: 148830

View profile button html:

<a class="visitor-log-visitor-profile-link visitorLogTooltip" data-visitor-id="33a6888c3a641432">
    <img src="plugins/Live/images/visitorProfileLaunch.png"> <span>View visitor profile</span>
</a>

XMLHttpRequest request executes when clicked:

index.php?date=today&module=Live&action=getVisitorProfilePopup&visitorId=33a6888c3a641432&idSite=1&period=day

Raw data returned from the request:

<div class='alert alert-danger'><strong>Error:</strong> Visitor could not be found</div>

Screenshot of problematic profile: profile

Regarding your question, the userid module is enabled in my installation, but I am not using it. I use the matomo-php-tracker but I am not using the setUserId() feature.

tsteur commented 4 years ago

@robo2bobo it sounds to me like some implementation issue in your PHP tracking. Is there any chance that some requests might change the visitorId? If you send a visitorId with every request, could this ID change somehow? If you don't send a visitorId, you need to make sure that you always send the same user agent etc for that visitor.

In case you have some technical experience you may want to enable the tracker debugging for a short time until this issue happens again. While you have this enabled you will also want to enable logging to a file. When you then experience this issue again, I'd check the logs for that visitId. This might explain what's happening.

ghost commented 4 years ago

First of all, thank you for taking the time to debug my problem. I appreciate it.

About my PHP implementation, I've been using the same code for years, since the "piwik" days and never had this issue, the errors started happening over the past few months. To be more specific, at the end of my index.php I have the following code:

require_once("MatomoTracker.php");
$matomoTracker = new MatomoTracker((int)$MATOMO_ID, $MATOMO_URL);
$matomoTracker->setTokenAuth($MATOMO_TOKEN);
$matomoTracker->setRequestTimeout(4);
$matomoTracker->doTrackPageView($title);

I am going to enable debugging and logging to a file and see if I can get more information. I think you are right about your initial observation, that the visitorId changed somehow.

ghost commented 3 years ago

Fixed after upgrade to v4