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
Adds tests for referrer attribution of visits & conversions #19250
Conversation
0d450f6
to
b5d7709
Compare
@sgiehl have you checked every dimension (including non-core plugins) to see if this could cause any regression there? Do I see this right that we have a method |
@tsteur I was thinking about using that method in the first place. But looking through the code I wasn't sure if it really contains what I would have expected. The previous visit property might either contain the current visit data or the previous visit data, if a new one was started. Anyway, shouldn't we use the same data for triggering every dimensions hook? Otherwise it can always end in unknown results based on the order the dimensions are walked through. I also had a look through the usages of |
be5c5d8
to
ce9fc46
Compare
What was the unexpected there @sgiehl ? I'm not so much into that part right now so it's not quite clear. If it's the different data for existing vs new visit, maybe we could look changing this?
I don't think that needs to be the case if we have clear naming for those methods for whether we access data from previous visit or current visit that may have been updated already. Maybe AFAIK dimensions are sorted depending on the plugin order. Meaning core plugins are updated first and other non-core plugins might want to see for example what was updated etc. Does that make sense? Possible I misunderstand something |
I got confused by the naming of the method already. For me But back to the actual problem I'm seeing with directly updating column properties. As I tried to describe before, doing that might bring up results in an unexpected state. The order in which the columns are processed is kind of defined by the plugins list in global config. All additional plugins are processed afterwards in sorted order. The problem I'm seeing with that, is that the result for The current problem with incorrectly set referrer url in some cases might also be solvable by changing the columns to use |
Regarding the dependency I think the dependency is maybe less between non-core plugins but more like that non-core plugins should be executed after core plugins. Indeed the naming is really not clear. I think that's the biggest problem here. Because with This way we would keep having the flexibility to access the original values or the changed values (knowing that there's only basic dependency management which may be good enough) |
@tsteur I tried updating the PR to use Refactoring and renaming the methods in Matomo 5 sounds good. We maybe should also remove the different use cases for But to solve this here now, we either use the "update all at once" I had implemented before, or I need to spend another day on refactoring the referrer detection. |
Coming back to the original issue. Can we maybe understand the problem a bit better to know how big the problem actually is? And then potentially we could actually create an issue for it so it can be scheduled. I'm not really sure we want to apply the original update all at once as it could cause a regression and it's really hard to tell. I looked at some code but it's hard to tell if it would be fine or not and it removes some flexibility maybe. Maybe for now we only merge the tests and create a new bug report for this issue so it can be prioritised and scheduled if needed? |
@tsteur The tests are failing without the change, as the referrer url is not updated correctly. |
👍 Let's do this for now and create a new issue describing the problem what it means for users. It's not really fully clear yet what the impact of it is. And be also good to qualify if it would create a new visit in some cases? I've tried to confirm implications re the initial solution but it would take quite a while to be fully sure it doesn't cause any regression thinking of a case like Updating them after a hook it's also still not clear that the next time a different hook is triggered, the visit is updated after all. Maybe in Matomo 5 it could be fixed properly or maybe |
@tsteur I've now adjusted the tests so they work without any other changes, but added some todos so it's clear which parts are actual incorrect behavior. Also created a follow-up issue for Matomo 5: #19316 Feel free to update the description or add a comment if I forgot to mention something important. |
Great, thanks 👍 |
Tests are passing, so I'll merge this one now. Everything else will be handled in the follow-up issue. |
* Adds first bunch of referrer attribution tests * simplify tests * refactor tests to use data provider, so its easier adding new tests * Add new test cases * Refactor tests into automically created test cases * implement tests for campaign handling * Adjust tests so they pass
Description:
While writing tests for the referrer attribution, I came across an issue where the referrer url was not updated correctly.
Having a closer look at the code around dimensions, visitor properties and how they are updated showed, that we might have an issue there.
Currently when a new action happens all visitor properties are loaded and the
onExistingVisit
hook is triggered. This one might return a value if it needs to be changed. If that is the case the property is directly updated.This might actually cause problems as it's not possible to rely on the data that is provided. I'll try to explain that with a simple example around the referrer detection.
The referrer url has an
onExistingVisit
hook, that checks if the referrer type is DIRECT. If that is the case, the URL will be updated.The referrer type basically does the same. The problem that might occur here is if the referrer type property is updated before the referrer url, the type might have already been changed to another value, causing the referrer url not to update, as the referrer type isn't DIRECT anymore.
If both dimensions are updated in reversed order both dimensions would change their value. So the result basically depends on the order of the dimensions, which depends on the order the plugins are loaded. So that can be kind of random.
So what this PR basically changes is, that (when triggering an hook for updating dimensions) the hooks for all dimensions will be triggered and the values that need to be changed will be gathered. After all hooks were triggered all dimensions will be updated at once. This guarantees that all dimension hooks will be triggered with the same set of properties.
As this is quite a fundamental change on how that works, it might be good if @tsteur might have a look here as well.
Additionally this PR adds tests with around 440 test cases for referrer attribution.
refs #18612
Review