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

Multiple unique visit for each action for same User ID #15320

Closed
itmagpro opened this issue Dec 28, 2019 · 9 comments · Fixed by #15337
Closed

Multiple unique visit for each action for same User ID #15320

itmagpro opened this issue Dec 28, 2019 · 9 comments · Fixed by #15337
Labels
Bug For errors / faults / flaws / inconsistencies etc. Regression Indicates a feature used to work in a certain way but it no longer does even though it should.
Milestone

Comments

@itmagpro
Copy link

itmagpro commented Dec 28, 2019

I use latest matomo 3.13.0

I read:

............................................................
Tracking HTTP API: API Reference - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3
https://developer.matomo.org/api-reference/tracking-api

JavaScript Tracking Client: Integrate - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3 - User ID
https://developer.matomo.org/guides/tracking-javascript-guide#user-id

User ID

User ID is a feature in Matomo that lets you connect together a given user's data collected from multiple devices and multiple browsers.
............................................................

I want to use this "User ID feature" and set code in my site:

............................................................
<?php
...
@$uid = substr(sha1($_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT'].$_SERVER['HTTP_ACCEPT_LANGUAGE']), 0, 16);
...
?>

<!-- Matomo -->
<script type="text/javascript">
  var _paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(["setCookieDomain", "*.example.com"]);
  <?php echo sprintf("_paq.push(['setUserId', '%s']);", $uid); ?>
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  ...
</script>
<!-- End Matomo Code -->

<noscript>
<!-- Matomo Image Tracker -->
<img src="https://example.com/piwik.php?idsite=2&amp;rec=1&amp;url=<?php echo rawurlencode(JUri::getInstance()); ?>&amp;action_name=<?php echo rawurlencode('[noscript] '.$document->title); ?>&amp;send_image=0&amp;urlref=<?php echo rawurlencode(@$_SERVER['HTTP_REFERER']); ?>&amp;uid=<?php echo rawurlencode($uid); ?>&amp;cid=<?php echo rawurlencode($uid); ?>" style="border:0" alt="" />
<!-- End Matomo -->
</noscript>
............................................................

In config.ini.php window_look_back_for_visitor var I set to 86400, see my full config.ini.php: https://pastebin.com/KG8FBQHy

But, when I looked statistic:

............................................................
Суббота, 28 декабря 2019 г. - 23:24:12
IP: 188.127.251.xx
Россия

Profile ID (aka uid): d2f22ac701961993
Visitor ID (aka cid): 8cbf24c93d0f4628

Прямой вход
Провайдер: Неизвестно

...............

Суббота, 28 декабря 2019 г. - 23:42:17
IP: 188.127.251.xx
Россия

Profile ID (aka uid): d2f22ac701961993
Visitor ID (aka cid): c3f6fec89ef58cb4

Прямой вход
Провайдер: Неизвестно
............................................................

I see, that same one visitor from same IP, with device and same "Profile ID" (d2f22ac701961993) counted/tracked as unique visitor instead as "Returned visitor" ;(

User ID is feature in Matomo or bug? How to fix this bug?

This bug appear for user which disable cookies, then matomo for same uid (d2f22ac701961993) generate different cid (8cbf24c93d0f4628 | c3f6fec89ef58cb4) for each visit.

Related topics for this problem:

New visit created for each action with userid populated since 3.13 · Issue #15299 · matomo-org/matomo · GitHub
#15299

New visit created for each action with userid populated since 3.13 · Issue #28 · matomo-org/piwik-java-tracker · GitHub
matomo-org/matomo-java-tracker#28

@tsteur
Copy link
Member

tsteur commented Dec 29, 2019

Any chance in your config/config.ini.php there is a setting named trust_visitors_cookies enabled? Even when the cookie changes Matomo should still be able to identify the visitor as the same even if visitorId changes.

@itmagpro
Copy link
Author

itmagpro commented Dec 30, 2019

tsteur - as you see reference on pastebin in my config/config.ini.php trust_visitors_cookies not present, in config/global.ini.php trust_visitors_cookies = 0 You right about "Matomo should", but in this/my case Matomo NOT identify the visitor as the same even if visitorId changes and tracked as "Multiple unique visit for each action for same User ID". config/global.ini.php see here: https://pastebin.com/2zBfLSEh

@tsteur
Copy link
Member

tsteur commented Dec 30, 2019

@itmagpro this looks like the content of config/global.ini.php is that correct?

@tsteur
Copy link
Member

tsteur commented Dec 30, 2019

@itmagpro I think I can reproduce it by adding this tracking code:

        _paq.push(['disableCookies']);
        _paq.push(['setUserId', 'foo']);

@tsteur
Copy link
Member

tsteur commented Dec 30, 2019

It seems Matomo JS tracker is not sending a visitorId when cookies are disabled. I think it should rather generate one randomly @mattab @sgiehl @diosmosis ? And then it will recognize visitor through configId?

In my case every action creates a new visit

@tsteur tsteur added Bug For errors / faults / flaws / inconsistencies etc. Regression Indicates a feature used to work in a certain way but it no longer does even though it should. labels Dec 30, 2019
@tsteur tsteur added this to the 3.13.1 milestone Dec 30, 2019
@diosmosis
Copy link
Member

@tsteur From the issue description there is a visitor ID that's being sent but it changes, which would make sense if cookies were disabled since it wouldn't be able to store the visitor ID, correct? I wonder why the configId isn't being matched, maybe there's something else we store in cookies that is used to compute the config ID.

The new visitor ID w/ disabled cookies I think is expected behavior after merging #14360, and the config ID is supposed to still match those visitors properly, so there must be a problem w/ the config ID... though I'm not sure what, the code looks ok...

@tsteur
Copy link
Member

tsteur commented Jan 1, 2020

The problem is that it checks and userId is null when matching configId here: https://github.com/matomo-org/matomo/blob/3.13.1-b1/core/Tracker/Model.php#L404-L405

I suppose this is not really needed anymore @diosmosis @mattab ?

Also just realising the query above (findVisitorByVisitorId) for visitorId is not needed when visitorId is empty ... should be maybe improved in the same PR

@diosmosis
Copy link
Member

diosmosis commented Jan 1, 2020

👍 makes sense to remove the userId is null check. Can pick the issue upf if needed.

tsteur added a commit that referenced this issue Jan 1, 2020
fix #15320

fyi @mattab @diosmosis 

I wonder if maybe the query should be actually and `user_id is null or user_id = $userIdFromRequestIfGiven`?
@tsteur
Copy link
Member

tsteur commented Jan 1, 2020

👍 created #15337

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. Regression Indicates a feature used to work in a certain way but it no longer does even though it should.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants