Bug 1542334 - Add telemetry for FxA app menu r=eoger,janerik
authorVijay Budhram <vbudhram@mozilla.com>
Tue, 30 Apr 2019 19:47:36 +0000
changeset 472062 47937619427b65ded176932cf951cbf21ec7ee8a
parent 472061 e34d54ab62b4e52aebcbed7456d67d0c5d9f0f9c
child 472063 23b9b8480e0a88f06efd2a148bb01bf839bf4750
push id35946
push userapavel@mozilla.com
push dateWed, 01 May 2019 15:54:31 +0000
treeherdermozilla-central@a027a998b8b7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerseoger, janerik
bugs1542334
milestone68.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 1542334 - Add telemetry for FxA app menu r=eoger,janerik Differential Revision: https://phabricator.services.mozilla.com/D28347
browser/base/content/browser-sync.js
browser/base/content/browser.js
browser/components/customizableui/content/panelUI.inc.xul
toolkit/components/telemetry/Events.yaml
--- a/browser/base/content/browser-sync.js
+++ b/browser/base/content/browser-sync.js
@@ -211,16 +211,31 @@ var gSync = {
   },
 
   showSendToDeviceView(anchor) {
     PanelUI.showSubView("PanelUI-sendTabToDevice", anchor);
     let panelViewNode = document.getElementById("PanelUI-sendTabToDevice");
     this.populateSendTabToDevicesView(panelViewNode, this.populateSendTabToDevicesView.bind(this));
   },
 
