Skip to content

Add immutable visitor property functions to the VisitProperties class #20600

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

Merged
merged 26 commits into from
May 4, 2023

Conversation

bx80
Copy link
Contributor

@bx80 bx80 commented Apr 18, 2023

Description:

When processing a tracking request, visit properties are added to a VisitProperties object by request processors in each plugin. The visit properties are also sometimes modified by the request processors as part of handling the request. This can mean that request processors that handle the request later in the sequence do not have access to the original visit property that they need to perform calculations as the value has already been overwritten.

This PR adds a second set of immutable visit properties to the VisitProperties class. The property can only be set once via the initializeImmutableProperty() method and will throw an exception if an attempt is made to set an existing property. The immutable values are initialized by the VisitRecognizer class and cannot be subsequently modified by request processors.

Since a VisitProperties object is already provided to the processRequestParams() method used by request processors there is no change to the event method signature and this should not affect existing plugin code.

Additional this PR resolves the TODO issue in plugins/Referrers/tests/Integration/ReferrerAttributionTest by providing a reliable way to determine the original referrer visit property.

Fixes #19316

Review

…, Visitor class and populate via the VisitRecognizer. Adjust referrer attribution and tests to use the immutable properties.
@bx80 bx80 added Bug For errors / faults / flaws / inconsistencies etc. not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. labels Apr 18, 2023
@bx80 bx80 added this to the 5.0.0 milestone Apr 18, 2023
@bx80 bx80 self-assigned this Apr 18, 2023
@michalkleiner
Copy link
Contributor

A few little inline comments but in general looks ok to me.

bx80 and others added 4 commits April 19, 2023 09:23
Co-authored-by: Michal Kleiner <mk@011.nz>
@bx80
Copy link
Contributor Author

bx80 commented Apr 18, 2023

@sgiehl I know you spent some time on referrer attribution recently, would you have expected this change to the secondary referrer detection to have changed the tests in this manner?

Copy link
Member

@sgiehl sgiehl left a comment

Choose a reason for hiding this comment

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

I know you spent some time on referrer attribution recently, would you have expected this change to the secondary referrer detection to have changed the tests in this manner?

Maybe I hoped it won't 🙈 But seems this would now end up in having to do #20067 to fix that properly.
Maybe try to revert those changes and only change the isCurrentReferrerDirectEntry method. This might help to avoid the unexpected changes.

bx80 and others added 2 commits April 20, 2023 11:06
Co-authored-by: Stefan Giehl <stefan@matomo.org>
Co-authored-by: Stefan Giehl <stefan@matomo.org>
@bx80
Copy link
Contributor Author

bx80 commented Apr 21, 2023

@sgiehl Using the getImmutableVisitorColumn() method just in isCurrentReferrerDirectEntry has reduced the failing tests to just three each in ReferrerKeywordTest, ReferrerNameTest and ReferrerTypeTest.

The failing tests are all where there is an initial direct entry action followed by referable action, the referrer fields are not being updated for the second action because 'isCurrentReferrerDirectEntry' doesn't find the Common::REFERRER_TYPE_DIRECT_ENTRY when using getImmutableVisitorColumn('referer_type');. If I revert to getVisitorColumn('referer_type'); then the tests pass.

It looks like the plugins/Referrers/Columns/Base::getReferrerInformation() method which detects direct entry is updating the visit properties with Common::REFERRER_TYPE_DIRECT_ENTRY, but isCurrentReferrerDirectEntry() can't see this change when using the immutable properties new method.

This makes me think that isCurrentReferrerDirectEntry() shouldn't be using the new method and perhaps plugins/Referrers/Columns/Campaign::shouldForceNewVisit() should do the direct entry check itself using the immutable properties.

Does that seem like a good approach to you?

@sgiehl
Copy link
Member

sgiehl commented Apr 21, 2023

Aren't those failing tests simply missing a set of the immutable properties? Looking at the tests they seem to be based on an "existing" type being set...

@bx80
Copy link
Contributor Author

bx80 commented Apr 24, 2023

Yes, that was the problem, I hadn't spotted that the tests were directly setting the visit properties. Thanks @sgiehl 🙂

@bx80
Copy link
Contributor Author

bx80 commented Apr 25, 2023

All tests are passing so this should now be ready for a final review.

@bx80 bx80 added the Needs Review PRs that need a code review label Apr 25, 2023
Ben and others added 3 commits April 26, 2023 13:14
…, Visitor class and populate via the VisitRecognizer. Adjust referrer attribution and tests to use the immutable properties.
Co-authored-by: Michal Kleiner <mk@011.nz>
@sgiehl sgiehl force-pushed the m19316-visit-immutable-properties branch from b8864c8 to ef94f2b Compare May 2, 2023 12:54
@bx80 bx80 requested a review from sgiehl May 3, 2023 22:47
Copy link
Member

@sgiehl sgiehl left a comment

Choose a reason for hiding this comment

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

Left two minor suggestions for code improvements. Otherwise this looks good to merge 👍

bx80 and others added 2 commits May 5, 2023 10:18
Co-authored-by: Stefan Giehl <stefan@matomo.org>
Co-authored-by: Stefan Giehl <stefan@matomo.org>
@bx80 bx80 merged commit acb201f into 5.x-dev May 4, 2023
@bx80 bx80 deleted the m19316-visit-immutable-properties branch May 4, 2023 23:50
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. Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Development

Successfully merging this pull request may close these issues.

Updating visit dimensions might not work correctly in some cases
3 participants