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

API bug? - Twice the amount of visitors in method Live.getCounters just after midnight #16293

Closed
ColinDude2020 opened this issue Aug 13, 2020 · 6 comments
Labels
answered For when a question was asked and we referred to forum or answered it.

Comments

@ColinDude2020
Copy link

I’m calling this URL every 5 minutes: https://$baseurl/?module=API&token_auth=$token&method=Live.getCounters&idSite=2&lastMinutes=10&format=json

Somehow, the “visitors” measure is always twice as high as it should be when the URL is called between 00:00 AM and 00:10 AM. This always happened, so I can reproduce it at that timeframe.

I’m using Matomo 3.14.0 on Ubuntu 18.04, on-premise.

Any thoughts?

@ColinDude2020 ColinDude2020 changed the title Twice the amount of visitors in method Live.getCounters just after midnight API bug? - Twice the amount of visitors in method Live.getCounters just after midnight Aug 13, 2020
@tsteur tsteur added the Waiting for user feedback Indicates the Matomo team is waiting for feedback from the author or other users. label Aug 13, 2020
@tsteur
Copy link
Member

tsteur commented Aug 13, 2020

Thanks for creating the issue @ColinDude2020 .

Looking in the code at the database query things look all good. Does the same happen for visits and actions?

Note: the query is :

			SELECT
				COUNT(DISTINCT log_visit.idvisitor)
			FROM
				matomo_log_visit AS log_visit
			WHERE
				log_visit.idsite in (2) AND log_visit.visit_last_action_time >= '...'

@ColinDude2020
Copy link
Author

I'll get back at you asap!

@ColinDude2020
Copy link
Author

Okay, I captured a few json files, pasted here: https://pastebin.com/pQbxBChN

"actions" seems not to be affected. but both "visitors" and "visits" are.

I use the Symfony framework to register the visitors (using the server-side api with curl) like this. These are my post params. Maybe that could be a lead?

$postData = array(
"token_auth" => '1234',
"cip" => $ip,
"rec" => 1,
"idsite" => 2,
"action_name" => $actionName,
"url " => urlencode($url),
"apiv" => 1,
"_id" => $session->get('unique_userid'),
"urlref" => $_SERVER["HTTP_REFERER"] ?? null
);

@ColinDude2020
Copy link
Author

ColinDude2020 commented Aug 15, 2020

I just realized that it's probably caused by the _id mapping. Something funny happens with the PHP function uniqid() around midnight.

           $session = $request->getSession();

            if (!$session->get('unique_userid'))
            {
                $session->set('unique_userid', uniqid());
            }

I don't have registered users, so I cannot use something like a username or e-mail address for the _id mapping. Should I try changing it to md5($ipAddress) ?

Okay for testing purposes I have just changed it to:

"_id" => substr(md5($ip),0,16)

@ColinDude2020
Copy link
Author

So that fixes it for me. No bug on Mamoto's side.

Somehow the session within Symfony resets at exactly 00:00 mid night. I'm keeping the change, works fine for me. 👍

Thanks!

@tsteur
Copy link
Member

tsteur commented Aug 16, 2020

Awesome thanks for letting us know @ColinDude2020

@tsteur tsteur closed this as completed Aug 16, 2020
@tsteur tsteur added answered For when a question was asked and we referred to forum or answered it. and removed Waiting for user feedback Indicates the Matomo team is waiting for feedback from the author or other users. labels Aug 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it.
Projects
None yet
Development

No branches or pull requests

2 participants