+  showSendToDeviceViewFromFxaMenu(anchor) {
+    this.showSendToDeviceView(anchor);
+    this.emitFxaToolbarTelemetry("send_tab", anchor);
+  },
+
+  showRemoteTabsFromFxaMenu(panel) {
+    PanelUI.showSubView("PanelUI-remotetabs", panel);
+    this.emitFxaToolbarTelemetry("sync_tabs", panel);
+  },
+
+  showSidebarFromFxaMenu(panel) {
+    SidebarUI.toggle("viewTabsSidebar");
+    this.emitFxaToolbarTelemetry("sync_tabs_sidebar", panel);
+  },
+
   populateSendTabToDevicesView(panelViewNode, reloadFunc) {
     let bodyNode = panelViewNode.querySelector(".panel-subview-body");
     let panelNode = panelViewNode.closest("panel");
     let browser = gBrowser.selectedBrowser;
     let url = browser.currentURI.spec;
     let title = browser.contentTitle;
     let multiselected = gBrowser.selectedTab.multiselected;
 
@@ -289,17 +304,17 @@ var gSync = {
     }
 
     this.enableSendTabIfValidTab();
 
     const anchor = document.getElementById("fxa-toolbar-menu-button");
     if (anchor.getAttribute("open") == "true") {
       PanelUI.hide();
     } else {
-      this.emitFxaToolbarTelemetry("toolbar_icon");
+      this.emitFxaToolbarTelemetry("toolbar_icon", anchor);
       PanelUI.showSubView(viewId, anchor, aEvent);
     }
   },
 
   updateFxAPanel(state = {}) {
     const mainWindowEl = document.documentElement;
 
     // The Firefox Account toolbar currently handles 3 different states for
@@ -350,28 +365,41 @@ var gSync = {
 
     if (canSendAllURIs) {
       document.getElementById("PanelUI-fxa-menu-sendtab-button").removeAttribute("disabled");
     } else {
       document.getElementById("PanelUI-fxa-menu-sendtab-button").setAttribute("disabled", true);
     }
   },
 
-  emitFxaToolbarTelemetry(type) {
-    if (!gFxaToolbarEnabled) {
-      return;
-    }
-    if (UIState.isReady()) {
+  emitFxaToolbarTelemetry(type, panel) {
+    if (UIState.isReady() && panel) {
       const state = UIState.get();
       const hasAvatar = state.avatarURL && !state.avatarURL.includes(FXA_NO_AVATAR_ZEROS);
       let extraOptions = {"fxa_status": state.status, "fxa_avatar": hasAvatar ? "true" : "false"};
-      Services.telemetry.recordEvent("fxa_avatar_menu", "click", type, null, extraOptions);
+
+      // When the fxa avatar panel is within the Firefox app menu,
+      // we emit different telemetry.
+      let eventName = "fxa_avatar_menu";
+      if (this.isPanelInsideAppMenu(panel)) {
+        eventName = "fxa_app_menu";
+      }
+
+      Services.telemetry.recordEvent(eventName, "click", type, null, extraOptions);
     }
   },
 
+  isPanelInsideAppMenu(panel = undefined) {
+    const appMenuPanel = document.getElementById("appMenu-popup");
+    if (panel && appMenuPanel.contains(panel)) {
+      return true;
+    }
+    return false;
+  },
+
   updatePanelPopup(state) {
     let defaultLabel = this.appMenuStatus.getAttribute("defaultlabel");
     const status = state.status;
     // Reset the status bar to its original state.
     this.appMenuLabel.setAttribute("label", defaultLabel);
     this.appMenuContainer.removeAttribute("fxastatus");
     this.appMenuAvatar.style.removeProperty("list-style-image");
     this.appMenuLabel.classList.remove("subviewbutton-nav");
@@ -442,16 +470,17 @@ var gSync = {
       state.syncing ? this.onActivityStart() : this.onActivityStop();
     }
   },
 
   onMenuPanelCommand() {
     switch (this.appMenuContainer.getAttribute("fxastatus")) {
     case "signedin":
       const panel = document.getElementById("appMenu-fxa-status");
+      this.emitFxaToolbarTelemetry("toolbar_icon", panel);
       PanelUI.showSubView("PanelUI-fxa", panel);
       break;
     case "error":
       if (this.appMenuContainer.getAttribute("fxastatus") == "unverified") {
         this.openPrefs("menupanel", "fxaError");
       } else {
         this.openSignInAgainPage("menupanel");
       }
@@ -480,32 +509,59 @@ var gSync = {
     });
   },
 
   async openConnectAnotherDevice(entryPoint) {
     const url = await FxAccounts.config.promiseConnectDeviceURI(entryPoint);
     openTrustedLinkIn(url, "tab");
   },
 
+  async openConnectAnotherDeviceFromFxaMenu(panel = undefined) {
+    this.emitFxaToolbarTelemetry("cad", panel);
+    let entryPoint = "fxa_discoverability_native";
+    if (this.isPanelInsideAppMenu(panel)) {
+      entryPoint = "fxa_app_menu";
+    }
+    this.openConnectAnotherDevice(entryPoint);
+  },
+
   openSendToDevicePromo() {
     let url = this.PRODUCT_INFO_BASE_URL;
     url += "send-tabs/?utm_source=" + Services.appinfo.name.toLowerCase();
     switchToTabHavingURI(url, true, { replaceQueryString: true });
   },
 
   async openFxAEmailFirstPage(entryPoint) {
     const url = await FxAccounts.config.promiseEmailFirstURI(entryPoint);
     switchToTabHavingURI(url, true, { replaceQueryString: true });
   },
 
+  async openFxAEmailFirstPageFromFxaMenu(panel = undefined) {
+    this.emitFxaToolbarTelemetry("login", panel);
+    let entryPoint = "fxa_discoverability_native";
+    if (this.isPanelInsideAppMenu(panel)) {
+        entryPoint = "fxa_app_menu";
+    }
+    this.openFxAEmailFirstPage(entryPoint);
+  },
+
   async openFxAManagePage(entryPoint) {
     const url = await FxAccounts.config.promiseManageURI(entryPoint);
     switchToTabHavingURI(url, true, { replaceQueryString: true });
   },
 
+  async openFxAManagePageFromFxaMenu(panel = undefined) {
+    this.emitFxaToolbarTelemetry("account_settings", panel);
+    let entryPoint = "fxa_discoverability_native";
+    if (this.isPanelInsideAppMenu(panel)) {
+        entryPoint = "fxa_app_menu";
+    }
+    this.openFxAManagePage(entryPoint);
+  },
+
   async sendTabToDevice(url, targets, title) {
     const fxaCommandsDevices = [];
     const oldSendTabClients = [];
     for (const target of targets) {
       if (fxAccounts.commands.sendTab.isDeviceCompatible(target)) {
         fxaCommandsDevices.push(target);
       } else if (target.clientRecord) {
         oldSendTabClients.push(target.clientRecord);
@@ -842,20 +898,34 @@ var gSync = {
         fxAccounts.commands.pollDeviceCommands().catch(e => {
           console.error("Fetching missed remote commands failed.", e);
         });
         Weave.Service.sync();
       });
     }
   },
 
+  doSyncFromFxaMenu(panel) {
+    this.doSync();
+    this.emitFxaToolbarTelemetry("sync_now", panel);
+  },
+
   openPrefs(entryPoint = "syncbutton", origin = undefined) {
     window.openPreferences("paneSync", { origin, urlParams: { entrypoint: entryPoint } });
   },
 
+  openPrefsFromFxaMenu(type, panel) {
+    this.emitFxaToolbarTelemetry(type, panel);
+    let entryPoint = "fxa_discoverability_native";
+    if (this.isPanelInsideAppMenu(panel)) {
+      entryPoint = "fxa_app_menu";
+    }
+    this.openPrefs(entryPoint);
+  },
+
   openSyncedTabsPanel() {
     let placement = CustomizableUI.getPlacementOfWidget("sync-button");
     let area = placement && placement.area;
     let anchor = document.getElementById("sync-button") ||
                  document.getElementById("PanelUI-menu-button");
     if (area == CustomizableUI.AREA_FIXED_OVERFLOW_PANEL) {
       // The button is in the overflow panel, so we need to show the panel,
       // then show our subview.
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -489,25 +489,26 @@ function showFxaToolbarMenu(enable) {
   // if sync is enabled.
   const syncEnabled = Services.prefs.getBoolPref("identity.fxaccounts.enabled", false);
   const mainWindowEl = document.documentElement;
   const fxaPanelEl = document.getElementById("PanelUI-fxa");
 
   mainWindowEl.setAttribute("fxastatus", "not_configured");
   fxaPanelEl.addEventListener("ViewShowing", gSync.updateSendToDeviceTitle);
 
+  Services.telemetry.setEventRecordingEnabled("fxa_app_menu", true);
+
   if (enable && syncEnabled) {
     mainWindowEl.setAttribute("fxatoolbarmenu", "visible");
 
     // We have to manually update the sync state UI when toggling the FxA toolbar
     // because it could show an invalid icon if the user is logged in and no sync
     // event was performed yet.
     gSync.maybeUpdateUIState();
 
-    // Enabled FxA toolbar telemetry
     Services.telemetry.setEventRecordingEnabled("fxa_avatar_menu", true);
 
     // We set an attribute here so that we can toggle the custom
     // badge depending on whether the FxA menu was ever accessed.
     if (!gFxaToolbarAccessed) {
       mainWindowEl.setAttribute("fxa_avatar_badged", "badged");
     } else {
       mainWindowEl.removeAttribute("fxa_avatar_badged");
--- a/browser/components/customizableui/content/panelUI.inc.xul
+++ b/browser/components/customizableui/content/panelUI.inc.xul
@@ -688,66 +688,66 @@
     <panelview id="PanelUI-fxa" class="PanelUI-subView" descriptionheightworkaround="true">
       <vbox class="panel-subview-body">
         <vbox id="PanelUI-fxa-signin">
           <image class="fxaChooseWhatToSyncDevices"/>
           <label class="PanelUI-fxa-signin-instruction-callout">&fxa.signin.callout.label;</label>
           <label class="PanelUI-fxa-signin-instruction-label">&fxa.signin.description.label;</label>
           <toolbarbutton class="PanelUI-fxa-signin-button"
                          label="&fxa.signin.button.label;"
-                         oncommand="gSync.openFxAEmailFirstPage('fxa_discoverability_native'); gSync.emitFxaToolbarTelemetry('login');"/>
+                         oncommand="gSync.openFxAEmailFirstPageFromFxaMenu(this);"/>
         </vbox>
         <vbox id="PanelUI-fxa-unverified" class="PanelUI-fxa-unverified-instruction-box">
           <image class="fxaGraphicMail"/>
           <label class="PanelUI-fxa-signin-instruction-callout">&fxa.unverified.callout.label;</label>
           <label class="PanelUI-fxa-signin-instruction-label">&fxa.unverified.description.label;</label>
           <toolbarbutton class="PanelUI-fxa-signin-button"
                          label="&fxa.unverified.button.label;"
-                         oncommand="gSync.openPrefs('fxa_discoverability_native'); gSync.emitFxaToolbarTelemetry('unver_sync_settings');"/>
+                         oncommand="gSync.openPrefsFromFxaMenu('unver_sync_settings', this);"/>
         </vbox>
         <vbox id="PanelUI-fxa-menu">
           <hbox flex="1" align="center" class="fxa-avatar-subpanel">
             <image role="presentation" id="fxa-menu-avatar"/>
             <vbox flex="1">
               <label class="fxa-avatar-subpanel-description" >&fxa.menu.signedInAs.label;</label>
               <label id="fxa-menu-email"></label>
             </vbox>
           </hbox>
           <toolbarseparator/>
           <toolbarbutton id="PanelUI-fxa-menu-sendtab-button"
                          class="subviewbutton subviewbutton-iconic subviewbutton-nav"
                          closemenu="none"
-                         oncommand="gSync.showSendToDeviceView(this); gSync.emitFxaToolbarTelemetry('send_tab');"/>
+                         oncommand="gSync.showSendToDeviceViewFromFxaMenu(this);"/>
           <toolbarbutton id="PanelUI-fxa-menu-remotetabs-button"
                          class="subviewbutton subviewbutton-iconic subviewbutton-nav"
                          label="&appMenuRemoteTabs.label;"
                          closemenu="none"
-                         oncommand="PanelUI.showSubView('PanelUI-remotetabs', this); gSync.emitFxaToolbarTelemetry('sync_tabs');"/>
+                         oncommand="gSync.showRemoteTabsFromFxaMenu(this);"/>
           <toolbarbutton id="PanelUI-fxa-menu-view-sidebar"
                          class="subviewbutton subviewbutton-iconic"
                          label="&appMenuRemoteTabs.sidebar.label;"
-                         oncommand="SidebarUI.toggle('viewTabsSidebar'); gSync.emitFxaToolbarTelemetry('sync_tabs_sidebar');">
+                         oncommand="gSync.showSidebarFromFxaMenu(this);">
             <observes element="sidebar-box" attribute="positionend"/>
           </toolbarbutton>
           <toolbarseparator/>
           <toolbarbutton class="subviewbutton"
                          label="&fxa.menu.connectAnotherDevice2.label;"
-                         oncommand="gSync.openConnectAnotherDevice('fxa_discoverability_native'); gSync.emitFxaToolbarTelemetry('cad');"/>
+                         oncommand="gSync.openConnectAnotherDeviceFromFxaMenu(this);"/>
           <toolbarbutton class="subviewbutton"
                          label="&fxa.menu.manageAccount.label;"
-                         oncommand="gSync.openFxAManagePage('fxa_discoverability_native'); gSync.emitFxaToolbarTelemetry('account_settings');"/>
+                         oncommand="gSync.openFxAManagePageFromFxaMenu(this);"/>
           <toolbarbutton class="subviewbutton"
                          label="&fxa.menu.syncSettings.label;"
-                         oncommand="gSync.openPrefs('fxa_discoverability_native'); gSync.emitFxaToolbarTelemetry('sync_settings');"/>
+                         oncommand="gSync.openPrefsFromFxaMenu('sync_settings', this);"/>
           <toolbarseparator/>
           <toolbarbutton id="PanelUI-fxa-menu-syncnow-button"
                          label="&syncSyncNowItem.label;"
                          syncinglabel="&syncSyncNowItemSyncing.label;"
                          class="subviewbutton subviewbutton-iconic"
-                         oncommand="gSync.doSync(); gSync.emitFxaToolbarTelemetry('sync_now');"
+                         oncommand="gSync.doSyncFromFxaMenu(this);"
                          closemenu="none"/>
         </vbox>
       </vbox>
     </panelview>
     <!-- This panelview is used to contain the dynamically created buttons for send tab to devices -->
     <panelview id="PanelUI-sendTabToDevice" flex="1" class="PanelUI-subView">
       <vbox class="panel-subview-body">
         <toolbarbutton id="PanelUI-sendTabToDevice-syncingDevices" class="subviewbutton subviewbutton-iconic pageAction-sendToDevice-notReady"
--- a/toolkit/components/telemetry/Events.yaml
+++ b/toolkit/components/telemetry/Events.yaml
@@ -362,16 +362,41 @@ fxa_avatar_menu:
     notification_emails: ["vbudhram@mozilla.com", "loines@mozilla.com"]
     expiry_version: "71"
     extra_keys:
       fxa_status: >
         The current state of the user. Possible states are "not_configured", "unverified",
         "signedin" and "login_failed".
       fxa_avatar: Boolean for whether or not account has set an avatar
 
+fxa_app_menu:
+  click:
+    objects: [
+      "account_settings",
+      "cad",
+      "send_tab",
+      "sync_now",
+      "sync_settings",
+      "sync_tabs",
+      "sync_tabs_sidebar",
+      "toolbar_icon"
+      ]
+    methods: ["click"]
+    release_channel_collection: opt-out
+    record_in_processes: ["main"]
+    description: This is recorded on interactions with the FxA menu in the app (hamburger) menu
+    bug_numbers: [1542334]
+    notification_emails: ["vbudhram@mozilla.com", "loines@mozilla.com"]
+    expiry_version: "73"
+    extra_keys:
+      fxa_status: >
+        The current state of the user. Possible states are "not_configured", "unverified",
+        "signedin" and "login_failed".
+      fxa_avatar: Boolean for whether or not account has set an avatar
+
 # This category contains event entries used for Telemetry tests.
 # They will not be sent out with any pings.
 telemetry.test:
   test:
     methods: ["test1", "test2"]
     objects: ["object1", "object2"]
     bug_numbers: [1286606]
     notification_emails: ["telemetry-client-dev@mozilla.com"]