commit 95874bf3ff6df2da0f6bccf172c4dda62e148534
parent 238d3985b1f0f80d010bb6f6d6166b9ae141574c
Author: Dale Harvey <dale@arandomurl.com>
Date: Wed, 8 Oct 2025 14:46:10 +0000
Bug 1983122 - Add pref to allow targeting of recent searchers. r=beth,Standard8,urlbar-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D262869
Diffstat:
7 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js
@@ -785,6 +785,11 @@ pref("browser.urlbar.suggest.yelpRealtime", true);
// settings.
pref("browser.urlbar.yelpRealtime.minKeywordLength", 0);
+// Timestamp of the time the user last performed a search via the urlbar
+// so that experiments can target users who have / have not performed
+// urlbar searches.
+pref("browser.urlbar.lastUrlbarSearchSeconds", 0);
+
pref("browser.altClickSave", false);
// Number of milliseconds to wait for the http headers (and thus
diff --git a/browser/components/search/BrowserSearchTelemetry.sys.mjs b/browser/components/search/BrowserSearchTelemetry.sys.mjs
@@ -163,6 +163,13 @@ class BrowserSearchTelemetryHandler {
return;
}
+ if (source.startsWith("urlbar")) {
+ Services.prefs.setIntPref(
+ "browser.urlbar.lastUrlbarSearchSeconds",
+ Math.round(Date.now() / 1000)
+ );
+ }
+
if (source != "contextmenu_visual") {
const countIdPrefix = `${engine.telemetryId}.`;
const countIdSource = countIdPrefix + source;
diff --git a/browser/components/search/test/browser/browser.toml b/browser/components/search/test/browser/browser.toml
@@ -108,6 +108,8 @@ support-files = ["trendingSuggestionEngine.sjs"]
["browser_search_discovery.js"]
+["browser_search_lastused_pref.js"]
+
["browser_searchbar_addEngine.js"]
["browser_searchbar_context.js"]
diff --git a/browser/components/search/test/browser/browser_search_lastused_pref.js b/browser/components/search/test/browser/browser_search_lastused_pref.js
@@ -0,0 +1,35 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const LAST_USED_PREF = "browser.urlbar.lastUrlbarSearchSeconds";
+
+add_setup(async function () {
+ await SearchTestUtils.installOpenSearchEngine({
+ url: getRootDirectory(gTestPath) + "searchSuggestionEngine.xml",
+ setAsDefault: true,
+ });
+
+ registerCleanupFunction(() => {
+ Services.prefs.clearUserPref(LAST_USED_PREF);
+ });
+});
+
+add_task(async () => {
+ let initialValue = Services.prefs.getIntPref(LAST_USED_PREF);
+ await UrlbarTestUtils.promiseAutocompleteResultPopup({
+ window,
+ value: "test",
+ waitForFocus: SimpleTest.waitForFocus,
+ });
+
+ let loaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
+ await UrlbarTestUtils.promisePopupClose(window, () => {
+ EventUtils.synthesizeKey("KEY_Enter");
+ });
+ await loaded;
+
+ let newValue = Services.prefs.getIntPref(LAST_USED_PREF);
+ Assert.greater(newValue, initialValue, "The urlbar search was recorded");
+});
diff --git a/testing/mochitest/ignorePrefs.json b/testing/mochitest/ignorePrefs.json
@@ -24,6 +24,7 @@
"browser.uiCustomization.horizontalTabsBackup",
"browser.uiCustomization.navBarWhenVerticalTabs",
"browser.uiCustomization.state",
+ "browser.urlbar.lastUrlbarSearchSeconds",
"browser.urlbar.placeholderName",
"browser.urlbar.placeholderName.private",
"browser.urlbar.recentsearches.lastDefaultChanged",
diff --git a/toolkit/components/nimbus/lib/TargetingContextRecorder.sys.mjs b/toolkit/components/nimbus/lib/TargetingContextRecorder.sys.mjs
@@ -223,6 +223,7 @@ export const PREFS = Object.freeze({
"browser.newtabpage.enabled": PREF_BOOL,
"browser.startup.page": PREF_INT,
"browser.toolbars.bookmarks.visibility": PREF_STRING,
+ "browser.urlbar.lastUrlbarSearchSeconds": PREF_INT,
"browser.urlbar.quicksuggest.dataCollection.enabled": PREF_BOOL,
"browser.urlbar.showSearchSuggestionsFirst": PREF_BOOL,
"browser.urlbar.suggest.quicksuggest.sponsored": PREF_BOOL,
diff --git a/toolkit/components/nimbus/metrics.yaml b/toolkit/components/nimbus/metrics.yaml
@@ -31,6 +31,7 @@ nimbus_targeting_environment:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1963183
- https://bugzilla.mozilla.org/show_bug.cgi?id=1971552
- https://bugzilla.mozilla.org/show_bug.cgi?id=1967328
+ - https://bugzilla.mozilla.org/show_bug.cgi?id=1983122
data_reviews: &targeting_context_data_reviews
- https://bugzilla.mozilla.org/show_bug.cgi?id=1928107
- https://bugzilla.mozilla.org/show_bug.cgi?id=1937207
@@ -40,6 +41,7 @@ nimbus_targeting_environment:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1963183
- https://bugzilla.mozilla.org/show_bug.cgi?id=1971552
- https://bugzilla.mozilla.org/show_bug.cgi?id=1967328
+ - https://bugzilla.mozilla.org/show_bug.cgi?id=1983122
notification_emails: &targeting_context_notification_emails
- beth@mozilla.com
- project-nimbus@mozilla.com
@@ -80,6 +82,7 @@ nimbus_targeting_environment:
- "browser.newtabpage.enabled"
- "browser.startup.page"
- "browser.toolbars.bookmarks.visibility"
+ - "browser.urlbar.lastUrlbarSearchSeconds"
- "browser.urlbar.quicksuggest.dataCollection.enabled"
- "browser.urlbar.showSearchSuggestionsFirst"
- "browser.urlbar.suggest.quicksuggest.sponsored"
@@ -189,6 +192,8 @@ nimbus_targeting_environment:
type: number
browser__toolbars__bookmarks__visibility:
type: string
+ browser__urlbar__lastUrlbarSearchSeconds:
+ type: number
browser__urlbar__quicksuggest__dataCollection__enabled:
type: boolean
browser__urlbar__showSearchSuggestionsFirst: