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

Record default search engine changes #10300

Merged
merged 13 commits into from
Oct 19, 2021
Merged

Record default search engine changes #10300

merged 13 commits into from
Oct 19, 2021

Conversation

rillian
Copy link
Contributor

@rillian rillian commented Sep 28, 2021

Add a P3A probe to record when the default search engine is changed,
and whether it's a transition between Brave Search or one of the
other major services. This helps understand what options are seem
better to users.

Closes brave/brave-browser#18224

Resolves

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

  1. Launch browser.
  2. Go to brave://local-state.
  3. Verify there is a Brave.Search.SwitchEngine entry under p3a.logs. (ctrl/cmd-f to search is helpful)
  4. Value under this should be 0:
    "Brave.Search.SwitchEngine": {
        "sent": <true or false>,
        "timestamp": <some number>,
        "value": "0"
    },
    
  5. Open Settings
  6. Click Search engine
  7. Select a different Search Engine used in the address bar
  8. Switch back to the local-state tab
  9. Reload the page
  10. Verify the value under Brave.Search.SwitchEngine has changed accordingly. (ctrl/cmd-g to repeat the last search is helpful)
  11. Repeat steps 5-10 to verify all combinations are reported correctly.

The measurement looks at both the current and the previous search engine, so it's important to check both switching to and away from Brave Search. However, if the list has 7 possible default search engines, that's 49 combinations, with variations by region, so exhaustive testing is too onerous. Switching to and from Brave Search a couple of times, and once between, say, Google and DuckDuckGo is sufficient.

Brave.SearchSwitchEngine values represent the following transition options:

  1. Haven't switched in the last week
  2. Switched from Brave to Google
  3. Switched from Brave to DuckDuckGo
  4. Switched from Brave to Other
  5. Switched from Google to Brave
  6. Switched from DuckDuckGo to Brave
  7. Switched from Other to Brave
  8. Switched from Other to Other

@rillian rillian requested a review from iefremov as a code owner September 28, 2021 19:47
@rillian rillian self-assigned this Sep 28, 2021
@rillian
Copy link
Contributor Author

rillian commented Sep 28, 2021

@bsclifton Here's a draft PR based on your sketch. I'd appreciate it if you could look it over and comment.

Question: I don't report the "did not switch" options. Would it work to call some alternate report function from the SearchEngineTrack constructor, maybe based on default_seach_url_.is_valid()? I'm unclear when that function runs.

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

Bucket issue aside, LGTM 👍

Would be awesome to re-enable the related tests and add a test for this! 😄 I'd be happy to re-review

@rillian rillian force-pushed the p3a-search-switch branch 2 times, most recently from e6d0644 to c3c3300 Compare October 4, 2021 21:49
@rillian rillian requested a review from goodov October 5, 2021 00:19
@rillian
Copy link
Contributor Author

rillian commented Oct 5, 2021

@goodov How does this look?

@rillian
Copy link
Contributor Author

rillian commented Oct 13, 2021

@goodov What do you think about this approach? Any suggestions on how to access the PrefsRegistry from here?

Add a P3A probe to record when the default search engine is changed,
and whether it's a transition between Brave Search or one of the
other major services. This helps understand what options are seem
better to users.

Keep track of the previous default search engine url. The event
the tracker observes only indicates something has changed, and
by then the previous state is no longer accessible; we need this
to correctly mark the transition in our matrix, separate from
whatever the original default was at startup.

Move the actual record step into an object method so it can access
the saved previous default. This simplifies calling it at startup
to set the initial kNoSwitch answer.

Note: this means we only report a change if the ping is sent from
the same application instance. We don't reset to kNoSwitch at the
end of the weekly sample cadence, and restarting the browser always
resets.

Closes brave/brave-browser#18224
Add a browser test to verify we record transitions as expected.

This is disabled for unstable results, similar to
SearchEngineProviderP3ATest.DefaultSearchEngineP3A.
This is a helper class to record events for later P3A reporting.

It remembers a sequence of enum values for a week, and can return
the most recently-added value within that time period, if any.
Use WeeklyEventStorage to keep track of default search engine
changes over the previous week, so we can return an accurate
report of whether a switch happened during the P3A measurement
period.

This registers a new pref to back the WeeklyEventStorage data.
@rillian
Copy link
Contributor Author

rillian commented Oct 13, 2021

Ready for review again!

I disabled the browser test for the SearchEngineTracker switch P3A because I was seeing unstable results similar to the default engine P3A browser test. CI has been unstable this week anyway, and we wanted to get this probe landed, so I've deferred that to later (brave/brave-browser#13057).

