Bug 1381460 - Add telemetry search event for Activity Stream. f=florian, r=Dexter, data-r=bsmedberg
☠☠ backed out by 956fc7cc7ce8 ☠ ☠
authorAndrei Oprea <aoprea@mozilla.com>
Mon, 24 Jul 2017 15:04:02 -0700
changeset 419483 839d8a60a2eaf716fe4dbc2296cfd6bc6703e3db
parent 419482 0a60cc1983211905a5bc0aaf9e3414469add6b91
child 419484 9315eabc7fb0301e772359505bff5704fe894b99
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersDexter
bugs1381460
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1381460 - Add telemetry search event for Activity Stream. f=florian, r=Dexter, data-r=bsmedberg MozReview-Commit-ID: 6FzcVbwVimw
browser/extensions/activity-stream/data/content/activity-stream.bundle.js
browser/modules/BrowserUsageTelemetry.jsm
browser/modules/test/browser/browser_UsageTelemetry_content.js
toolkit/components/telemetry/Events.yaml
toolkit/components/telemetry/Scalars.yaml
--- a/browser/extensions/activity-stream/data/content/activity-stream.bundle.js
+++ b/browser/extensions/activity-stream/data/content/activity-stream.bundle.js
@@ -1707,22 +1707,17 @@ class Search extends React.Component {
       this.props.dispatch(ac.UserEvent({ event: "SEARCH" }));
     }
   }
   onClick(event) {
     this.controller.search(event);
   }
   onInputMount(input) {
     if (input) {
-      // The first "newtab" parameter here is called the "healthReportKey" and needs
-      // to be "newtab" so that BrowserUsageTelemetry.jsm knows to handle events with
-      // this name, and can add the appropriate telemetry probes for search. Without the
-      // correct name, certain tests like browser_UsageTelemetry_content.js will fail (See
-      // github ticket #2348 for more details)
-      this.controller = new ContentSearchUIController(input, input.parentNode, "newtab", "newtab");
+      this.controller = new ContentSearchUIController(input, input.parentNode, "activitystream", "activitystream");
       addEventListener("ContentSearchClient", this);
     } else {
       this.controller = null;
       removeEventListener("ContentSearchClient", this);
     }
   }
 
   /*
--- a/browser/modules/BrowserUsageTelemetry.jsm
+++ b/browser/modules/BrowserUsageTelemetry.jsm
@@ -39,16 +39,17 @@ const UNFILTERED_URI_COUNT_SCALAR_NAME =
 
 // A list of known search origins.
 const KNOWN_SEARCH_SOURCES = [
   "abouthome",
   "contextmenu",
   "newtab",
   "searchbar",
   "urlbar",
+  "activitystream"
 ];
 
 const KNOWN_ONEOFF_SOURCES = [
   "oneoff-urlbar",
   "oneoff-searchbar",
   "unknown", // Edge case: this is the searchbar (see bug 1195733 comment 7).
 ];
 
@@ -433,16 +434,18 @@ let BrowserUsageTelemetry = {
         this._handleSearchAndUrlbar(engine, source, details);
         break;
       case "abouthome":
         this._recordSearch(engine, "about_home", "enter");
         break;
       case "newtab":
         this._recordSearch(engine, "about_newtab", "enter");
         break;
+      case "activitystream":
+        this._recordSearch(engine, "activitystream", "enter");
       case "contextmenu":
         this._recordSearch(engine, "contextmenu");
         break;
     }
   },
 
   /**
    * This function handles the "urlbar", "urlbar-oneoff", "searchbar" and
--- a/browser/modules/test/browser/browser_UsageTelemetry_content.js
+++ b/browser/modules/test/browser/browser_UsageTelemetry_content.js
@@ -1,13 +1,14 @@
 "use strict";
 
 const BASE_PROBE_NAME = "browser.engagement.navigation.";
 const SCALAR_CONTEXT_MENU = BASE_PROBE_NAME + "contextmenu";
 const SCALAR_ABOUT_NEWTAB = BASE_PROBE_NAME + "about_newtab";
+const SCALAR_ABOUT_ACTIVITYSTREAM = BASE_PROBE_NAME + "activitystream";
 
 add_task(async function setup() {
   // Create two new search engines. Mark one as the default engine, so
   // the test don't crash. We need to engines for this test as the searchbar
   // in content doesn't display the default search engine among the one-off engines.
   Services.search.addEngineWithDetails("MozSearch", "", "mozalias", "", "GET",
                                        "http://example.com/?q={searchTerms}");
 
@@ -85,22 +86,31 @@ add_task(async function test_context_men
   checkEvents(events, [["navigation", "search", "contextmenu", null, {engine: "other-MozSearch"}]]);
 
   contextMenu.hidePopup();
   await BrowserTestUtils.removeTab(gBrowser.selectedTab);
   await BrowserTestUtils.removeTab(tab);
 });
 
 add_task(async function test_about_newtab() {
+  // Test newtab search event.
+  const ACTIVITY_STREAM_ENABLED = Services.prefs.getBoolPref("browser.newtabpage.activity-stream.enabled");
+  if (ACTIVITY_STREAM_ENABLED === true) {
+    Services.prefs.setBoolPref("browser.newtabpage.activity-stream.enabled", false);
+  }
   // Let's reset the counts.
   Services.telemetry.clearScalars();
   Services.telemetry.clearEvents();
   let search_hist = getSearchCountsHistogram();
 
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:newtab", false);
+  // browser.newtab.preload preloads a new tab before pref change actually happens.
+  // We need to throw away the first tab we open because it will not be up to date.
+  await BrowserTestUtils.removeTab(tab);
+  tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:newtab", false);
   await ContentTask.spawn(tab.linkedBrowser, null, async function() {
     await ContentTaskUtils.waitForCondition(() => !content.document.hidden);
   });
 
   info("Trigger a simple serch, just text + enter.");
   let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
   await typeInSearchField(tab.linkedBrowser, "test query", "newtab-search-text");
   await BrowserTestUtils.synthesizeKey("VK_RETURN", {}, tab.linkedBrowser);
@@ -115,10 +125,57 @@ add_task(async function test_about_newta
   // Make sure SEARCH_COUNTS contains identical values.
   checkKeyedHistogram(search_hist, "other-MozSearch.newtab", 1);
 
   // Also check events.
   let events = Services.telemetry.snapshotBuiltinEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false);
   events = (events.parent || []).filter(e => e[1] == "navigation" && e[2] == "search");
   checkEvents(events, [["navigation", "search", "about_newtab", "enter", {engine: "other-MozSearch"}]]);
 
+  Services.prefs.clearUserPref("browser.newtabpage.activity-stream.enabled");
+
   await BrowserTestUtils.removeTab(tab);
 });
+
+add_task(async function test_about_newtab_activitystream() {
+  // Test activitystream search event.
+  const ACTIVITY_STREAM_ENABLED = Services.prefs.getBoolPref("browser.newtabpage.activity-stream.enabled");
+  if (ACTIVITY_STREAM_ENABLED === false) {
+    Services.prefs.setBoolPref("browser.newtabpage.activity-stream.enabled", true);
+  }
+  // Let's reset the counts.
+  Services.telemetry.clearScalars();
+  Services.telemetry.clearEvents();
+  let search_hist = getSearchCountsHistogram();
+
+  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:newtab", false);
+  // browser.newtab.preload preloads a new tab before pref change actually happens.
+  // We need to throw away the first tab we open because it will not be up to date.
+  await BrowserTestUtils.removeTab(tab);
+  tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:newtab", false);
+  await ContentTask.spawn(tab.linkedBrowser, null, async function() {
+    await ContentTaskUtils.waitForCondition(() => !content.document.hidden);
+  });
+
+  info("Trigger a simple serch, just text + enter.");
+  let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+  await typeInSearchField(tab.linkedBrowser, "test query", "newtab-search-text");
+  await BrowserTestUtils.synthesizeKey("VK_RETURN", {}, tab.linkedBrowser);
+  await p;
+
+  // Check if the scalars contain the expected values.
+  const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, false);
+  checkKeyedScalar(scalars, SCALAR_ABOUT_ACTIVITYSTREAM, "search_enter", 1);
+  Assert.equal(Object.keys(scalars[SCALAR_ABOUT_ACTIVITYSTREAM]).length, 1,
+    "This search must only increment one entry in the scalar.");
+
+  // Make sure SEARCH_COUNTS contains identical values.
+  checkKeyedHistogram(search_hist, "other-MozSearch.activitystream", 1);
+
+  // Also check events.
+  let events = Services.telemetry.snapshotBuiltinEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false);
+  events = (events.parent || []).filter(e => e[1] == "navigation" && e[2] == "search");
+  checkEvents(events, [["navigation", "search", "activitystream", "enter", {engine: "other-MozSearch"}]]);
+
+  Services.prefs.clearUserPref("browser.newtabpage.activity-stream.enabled");
+
+  await BrowserTestUtils.removeTab(tab);
+});
--- a/toolkit/components/telemetry/Events.yaml
+++ b/toolkit/components/telemetry/Events.yaml
@@ -1,12 +1,12 @@
 navigation:
   search:
     objects: ["about_home", "about_newtab", "contextmenu", "oneoff",
-              "suggestion", "alias", "enter", "searchbar", "urlbar"]
+              "suggestion", "alias", "enter", "searchbar", "urlbar", "activitystream"]
     release_channel_collection: opt-out
     record_in_processes: ["main"]
     description: >
       This is recorded on each search navigation.
       The value field records the action used to trigger the search:
         "enter", "oneoff", "suggestion", "alias", null (for contextmenu)
     bug_numbers: [1316281]
     notification_emails:
--- a/toolkit/components/telemetry/Scalars.yaml
+++ b/toolkit/components/telemetry/Scalars.yaml
@@ -243,16 +243,30 @@ browser.engagement.navigation:
     kind: uint
     keyed: true
     notification_emails:
       - bcolloran@mozilla.com
     release_channel_collection: opt-out
     record_in_processes:
       - 'main'
 
+  activitystream:
+    bug_numbers:
+      - 1381460
+    description: >
+      Count search events originating from Activity Stream. This is currently only tracking simple searches and saving them in the 'search_enter' key.
+    expires: never
+    kind: uint
+    keyed: true
+    notification_emails:
+      - aoprea@mozilla.com
+    release_channel_collection: opt-out
+    record_in_processes:
+      - 'main'
+
 # The following section contains the browser usage scalars.
 browser.usage:
   graphite:
     bug_numbers:
       - 1331915
     description: >
       The number of times a graphite2 font has been loaded.
     expires: "60"