Commit 95539042 authored by Sarah Clements's avatar Sarah Clements
Browse files

Bug 1819081 - Add telemetry to bookmarks sidebar and library r=mak

* Add histograms for cumulative searches and utilize scalars added in bug 1815906
* Add test coverage

Differential Revision: https://phabricator.services.mozilla.com/D172596
parent 8eccde29
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ XPCOMUtils.defineLazyScriptGetter(
  "chrome://browser/content/places/controller.js"
);
/* End Shared Places Import */
var gCumulativeSearches = 0;

function init() {
  let uidensity = window.top.document.documentElement.getAttribute("uidensity");
@@ -43,10 +44,35 @@ function searchBookmarks(aSearchString) {
    // eslint-disable-next-line no-self-assign
    tree.place = tree.place;
  } else {
    Services.telemetry.keyedScalarAdd("sidebar.search", "bookmarks", 1);
    gCumulativeSearches++;
    tree.applyFilter(aSearchString, PlacesUtils.bookmarks.userContentRoots);
  }
}

function updateTelemetry(urlsOpened = []) {
  let searchesHistogram = Services.telemetry.getHistogramById(
    "PLACES_BOOKMARKS_SEARCHBAR_CUMULATIVE_SEARCHES"
  );
  searchesHistogram.add(gCumulativeSearches);
  clearCumulativeCounter();

  Services.telemetry.keyedScalarAdd(
    "sidebar.link",
    "bookmarks",
    urlsOpened.length
  );
}

function clearCumulativeCounter() {
  gCumulativeSearches = 0;
}

function unloadBookmarksSidebar() {
  clearCumulativeCounter();
  PlacesUIUtils.setMouseoverURL("", window);
}

window.addEventListener("SidebarFocused", () =>
  document.getElementById("search-box").focus()
);
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@
        xmlns:html="http://www.w3.org/1999/xhtml"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        onload="init();"
        onunload="PlacesUIUtils.setMouseoverURL('', window);"
        onunload="unloadBookmarksSidebar();"
        data-l10n-id="bookmarks-sidebar-content">

  <script src="chrome://browser/content/places/bookmarksSidebar.js"/>
+0 −2
Original line number Diff line number Diff line
@@ -34,8 +34,6 @@ var gCumulativeSearches = 0;
var gCumulativeFilterCount = 0;

function HistorySidebarInit() {
  Services.telemetry.keyedScalarAdd("sidebar.opened", "history", 1);

  let uidensity = window.top.document.documentElement.getAttribute("uidensity");
  if (uidensity) {
    document.documentElement.setAttribute("uidensity", uidensity);
+22 −11
Original line number Diff line number Diff line
@@ -183,6 +183,8 @@ var PlacesOrganizer = {
        this._places.selectNode(historyNode.getChild(0));
      }
      Services.telemetry.keyedScalarAdd("library.opened", "history", 1);
    } else {
      Services.telemetry.keyedScalarAdd("library.opened", "bookmarks", 1);
    }

    // clear the back-stack
@@ -825,13 +827,8 @@ var PlacesSearchBox = {
    return document.getElementById("searchFilter");
  },

  _cumulativeLibraryHistorySearchCount: 0,
  get cumulativeSearchCount() {
    return this._cumulativeLibraryHistorySearchCount;
  },
  set cumulativeSearchCount(cumulativeSearches) {
    this._cumulativeLibraryHistorySearchCount = cumulativeSearches;
  },
  cumulativeHistorySearches: 0,
  cumulativeBookmarkSearches: 0,

  /**
   * Folders to include when searching.
@@ -873,6 +870,8 @@ var PlacesSearchBox = {
    switch (PlacesSearchBox.filterCollection) {
      case "bookmarks":
        currentView.applyFilter(filterString, this.folders);
        Services.telemetry.keyedScalarAdd("library.search", "bookmarks", 1);
        this.cumulativeBookmarkSearches++;
        break;
      case "history": {
        let currentOptions = PO.getCurrentOptions();
@@ -893,7 +892,7 @@ var PlacesSearchBox = {
          currentView.applyFilter(filterString, null, true);
          TelemetryStopwatch.finish(HISTORY_LIBRARY_SEARCH_TELEMETRY);
          Services.telemetry.keyedScalarAdd("library.search", "history", 1);
          this._cumulativeLibraryHistorySearchCount++;
          this.cumulativeHistorySearches++;
        }
        break;
      }
@@ -998,7 +997,19 @@ function updateTelemetry(urlsOpened) {
    link => !link.isBookmark && !PlacesUtils.nodeIsBookmark(link)
  );
  if (!historyLinks.length) {
    // TODO (Bug 1819081)
    let searchesHistogram = Services.telemetry.getHistogramById(
      "PLACES_LIBRARY_CUMULATIVE_BOOKMARK_SEARCHES"
    );
    searchesHistogram.add(PlacesSearchBox.cumulativeBookmarkSearches);

    // Clear cumulative search counter
    PlacesSearchBox.cumulativeBookmarkSearches = 0;

    Services.telemetry.keyedScalarAdd(
      "library.link",
      "bookmarks",
      urlsOpened.length
    );
    return;
  }

@@ -1006,10 +1017,10 @@ function updateTelemetry(urlsOpened) {
  let searchesHistogram = Services.telemetry.getHistogramById(
    "PLACES_LIBRARY_CUMULATIVE_HISTORY_SEARCHES"
  );
  searchesHistogram.add(PlacesSearchBox.cumulativeSearchCount);
  searchesHistogram.add(PlacesSearchBox.cumulativeHistorySearches);

  // Clear cumulative search counter
  PlacesSearchBox.cumulativeSearchCount = 0;
  PlacesSearchBox.cumulativeHistorySearches = 0;

  Services.telemetry.keyedScalarAdd(
    "library.link",
+2 −1
Original line number Diff line number Diff line
@@ -95,7 +95,6 @@ skip-if = verify && debug && os == 'win'
[browser_library_delete_bookmarks_in_tags.js]
[browser_library_delete_tags.js]
[browser_library_downloads.js]
[browser_library_history_telemetry.js]
[browser_library_left_pane_middleclick.js]
[browser_library_left_pane_select_hierarchy.js]
[browser_library_middleclick.js]
@@ -107,6 +106,7 @@ skip-if = verify && debug && os == 'win'
[browser_library_open_leak.js]
[browser_library_panel_leak.js]
[browser_library_search.js]
[browser_library_telemetry.js]
[browser_library_tree_leak.js]
[browser_library_views_liveupdate.js]
[browser_library_warnOnOpen.js]
@@ -117,6 +117,7 @@ skip-if = verify && debug && os == 'win'
[browser_paste_resets_cut_highlights.js]
[browser_remove_bookmarks.js]
[browser_sidebar_history_telemetry.js]
[browser_sidebar_bookmarks_telemetry.js]
[browser_sidebar_open_bookmarks.js]
[browser_sidebarpanels_click.js]
[browser_sort_in_library.js]
Loading