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

UserID overwrites VisitorID, but doesn't claim existing Visit #19927

Open
SeverinEventfrog opened this issue Oct 28, 2022 · 27 comments
Open

UserID overwrites VisitorID, but doesn't claim existing Visit #19927

SeverinEventfrog opened this issue Oct 28, 2022 · 27 comments
Labels
c: Data Integrity & Accuracy c: Tracking For issues related to getting tracking data into Matomo. Can't reproduce (yet) For issues that are reported by several people, but can't be reproduced reliably and need more data Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical. worksforme The issue cannot be reproduced and things work as intended.

Comments

@SeverinEventfrog
Copy link

We run a webshop. Users can put items in their basket and stroll around, but only need to login with a userId when starting the checkout proceedure. We want to have all actions pre-login also assigned to the userId. However, when enable_userid_overwrites_visitorid = 1 is set (is by default), then Matomo will not find the existing visit pre-login and instead create a new visit for the userId. Thereby loosing a lot of user interactions, like looking at products and not buying them.

Expected Behavior

enable_userid_overwrites_visitorid = 1
Navigate to the home page
1 visit with 1 action with unknown user
Navigate to the login screen
1 visit with 2 actions with unknow user
Login and call setUserId function
1 visit with 3 actions with known user (merging all pass actions)
Logout
1 visit with 4 actions with know user (it continues to put actions in the same visit)

Current Behavior

