Bug 1324167 - Create telemetry probes to track which preference categories are opened. r=gijs privacy-review=bsmedberg draft
authorJared Wein <jwein@mozilla.com>
Tue, 20 Dec 2016 16:37:04 -0500
changeset 451695 21bb7559d34ae93abe0cb776b81a2ecb7a929046
parent 451694 416c29514c909042fbad340b597ed9e54f795719
child 540101 d7e6c1e9291ed781a3407adf8e24c8c2c6e09b80
push id39260
push userbmo:jaws@mozilla.com
push dateTue, 20 Dec 2016 21:37:36 +0000
reviewersgijs
bugs1324167
milestone53.0a1
Bug 1324167 - Create telemetry probes to track which preference categories are opened. r=gijs privacy-review=bsmedberg MozReview-Commit-ID: 39UhphnkKkC
browser/components/preferences/in-content/advanced.js
browser/components/preferences/in-content/preferences.js
toolkit/components/telemetry/Histograms.json
--- a/browser/components/preferences/in-content/advanced.js
+++ b/browser/components/preferences/in-content/advanced.js
@@ -114,16 +114,26 @@ var gAdvancedPane = {
    * tab can be persisted between openings of the preferences window.
    */
   tabSelectionChanged: function()
   {
     if (!this._inited)
       return;
     var advancedPrefs = document.getElementById("advancedPrefs");
     var preference = document.getElementById("browser.preferences.advanced.selectedTabIndex");
+
+    // tabSelectionChanged gets called twice due to the selectedIndex being set
+    // by both the selectedItem and selectedPanel callstacks. This guard is used
+    // to prevent double-counting in Telemetry.
+    if (preference.valueFromPreferences != advancedPrefs.selectedIndex) {
+      Services.telemetry
+              .getHistogramById("FX_PREFERENCES_CATEGORY_OPENED")
+              .add(telemetryBucketForCategory("advanced"));
+    }
+
     preference.valueFromPreferences = advancedPrefs.selectedIndex;
   },
 
   // GENERAL TAB
 
   /*
    * Preferences:
    *
--- a/browser/components/preferences/in-content/preferences.js
+++ b/browser/components/preferences/in-content/preferences.js
@@ -118,16 +118,46 @@ function init_dynamic_padding() {
   }
   `;
   let mediaStyle = document.createElementNS('http://www.w3.org/1999/xhtml', 'html:style');
   mediaStyle.setAttribute('type', 'text/css');
   mediaStyle.appendChild(document.createCDATASection(mediaRule));
   document.documentElement.appendChild(mediaStyle);
 }
 
+function telemetryBucketForCategory(category) {
+  switch (category) {
+    case "general":
+    case "search":
+    case "content":
+    case "applications":
+    case "privacy":
+    case "security":
+    case "sync":
+      return category;
+    case "advanced":
+      let advancedPaneTabs = document.getElementById("advancedPrefs");
+      switch (advancedPaneTabs.selectedTab.id) {
+        case "generalTab":
+          return "advancedGeneral";
+        case "dataChoicesTab":
+          return "advancedDataChoices";
+        case "networkTab":
+          return "advancedNetwork";
+        case "updateTab":
+          return "advancedUpdates";
+        case "encryptionTab":
+          return "advancedCerts";
+      }
+      // fall-through for unknown.
+    default:
+      return "unknown";
+  }
+}
+
 function onHashChange() {
   gotoPref();
 }
 
 function gotoPref(aCategory) {
   let categories = document.getElementById("categories");
   const kDefaultCategoryInternalName = categories.firstElementChild.value;
   let hash = document.location.hash;
@@ -146,28 +176,32 @@ function gotoPref(aCategory) {
 
   try {
     init_category_if_required(category);
   } catch (ex) {
     Cu.reportError("Error initializing preference category " + category + ": " + ex);
     throw ex;
   }
 
-  let newHash = internalPrefCategoryNameToFriendlyName(category);
+  let friendlyName = internalPrefCategoryNameToFriendlyName(category);
   if (gLastHash || category != kDefaultCategoryInternalName) {
-    document.location.hash = newHash;
+    document.location.hash = friendlyName;
   }
   // Need to set the gLastHash before setting categories.selectedItem since
   // the categories 'select' event will re-enter the gotoPref codepath.
   gLastHash = category;
   categories.selectedItem = item;
   window.history.replaceState(category, document.title);
   search(category, "data-category");
   let mainContent = document.querySelector(".main-content");
   mainContent.scrollTop = 0;
+
+  Services.telemetry
+          .getHistogramById("FX_PREFERENCES_CATEGORY_OPENED")
+          .add(telemetryBucketForCategory(friendlyName));
 }
 
 function search(aQuery, aAttribute) {
   let elements = document.getElementById("mainPrefPane").children;
   for (let element of elements) {
     let attributeValue = element.getAttribute(aAttribute);
     element.hidden = (attributeValue != aQuery);
   }
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -5245,16 +5245,25 @@
     "bug_numbers": [1276694],
     "alert_emails": ["gijs@mozilla.com"],
     "expires_in_version": "53",
     "keyed": true,
     "kind": "boolean",
     "releaseChannelCollection": "opt-out",
     "description": "Whether the browser we migrated from was the browser with the most recent data. Keyed by that browser's identifier (e.g. 'ie', 'edge', 'safari', etc.)."
   },
+  "FX_PREFERENCES_CATEGORY_OPENED": {
+    "bug_numbers": [1324167],
+    "alert_emails": ["jaws@mozilla.com"],
+    "expires_in_version": "56",
+    "kind": "categorical",
+    "labels": ["unknown", "general", "search", "content", "applications", "privacy", "security", "sync", "advancedGeneral", "advancedDataChoices", "advancedNetwork", "advancedUpdates", "advancedCerts"],
+    "releaseChannelCollection": "opt-out",
+    "description": "Count how often each preference category is opened."
+  },
   "INPUT_EVENT_RESPONSE_MS": {
     "alert_emails": ["perf-telemetry-alerts@mozilla.com"],
     "bug_numbers": [1235908],
     "expires_in_version": "never",
     "kind": "exponential",
     "high": 10000,
     "n_buckets": 50,
     "description": "Time (ms) from the Input event being created to the end of it being handled"