Specialize WeeklyEventStorage to use the basic `int` type for
event codes, rather than being a template class. The removes
type information at call sites using an `enum class` but also
reduces code bloat, which we prefer.
@rillian rillian requested a review from goodov October 14, 2021 23:45
Like the other SearchEngineTracker browser test, this gives unstable
results in ci, tracked in brave/brave-browser#13057.

Disable the test for now, and remove the `MergeHistogramDeltasForTesting`
which we don't expect is necessary and made no difference in testing.
@rillian
Copy link
Contributor Author

rillian commented Oct 18, 2021

I've not been able to get the test stable, so I've disabled it again. Given the priority, I think we should land without browsertest coverage for the P3A probe.

@rillian
Copy link
Contributor Author

rillian commented Oct 18, 2021

I think the android ci failure in unrelated. Restarted the job.

groovy.lang.MissingPropertyException: No such property: getSlackColorMap for class: Script1

@rillian
Copy link
Contributor Author

rillian commented Oct 18, 2021

Likewise the other groovy failures, confirmed by Mihai's post on slack. Looks like these will all fail notifying success. I'll restart them.

@goodov goodov force-pushed the p3a-search-switch branch from b1f5d61 to 49b17a1 Compare October 19, 2021 10:37
@rillian
Copy link
Contributor Author

rillian commented Oct 19, 2021

Thanks for the fixes! @iefremov ok to merge?

Revert the explicit absl build dependency. The base module
already pulls this in, so we don't need to explicitly reference
it even though our usage of absl::Optional is independent.

Also remove an obsolete fixme comment; @goodov's patch fixed this.

Addresses review comments from @iefremov.
- Document the motivation for setting the region.
- Fix a comment typo.
@GeetaSarvadnya
Copy link

GeetaSarvadnya commented Oct 21, 2021

Verification passed on

Brave | 1.33.24 Chromium: 95.0.4638.54 (Official Build) nightly (64-bit)
-- | --
Revision | d31a821ec901f68d0d34ccdbaea45b4c86ce543e-refs/branch-heads/4638@{#871}
OS | Windows 10 Version 21H1 (Build 19043.1288)

Brave default SE supported region - US

Existing user

Default was not Brave, did not switch - PASSED
  • Installed 1.30.x nightly build and ensured that the default SE is set as Google
  • Upgraded to 1.33.x nightly build and ensured that Google was still the default SE after upgrading
  • Confirmed that the response value for Brave.Search.SwitchEngine is 0 as expected
1.30.x Google 1.33.x Google Brave.Search.SwitchEngine - Response value is 0
image image image
Default was Brave, did not switch - PASSED
  • Installed 1.30.x nightly build and ensured that the default SE is set as Brave
  • Upgraded to 1.33.x nightly build and ensured that Brave was still the default SE after upgrading
  • Confirmed that the response value for Brave.Search.SwitchEngine is 0 as expected
1.30.x Brave 1.33.x Brave Brave.Search.SwitchEngine - Response value is 0
image image image
Default was Brave, switched to Google - PASSED
  • Installed 1.30.x nightly build and ensured that the default SE is set as Brave
  • Upgraded to 1.33.x nightly build and changed SE to Google after upgrade
  • Confirmed that the response value for Brave.Search.SwitchEngine is 1 as expected
1.30.x Brave 1.33.x Google Brave.Search.SwitchEngine - Response value is 1
image image image
Default was Brave, switched to DDG - PASSED
  • Installed 1.30.x nightly build and ensured that the default SE is set as Brave
  • Upgraded to 1.33.x nightly build and changed SE to DDG after upgrade
  • Confirmed that the response value for Brave.Search.SwitchEngine is 2 as expected
1.30.x Brave 1.33.x DDG Brave.Search.SwitchEngine - Response value is 2
image image image
Default was Brave, switched to Other (NOT Google OR DDG) - PASSED
  • Installed 1.30.x nightly build and ensured that the default SE is set as Brave
  • Upgraded to 1.33.x nightly build and changed SE to Bing after upgrade
  • Confirmed that the response value for Brave.Search.SwitchEngine is 3 as expected
1.30.x Brave 1.33.x Bing Brave.Search.SwitchEngine - Response value is 3
image image image
Default was Google, switched to Brave - PASSED
  • Installed 1.30.x nightly build and ensured that the default SE is set as Google
  • Upgraded to 1.33.x nightly build and changed SE to Brave after upgrade
  • Confirmed that the response value for Brave.Search.SwitchEngine is 4 as expected
1.30.x Google 1.33.x Brave Brave.Search.SwitchEngine - Response value is 4
image image image
Default was DDG, switched to Brave - PASSED
  • Installed 1.30.x nightly build and ensured that the default SE is set as DDG
  • Upgraded to 1.33.x nightly build and changed SE to Brave after upgrade
  • Confirmed that the response value for Brave.Search.SwitchEngine is 5 as expected
1.30.x DDG 1.33.x Brave Brave.Search.SwitchEngine - Response value is 5
image image image
Default was Other (NOT Google OR DDG), switched to Brave - PASSED
  • Installed 1.30.x nightly build and ensured that the default SE is set as Startpage
  • Upgraded to 1.33.x nightly build and changed SE to Brave after upgrade
  • Confirmed that the response value for Brave.Search.SwitchEngine is 6 as expected
1.30.x Startpage 1.33.x Brave Brave.Search.SwitchEngine - Response value is 6
image image image
Default was Other (not Brave), switched to Other (not Brave) - PASSED
  • Installed 1.30.x nightly build and ensured that the default SE is set as Qwant
  • Upgraded to 1.33.x nightly build and changed SE to Ecosia after upgrade
  • Confirmed that the response value for Brave.Search.SwitchEngine is 7 as expected
1.30.x Qwant 1.33.x Ecosia Brave.Search.SwitchEngine - Response value is 7
image image image

New user

Clean profile, default SE is brave - PASSED
  • Installed 1.33.x nightly build and ensured that the default SE is set as Brave
  • Confirmed that the response value for Brave.Search.SwitchEngine is 0 as expected
1.33.x Brave Brave.Search.SwitchEngine - Response value is 0
image image
Clean profile, default is Brave, switch to Google - PASSED
  • Installed 1.33.x nightly build and ensured that the default SE is set as Brave
  • Change default SE to Google
  • Confirmed that the response value for Brave.Search.SwitchEngine is changed from 0 to 1 as expected
1.33.x Brave Brave.Search.SwitchEngine - Response value is 0 1.33.x Google Brave.Search.SwitchEngine - Response value is 1
image image image image
Clean profile, default is Brave, switch to Google and again switch back to Brave- PASSED
  • Installed 1.33.x nightly build and ensured that the default SE is set as Brave
  • Change default SE to Google and then switch back to Brave
  • Confirmed that the response value for Brave.Search.SwitchEngine is changed from 0 ---> 1-->4 as expected
1.33.x Brave Brave.Search.SwitchEngine - Response value is 0 1.33.x Google Brave.Search.SwitchEngine - Response value is 1 1.33.x Brave Brave.Search.SwitchEngine - Response value is 4
image image image image image image
Clean profile, default is Brave, switch to DDG - PASSED
  • Installed 1.33.x nightly build and ensured that the default SE is set as Brave
  • Change default SE to DDG
  • Confirmed that the response value for Brave.Search.SwitchEngine is changed from 0 to 2 as expected
1.33.x Brave Brave.Search.SwitchEngine - Response value is 0 1.33.x DDG Brave.Search.SwitchEngine - Response value is 2
image image image image
Clean profile, default is Brave, switched to Other (NOT Google OR DDG) - PASSED
  • Installed 1.33.x nightly build and ensured that the default SE is set as Brave
  • Change default SE to Ecosia
  • Confirmed that the response value for Brave.Search.SwitchEngine is changed from 0 to 3 as expected
1.33.x Brave Brave.Search.SwitchEngine - Response value is 0 1.33.x Ecosia Brave.Search.SwitchEngine - Response value is 3
image image image image
Clean profile, default is Brave, switch to Other (NOT Google OR DDG), switched to Brave- PASSED
  • Installed 1.33.x nightly build and ensured that the default SE is set as Brave
  • Change default SE to Startpage and then switch back to Brave
  • Confirmed that the response value for Brave.Search.SwitchEngine is changed from 0 ---> 3-->6 as expected
1.33.x Brave Brave.Search.SwitchEngine - Response value is 0 1.33.x Startpage Brave.Search.SwitchEngine - Response value is 3 1.33.x Brave Brave.Search.SwitchEngine - Response value is 6
image image image image image image
Clean profile, default to Other (not Brave), switched to Other (not Brave)- PASSED
  • Installed 1.33.x nightly build and ensured that the default SE is set as Brave
  • Change default SE to Bing and then switch to Qwant
  • Confirmed that the response value for Brave.Search.SwitchEngine is changed from 0 ---> 3-->7 as expected
1.33.x Brave Brave.Search.SwitchEngine - Response value is 0 1.33.x Bing Brave.Search.SwitchEngine - Response value is 3 1.33.x Qwant Brave.Search.SwitchEngine - Response value is 7
image image image image image image

Brave default SE not supported region - IN

New user

Clean profile, default SE is Google - PASSED
  • Installed 1.30.x nightly build and ensured that the default SE is set as Google
  • Confirmed that the response value for Brave.Search.SwitchEngine is 0 as expected
1.33.x Google Brave.Search.SwitchEngine - Response value is 0
image image
Clean profile, default is Google, switch to Brave - PASSED
  • Installed 1.33.x nightly build and ensured that the default SE is set as Google
  • Change default SE to Brave
  • Confirmed that the response value for Brave.Search.SwitchEngine is changed from 0 to 4 as expected
1.33.x Google Brave.Search.SwitchEngine - Response value is 0 1.33.x Brave Brave.Search.SwitchEngine - Response value is 4
image image image image
Clean profile, default is Google, switch to DDG - PASSED
  • Installed 1.33.x nightly build and ensured that the default SE is set as Google
  • Change default SE to DDG
  • Confirmed that the response value for Brave.Search.SwitchEngine is changed from 0 to 7 as expected
1.33.x Google Brave.Search.SwitchEngine - Response value is 0 1.33.x DDG Brave.Search.SwitchEngine - Response value is 7
image image image image
Clean profile, default is Google, switch to Brave and then switch to Bing - PASSED
  • Installed 1.33.x nightly build and ensured that the default SE is set as Google
  • Change default SE to Brave and then switch to Bing
  • Confirmed that the response value for Brave.Search.SwitchEngine is changed from 0 --> 4 -->3as expected
1.33.x Google Brave.Search.SwitchEngine - Response value is 0 1.33.x Brave Brave.Search.SwitchEngine - Response value is 4 1.33.x Bing Brave.Search.SwitchEngine - Response value is 3
image image image image image image

Existing user

Default was not Brave, did not switch - PASSED
  • Installed 1.30.x nightly build and ensured that the default SE is set as Google
  • Upgraded to 1.33.x nightly build and ensured that Google was still the default SE after upgrading
  • Confirmed that the response value for Brave.Search.SwitchEngine is 0 as expected
1.30.x Google 1.33.x Google Brave.Search.SwitchEngine - Response value is 0
image image image
Default was Brave, did not switch - PASSED
  • Installed 1.30.x nightly build and ensured that the default SE is set as Brave
  • Upgraded to 1.33.x nightly build and ensured that Brave was still the default SE after upgrading
  • Confirmed that the response value for Brave.Search.SwitchEngine is 0 as expected
1.30.x Brave 1.33.x Brave Brave.Search.SwitchEngine - Response value is 0
image image image
Default was Brave, switched to Google - PASSED
  • Installed 1.30.x nightly build and ensured that the default SE is set as Brave
  • Upgraded to 1.33.x nightly build and switch SE to Google
  • Confirmed that the response value for Brave.Search.SwitchEngine is 1 as expected
1.30.x Brave 1.33.x Brave Brave.Search.SwitchEngine - Response value is 1
image image image
Default was Brave, switched to DDG - PASSED
  • Installed 1.30.x nightly build and ensured that the default SE is set as Brave
  • Upgraded to 1.33.x nightly build and switch SE to Google
  • Confirmed that the response value for Brave.Search.SwitchEngine is 2 as expected
1.30.x Brave 1.33.x Brave Brave.Search.SwitchEngine - Response value is 2
image image image
Default was Other (not Brave), switched to Other (not Brave) - PASSED
  • Installed 1.30.x nightly build and ensured that the default SE is set as Statpage
  • Upgraded to 1.33.x nightly build and switch SE to Bing
  • Confirmed that the response value for Brave.Search.SwitchEngine is 7 as expected
1.30.x Statpage 1.33.x Bing Brave.Search.SwitchEngine - Response value is 7
image image
image
Default was Other (NOT Google OR DDG), switched to Brave - PASSED
  • Installed 1.30.x nightly build and ensured that the default SE is set as Qwant
  • Upgraded to 1.33.x nightly build and switch SE to Brave
  • Confirmed that the response value for Brave.Search.SwitchEngine is 6 as expected
1.30.x Qwant 1.33.x Brave Brave.Search.SwitchEngine - Response value is 6
image image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[P3A] New question about Search providers
6 participants