enable_userid_overwrites_visitorid = 1
Navigate to the home page without any Cookie
1 visit with 1 action with unknown user
Navigate to the login screen
1 visit with 2 actions with unknow user
Login and call setUserId function
1 visit with 2 actions with unknown user
1 visit with 1 action with known user (it didn't merged the pass actions)
Logout and no longer use setUserId
1 visit with 3 actions with unknow user
1 visit with 1 action with known user

Possible Solution

When userId overwrites visitorId, the check for existing visits should also check for visits of the visitorId, if that one is supplied. As when the visitorId is supplied, the trackingrequest clearly states to be from that visitor. So claiming the visit with the newly supplied userID is expected behaviour and even documented here: https://matomo.org/faq/general/how-are-requests-with-a-user-id-tracked/
"When a user logs in, Matomo counts all actions before and after logging in as one user, one visit, and one unique visitor."

Inuitively, this check could be done only, if no active visit for the userId is found.
However, I would suggest claiming the given visit even if another already assigned to the userId exists, as they might be from different devices within 20 minutes and just adding to the older one would disconnect the newer visits's previous actions from the userId.

Pseudocode:
get_existing_visit(visitorId, userId){
visits.add(get_visits_by_visitorId(visitorId)) # make sure, that visitorId has not already been overwriten by userId!
visits.add(get_visits_by_userId(userId))
visits.sort_by_last_action_time()
return visits.pop()
}

Steps to Reproduce (for Bugs)

See Behavior, we use JavaScript Tracking and the _paq.push(['setUserId', 'USER_ID_HERE']);

Context

In our Webshop, we want to know what a user has looked at and done during one sitting. If they happen to log in, we want all their actions to be mapped to their userID. We want this mapping to work, even if the user deletes their Cookies. We also want to be able to use the Matomo UI to click on Visitor-Profile and see all past actions of that User ( not only Visitor!).

We are aware of this option:
enable_userid_overwrites_visitorid = 0
Navigate to the home page
1 visit with 1 action with unknown user
Navigate to the login screen
1 visit with 2 actions with unknow user
Login and call setUserId function
1 visit with 3 actions with known user (just setting userID, vistorID unchanged)
Logout
1 visit with 4 actions with know user (it continued to put actions in the same visit)
But then, should the user ever delete their Cookie or much more likely just use another device, they would get another visitorID. The userID link is our active workaround but is slow for DB SELECTS and the Matomo Admin UI will only show all actions of the same VisitorID and not userID.

Your Environment

  • Matomo Version: 4.10.0
  • PHP Version: 7.3
  • Server Operating System: Debian 4.19.x
  • Additionally installed plugins:
    ** FormAnalytics
    ** GoogleAnalyticsImporter
    ** HeatmapSessionRecording
    ** MediaAnalytics

For information:

Matomo 4.1.0 on Windows
Edge 87 without adblocker
@SeverinEventfrog SeverinEventfrog added the Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. label Oct 28, 2022
@bx80
Copy link
Contributor

bx80 commented Oct 30, 2022

Thanks for reporting this @SeverinEventfrog, the detail you've provided is very helpful 👍

Since this is a case of documented behavior no longer happening in the current release I'll mark this as a regression.

@bx80 bx80 added the Regression Indicates a feature used to work in a certain way but it no longer does even though it should. label Oct 30, 2022
@bx80 bx80 added this to the 5.0.0 milestone Oct 30, 2022
@peterhashair peterhashair removed the Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. label Nov 9, 2022
@janinaMi
Copy link

Hey, im expiriencing the same issue. Could you please prioritize the issue higher, because it really messes up the tracking data.
Maybe it would be a possibility for the matching in the isNewVisit() method to use not only the user-id generated visitor-id, but also the visitor-id, which would be active without user-id?

@bx80
Copy link
Contributor

bx80 commented Nov 28, 2022

@mattab This appears to be the same issue as L3-265. Since it's a regression, should it be assigned to the next point release?

@mattab mattab modified the milestones: 5.0.0, Impact Backlog Nov 30, 2022
@sgiehl
Copy link
Member

sgiehl commented Nov 30, 2022

@SeverinEventfrog @janinaMi Are you only using the setUserId method when the user logs in, or does this also trigger something else, like setCookieConsentGiven or enableBrowserFeatureDetection?

@janinaMi
Copy link

@sgiehl I'm just using the setUserId method

@SeverinEventfrog
Copy link
Author

We also only use setUserId and we only use it after the user logs in. CookieConsent does specifically not trigger it. The moethod is only triggered after the correct userID is known.

@mattab mattab modified the milestones: Impact Backlog, 5.3.0, 5.2.0 Jan 24, 2023
@Starker3
Copy link
Contributor

Starker3 commented May 8, 2023

We have another user experiencing this issue. Due to how their website is setup it makes it appear as though 60% of their visits are from user that are not logged in, even though their website requires an account to access it. This leads to inaccurate reports for them because the existing visit is not claimed when the User ID is set.

@Starker3
Copy link
Contributor

Starker3 commented Jun 5, 2023

We have another customer who is experiencing this issue. They have a website where users are required to be signed in to view any pages and created a Custom Report to track certain actions. That report contains two specific metrics:
Sum of Unique User IDs
Sum of Unique Visitors

The Sum of Unique Visitors is effectively 2x the Sum of Unique User IDs for any period they select.

@atom-box
Copy link

atom-box commented Jun 6, 2023

A customer has pointed out that because of this bug "we reported the wrong numbers" for more than half a year to senior management.

@atom-box
Copy link

atom-box commented Jun 9, 2023

Another customer reported the bug today:

We found that the visit log will separate into 2 logs after the customer login instead of updating the id in the same visit log / profile.

@raphael-kagermeier
Copy link

Hi @Starker3 and @atom-box, we had a similar issue with one of our clients.
We were able to recover this unexpected behavior by accessing the visitorLog via the API and merging visits within a short timeframe that had matching device and screen specs.

While this approach didn't alter the Matomo statistics, it served as an effective workaround given that we where already generating custom (excel) reports for our clients.

The specs we used to merge visits where:

  • operatingSystem
  • deviceModel
  • browser
  • language.

A simple merger plugin for Matomo might be a handy solution for the future, since realizing this misconfiguration is quite frustrating.

@michalkleiner
Copy link
Contributor

We have tried to reproduce this issue to understand exactly the scope of the problem.
It might be a combination of different JS tracker settings such as cookie consent or browser features detection etc.

There were changes in Matomo 5 (PR 20096) related to the tracking requests that might address this so it would be good if the customers could confirm this is still an issue on Matomo 5.

Additionally, we aren't seeing if this worked previously, hence removing the regression label.

We acknowledge that there might be various issues around UserID tracking, but this will require a larger piece of work to fix holistically.

Let us know when you bump into any related issues so we can look into it better.

@michalkleiner michalkleiner added Can't reproduce (yet) For issues that are reported by several people, but can't be reproduced reliably and need more data worksforme The issue cannot be reproduced and things work as intended. and removed Regression Indicates a feature used to work in a certain way but it no longer does even though it should. labels Aug 28, 2023
@MatomoForumNotifications

This issue has been mentioned on Matomo forums. There might be relevant details there:

https://forum.matomo.org/t/two-sessions-instead-of-one-visitor-id-and-user-id/45230/9

@9joshua
Copy link
Contributor

9joshua commented Aug 30, 2023

I can only reproduce this with a Brave browser. Unable to reproduce on Cloud or on-premise with Chrome and FF...
image
The Brave shield was disabled during my test.
My Brave _pk_id cookie still had the original visitor ID.

EDIT: The above test was using v4.15. I was unable to reproduce this with Matomo 5 RC1.

@mattab mattab modified the milestones: 5.2.0, 5.1.0 Sep 5, 2023
@mattab mattab added the Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical. label Sep 12, 2023
@MatomoForumNotifications

This issue has been mentioned on Matomo forums. There might be relevant details there:

https://forum.matomo.org/t/problem-with-changed-idvisitor-and-idvisit-after-login/53946/4

@9joshua
Copy link
Contributor

9joshua commented Nov 27, 2023

Testing again, I can reproduce this in Matomo 4 but not with Matomo 5.

However it is important to note that not calling setUserId on every page will create a different visitor in Matomo.
For example, if setUserId is called prior to any action on the page, all actions will be tracked to that user. If the user ID is not set on any page, or any action is tracked prior to setting the user ID, a new visit and visitor to be created in Matomo and those actions will be recorded to the new visit. My guess is that this can happen at times and in the future this behaviour may be mistaken for the Matomo 4 bug.

I see comments here about users having 2x the unique visitors as user IDs. This can happen after the user logs out and is tracked without setting a User ID. This Custom Report shows the visitor with a User ID of 333Z who was then assigned a visitor ID of 6747e813356d497f after tracking an action without calling setUserId is counted as two unique visitors...
image

It is also important to note that if an ecommerce solution does not also set the same user ID when reporting an ecommerce transaction a new visit will be created. This seems to be quite possible with solutions such as the Matomo WooCommerce plugin which report transactions from the backend and do not have access to the User ID.

@9joshua
Copy link
Contributor

9joshua commented Dec 6, 2023

Another customer has this issue with Matomo 5, tracking via an SDK. I think they have found a reason why this can occur. If a visitor returns to the site and is not recognised by Matomo, they are assigned a new Visitor ID. If an existing User ID is then assigned to this visitor, their visit is split and all subsequent actions are tracked as a new visit. I have reproduced this with Matomo Cloud (5.0.0).

Here the visit was tracked on Firefox but after assigning an existing User ID (101), the visit was split and the browser is reported as the previous known browser (Brave) even though the actual browser for the visit was still Firefox...
image

@mattab mattab added c: Data Integrity & Accuracy c: Tracking For issues related to getting tracking data into Matomo. labels Dec 10, 2023
@Stan-vw Stan-vw removed this from the 5.1.0 milestone Jan 18, 2024
@fulstadev
Copy link

fulstadev commented Jan 22, 2024

We're facing the same issue in Matomo 4.16.0 and also after updating to 5.0.1, same problem. As stated almost one and a half year ago according to this issue, the docs still claim:

https://matomo.org/faq/general/how-are-requests-with-a-user-id-tracked/
"When a user logs in, Matomo counts all actions before and after logging in as one user, one visit, and one unique visitor."

Will this issue be fixed anytime soon? Or is the only way to solve this by setting the enable_userid_overwrites_visitorid = 0 config? If so, we wonder why the default configs in Matomo changed from upon 3 (if what we read is correct) from 0 being the default to 1 being the default. Do we have to worry about any kind of negative implications when setting it to 0 to get rid of this problem ?

@MatomoForumNotifications

This issue has been mentioned on Matomo forums. There might be relevant details there:

https://forum.matomo.org/t/is-visitor-data-merged-into-user-data-after-login/42511/3

@webian
Copy link

webian commented Jan 22, 2024

The same problem for me, more or less. In my use case the user doesn't even need to log in.

As soon as the user puts something in the cart, a new visitor profile is created and an "Abandoned Cart" event appears in the Matomo real-time view for this new visitor profile. The visit is split in 2 visitor profiles. :(

@MatomoForumNotifications

This issue has been mentioned on Matomo forums. There might be relevant details there:

https://forum.matomo.org/t/cid-not-being-enforced-although-sent/54953/3

@KarlGe
Copy link

KarlGe commented Feb 16, 2024

We're struggling with the exact same problem. In our visits log you can see

  1. I already have a registered user from previous visits
  2. I visit the page logged out, a new visit is created
  3. I go through the login process and return to our authentication page
  4. A new visit is created the moment User ID is added, with a new visit ID and Visitor ID connected to the previously registered user
    image

@Starker3
Copy link
Contributor

@KarlGe
What version of Matomo did you encounter this behavior? If you're not yet using Matomo 5 I would recommend updating and see if the issue still happens.

@KarlGe
Copy link

KarlGe commented Feb 20, 2024

@KarlGe What version of Matomo did you encounter this behavior? If you're not yet using Matomo 5 I would recommend updating and see if the issue still happens.

Thanks for the suggestion, from the other replies it seemed like that wouldn't fix it but I will give it a try.

@9joshua
Copy link
Contributor

9joshua commented Feb 25, 2024

Another Cloud customer is experiencing this issue. The have the same symptoms as I described above...

If a visitor returns to the site and is not recognised by Matomo, they are assigned a new Visitor ID. If an existing User ID is then assigned to this visitor, their visit is split and all subsequent actions are tracked as a new visit.

@KarlGe
Copy link

KarlGe commented Feb 26, 2024

Just to confirm @Starker3
We've updated to Matomo 5 (5.0.2) and tried this again
image
Here you can see me first visiting the page, and it gets assigned to one unique visitor
image

Then when I call setUserId, and trackPageView it will connect that to the previous unique visitor that had that userId, without assigning the first part of the visit to that user, hence creating two visits for this one visit
image

This looks to be the exact same thing as 9joshua is describing
We've had to disable user IDs temporarily, since this is happening

@pavelrgl
Copy link

pavelrgl commented Apr 16, 2024

I have the same issue. When I log in, a new visit started and did not merge with the current one.
UserID is set by _paq.push(['setUserId', userData.id]);

it is a SPA, so the user id is set before triggering pageview after login.

Matomo version: 5.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Data Integrity & Accuracy c: Tracking For issues related to getting tracking data into Matomo. Can't reproduce (yet) For issues that are reported by several people, but can't be reproduced reliably and need more data Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical. worksforme The issue cannot be reproduced and things work as intended.
Projects
None yet
Development

No branches or pull requests