tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 67a598e274b90edc42183a54baf7db086fef241a
parent c646419334e394cb3129d1806d740206c957b578
Author: Drew Willcoxon <adw@mozilla.com>
Date:   Thu, 23 Oct 2025 22:32:05 +0000

Bug 1995362 - Part 3: Record the new online Suggest pref in urlbar pref telemetry. r=daisuke,Standard8,urlbar-reviewers

This records the new online prefs in urlbar pref telemetry. I added some code
for treating the `quickSuggestOnlineAvailable` Nimbus variable the same as its
fallback pref for the purpose of this telemetry. That way, when we use Nimbus to
enable new online Suggest for people, we'll record the value that makes sense
for the pref even though technically the pref itself will not be set.

Why record the `online.available` pref/variable in the first place? Because most
regions will not have online Suggest available at all, but all users will have
the `online.enabled` pref set to true by default (see bug 1995362). So recording
only the `enabled` pref wouldn't tell us the whole story.

Depends on D269321

Differential Revision: https://phabricator.services.mozilla.com/D269322

Diffstat:
Mbrowser/components/urlbar/UrlbarController.sys.mjs | 28+++++++++++++++++++++++-----
Mbrowser/components/urlbar/UrlbarPrefs.sys.mjs | 8++++----
Mbrowser/components/urlbar/metrics.yaml | 44+++++++++++++++++++++++++++++++++-----------
Mbrowser/components/urlbar/tests/engagementTelemetry/browser/browser_glean_telemetry_record_preferences.js | 45+++++++++++++++++++++++++++++++++++++++++++--
Mtools/@types/generated/lib.gecko.glean.d.ts | 3++-
5 files changed, 105 insertions(+), 23 deletions(-)

