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

Match configId even when userId is found #15337

Merged
merged 4 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions core/Tracker/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public function updateAction($idLinkVa, $valuesToUpdate)
return $wasInserted;
}

public function findVisitor($idSite, $configId, $idVisitor, $fieldsToRead, $shouldMatchOneFieldOnly, $isVisitorIdToLookup, $timeLookBack, $timeLookAhead)
public function findVisitor($idSite, $configId, $idVisitor, $userId, $fieldsToRead, $shouldMatchOneFieldOnly, $isVisitorIdToLookup, $timeLookBack, $timeLookAhead)
{
$selectCustomVariables = '';

Expand Down Expand Up @@ -398,10 +398,20 @@ public function findVisitor($idSite, $configId, $idVisitor, $fieldsToRead, $shou
} elseif ($shouldMatchOneFieldOnly) {
$visitRow = $this->findVisitorByConfigId($configId, $select, $from, $configIdWhere, $configIdbindSql);
} else {
$visitRow = $this->findVisitorByVisitorId($idVisitor, $select, $from, $visitorIdWhere, $visitorIdbindSql);
if (!empty($idVisitor)) {
$visitRow = $this->findVisitorByVisitorId($idVisitor, $select, $from, $visitorIdWhere, $visitorIdbindSql);
} else {
$visitRow = false;
}

if (empty($visitRow)) {
$configIdWhere .= ' AND user_id IS NULL ';
$configIdWhere .= ' AND ( user_id IS NULL ';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diosmosis @mattab noticing this would create a new visit when userId was previously set, and then user logs out using resetUserId. I suppose this is not what we want as we also don't create a new visit when userId is set initially. I suppose we maybe really only always want to add AND ( user_id IS NULL OR user_id = ? ) when userId is not empty?

Copy link
Member Author

@tsteur tsteur Jan 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also when user is found by idVisitor, then we would also not create a new visit after resetUserId so we need to make sure to have consistent behavior no matter if cookies are enabled or disabled... I will later change the query I reckon to only compare userId when a userId is set

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If userId is null, we'd want to look for ( user_id IS NULL ) though, correct? Otherwise it would match the logged out user. Then again, ( user_id IS NULL OR user_id = ? ) would also match the user after they login (ie, logged out => login), so maybe both behaviors are desired?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's current desired/ implemented behaviour AFAIK and that's how it also works when it matches the visit by visitorId. See thread in matomo-org/developer-documentation#320

We just need to make sure to always have consistent behaviour on log in and log out. Either we always create a new visit on log in and log out, or never.

Copy link
Member

@diosmosis diosmosis Jan 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the point of separating user ID from visitor ID was so you could tell when a user logged in/out. Ie, it would count as the same visitor (along with same user different idvisitor being different visitors but one user), but count as different users? Maybe this isn't clear anymore w/ the userid change...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure? If that's the case, then I think this wasn't implemented.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right it was never implemented. It does seem more useful to me though. I guess it could go in another issue.

if (!empty($userId)) {
$configIdWhere .= 'OR user_id = ? )';
$configIdbindSql[] = $userId;
} else {
$configIdWhere .= ')';
}
$visitRow = $this->findVisitorByConfigId($configId, $select, $from, $configIdWhere, $configIdbindSql);
}
}
Expand Down
3 changes: 2 additions & 1 deletion core/Tracker/VisitorRecognizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function findKnownVisitor($configId, VisitProperties $visitProperties, Re
{
$idSite = $request->getIdSite();
$idVisitor = $request->getVisitorId();
$userId = $request->getForcedUserId();

$isVisitorIdToLookup = !empty($idVisitor);

Expand All @@ -98,7 +99,7 @@ public function findKnownVisitor($configId, VisitProperties $visitProperties, Re
$shouldMatchOneFieldOnly = $this->shouldLookupOneVisitorFieldOnly($isVisitorIdToLookup, $request);
list($timeLookBack, $timeLookAhead) = $this->getWindowLookupThisVisit($request);

$visitRow = $this->model->findVisitor($idSite, $configId, $idVisitor, $persistedVisitAttributes, $shouldMatchOneFieldOnly, $isVisitorIdToLookup, $timeLookBack, $timeLookAhead);
$visitRow = $this->model->findVisitor($idSite, $configId, $idVisitor, $userId, $persistedVisitAttributes, $shouldMatchOneFieldOnly, $isVisitorIdToLookup, $timeLookBack, $timeLookAhead);
$this->visitRow = $visitRow;

if ($visitRow
Expand Down