diff --git a/browser/components/urlbar/UrlbarController.sys.mjs b/browser/components/urlbar/UrlbarController.sys.mjs @@ -1623,22 +1623,30 @@ class TelemetryEvent { #PING_PREFS = { maxRichResults: Glean.urlbar.prefMaxResults, - "quicksuggest.dataCollection.enabled": - Glean.urlbar.prefSuggestDataCollection, + "quicksuggest.online.available": Glean.urlbar.prefSuggestOnlineAvailable, + "quicksuggest.online.enabled": Glean.urlbar.prefSuggestOnlineEnabled, "suggest.quicksuggest.nonsponsored": Glean.urlbar.prefSuggestNonsponsored, "suggest.quicksuggest.sponsored": Glean.urlbar.prefSuggestSponsored, "suggest.topsites": Glean.urlbar.prefSuggestTopsites, }; + // Used to record telemetry for prefs that are fallbacks for Nimbus variables. + // `onNimbusChanged` is called for these variables rather than `onPrefChanged` + // but we want to record telemetry as if the prefs themselves changed. This + // object maps Nimbus variable names to their fallback prefs. + #PING_NIMBUS_VARIABLES = { + quickSuggestOnlineAvailable: "quicksuggest.online.available", + }; + #readPingPrefs() { for (const p of Object.keys(this.#PING_PREFS)) { - this.onPrefChanged(p); + this.#recordPref(p); } } - onPrefChanged(pref) { + #recordPref(pref, newValue = undefined) { const metric = this.#PING_PREFS[pref]; - const prefValue = lazy.UrlbarPrefs.get(pref); + const prefValue = newValue ?? lazy.UrlbarPrefs.get(pref); if (metric) { metric.set(prefValue); } @@ -1652,6 +1660,16 @@ class TelemetryEvent { } } + onPrefChanged(pref) { + this.#recordPref(pref); + } + + onNimbusChanged(name, newValue) { + if (this.#PING_NIMBUS_VARIABLES.hasOwnProperty(name)) { + this.#recordPref(this.#PING_NIMBUS_VARIABLES[name], newValue); + } + } + // Used to avoid re-entering `record()`. #handlingRecord = false; diff --git a/browser/components/urlbar/UrlbarPrefs.sys.mjs b/browser/components/urlbar/UrlbarPrefs.sys.mjs @@ -1025,7 +1025,7 @@ class Preferences { * `browser.urlbar.` branch, the name will be relative to the branch. * For other prefs, the name will be the full name. * - `onNimbusChanged` invoked when a Nimbus value changes. It will be - * passed the name of the changed Nimbus variable. + * passed the name of the changed Nimbus variable and the new value. */ addObserver(observer) { this._observerWeakRefs.push(Cu.getWeakReference(observer)); @@ -1111,7 +1111,7 @@ class Preferences { oldNimbus.hasOwnProperty(name) != newNimbus.hasOwnProperty(name) || oldNimbus[name] !== newNimbus[name] ) { - this.#notifyObservers("onNimbusChanged", name); + this.#notifyObservers("onNimbusChanged", name, newNimbus[name]); } } } @@ -1340,7 +1340,7 @@ class Preferences { ); } - #notifyObservers(method, changed) { + #notifyObservers(method, changed, ...rest) { for (let i = 0; i < this._observerWeakRefs.length; ) { let observer = this._observerWeakRefs[i].get(); if (!observer) { @@ -1350,7 +1350,7 @@ class Preferences { } if (method in observer) { try { - observer[method](changed); + observer[method](changed, ...rest); } catch (ex) { console.error(ex); } diff --git a/browser/components/urlbar/metrics.yaml b/browser/components/urlbar/metrics.yaml @@ -816,14 +816,13 @@ urlbar: send_in_pings: - events - pref_suggest_data_collection: + pref_suggest_nonsponsored: lifetime: application type: boolean description: > - Whether the user has opted in to data collection for Firefox Suggest, - i.e., online suggestions served from Merino. + Whether non-sponsored quick suggest results are shown in the urlbar. Corresponds to the value of the - `browser.urlbar.quicksuggest.dataCollection.enabled` pref. + `browser.urlbar.suggest.quicksuggest.nonsponsored` pref. bugs: - https://bugzilla.mozilla.org/show_bug.cgi?id=1847855 - https://bugzilla.mozilla.org/show_bug.cgi?id=1849726 @@ -837,18 +836,41 @@ urlbar: send_in_pings: - events - pref_suggest_nonsponsored: + pref_suggest_online_available: lifetime: application type: boolean description: > - Whether non-sponsored quick suggest results are shown in the urlbar. - Corresponds to the value of the - `browser.urlbar.suggest.quicksuggest.nonsponsored` pref. + Whether online Suggest is available to the user. + Corresponds to the Nimbus variable `quickSuggestOnlineAvailable` and its + fallback pref `browser.urlbar.quicksuggest.online.available`. + NOTE: "Online Suggest" in this context means the new version of online + Suggest introduced in 146 with Terms of Use and OHTTP. bugs: - - https://bugzilla.mozilla.org/show_bug.cgi?id=1847855 - - https://bugzilla.mozilla.org/show_bug.cgi?id=1849726 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1995362 data_reviews: - - https://bugzilla.mozilla.org/show_bug.cgi?id=1847855 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1995362 + data_sensitivity: + - interaction + notification_emails: + - fx-search-telemetry@mozilla.com + expires: never + send_in_pings: + - events + + pref_suggest_online_enabled: + lifetime: application + type: boolean + description: > + This pref is true for all users by default! You probably want to use this + in conjunction with pref_suggest_online_available and/or restrict your + analysis to user populations where you know online Suggest is available. + Corresponds to `browser.urlbar.quicksuggest.online.enabled`. + NOTE: "Online Suggest" in this context means the new version of online + Suggest introduced in 146 with Terms of Use and OHTTP. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1995362 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1995362 data_sensitivity: - interaction notification_emails: diff --git a/browser/components/urlbar/tests/engagementTelemetry/browser/browser_glean_telemetry_record_preferences.js b/browser/components/urlbar/tests/engagementTelemetry/browser/browser_glean_telemetry_record_preferences.js @@ -37,8 +37,12 @@ add_task(async function prefMaxRichResults() { add_task(async function boolPref() { const testData = [ { - green: "prefSuggestDataCollection", - pref: "quicksuggest.dataCollection.enabled", + green: "prefSuggestOnlineAvailable", + pref: "quicksuggest.online.available", + }, + { + green: "prefSuggestOnlineEnabled", + pref: "quicksuggest.online.enabled", }, { green: "prefSuggestNonsponsored", @@ -72,3 +76,40 @@ add_task(async function boolPref() { ); } }); + +add_task(async function boolNimbusVariable() { + const testData = [ + { + glean: "prefSuggestOnlineAvailable", + variable: "quickSuggestOnlineAvailable", + pref: "quicksuggest.online.available", + }, + ]; + + for (const { glean, variable, pref } of testData) { + let initialValue = UrlbarPrefs.get(pref); + Assert.equal( + Glean.urlbar[glean].testGetValue(), + initialValue, + `Record ${glean} when UrlbarController is initialized` + ); + + let nimbusCleanup = await UrlbarTestUtils.initNimbusFeature({ + [variable]: !initialValue, + }); + + Assert.equal( + Glean.urlbar[glean].testGetValue(), + !initialValue, + `Record ${glean} when the ${variable} variable is set` + ); + + await nimbusCleanup(); + + Assert.equal( + Glean.urlbar[glean].testGetValue(), + initialValue, + `Record ${glean} when the ${variable} variable is unset` + ); + } +}); diff --git a/tools/@types/generated/lib.gecko.glean.d.ts b/tools/@types/generated/lib.gecko.glean.d.ts @@ -1292,8 +1292,9 @@ interface GleanImpl { heuristicResultMissing: GleanRate; keywordExposure: GleanEventWithExtras<{ keyword?: string, result?: string, terminal?: string }>; prefMaxResults: GleanQuantity; - prefSuggestDataCollection: GleanBoolean; prefSuggestNonsponsored: GleanBoolean; + prefSuggestOnlineAvailable: GleanBoolean; + prefSuggestOnlineEnabled: GleanBoolean; prefSuggestSponsored: GleanBoolean; prefSuggestTopsites: GleanBoolean; prefSwitchTabsSearchAllContainers: GleanBoolean;