Bug 1036581 add telemetry probes to social buttons and sidebar, r=dolske
authorShane Caraveo <scaraveo@mozilla.com>
Wed, 16 Jul 2014 19:15:02 -0700
changeset 216520 6c0b6745b7dc13cb06764b02efcca3e82bb995ee
parent 216519 ec7f2245280cc062085966e138f67ba4342e2b7b
child 216521 427b0299698bb114113be30a8f2d332755abb01c
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske
bugs1036581
milestone33.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 1036581 add telemetry probes to social buttons and sidebar, r=dolske
browser/base/content/browser-social.js
browser/base/content/socialmarks.xml
toolkit/components/telemetry/Histograms.json
--- a/browser/base/content/browser-social.js
+++ b/browser/base/content/browser-social.js
@@ -573,22 +573,28 @@ SocialShare = {
       cmd.setAttribute("disabled", "true");
       shareButton.setAttribute("disabled", "true");
     } else {
       cmd.removeAttribute("disabled");
       shareButton.removeAttribute("disabled");
     }
   },
 
+  _onclick: function() {
+    Services.telemetry.getHistogramById("SOCIAL_PANEL_CLICKS").add(0);
+  },
+  
   onShowing: function() {
     this.anchor.setAttribute("open", "true");
+    this.iframe.addEventListener("click", this._onclick, true);
   },
 
   onHidden: function() {
     this.anchor.removeAttribute("open");
+    this.iframe.removeEventListener("click", this._onclick, true);
     this.iframe.setAttribute("src", "data:text/plain;charset=utf8,");
     this.currentShare = null;
   },
 
   setErrorMessage: function() {
     let iframe = this.iframe;
     if (!iframe)
       return;
@@ -699,20 +705,23 @@ SocialShare = {
     // always ensure that origin belongs to the endpoint
     let uri = Services.io.newURI(shareEndpoint, null, null);
     iframe.setAttribute("origin", provider.origin);
     iframe.setAttribute("src", shareEndpoint);
 
     let anchor = document.getAnonymousElementByAttribute(this.anchor, "class", "toolbarbutton-icon");
     this.panel.openPopup(anchor, "bottomcenter topright", 0, 0, false, false);
     Social.setErrorListener(iframe, this.setErrorMessage.bind(this));
+    Services.telemetry.getHistogramById("SOCIAL_TOOLBAR_BUTTONS").add(0);
   }
 };
 
 SocialSidebar = {
+  _openStartTime: 0,
+
   // Whether the sidebar can be shown for this window.
   get canShow() {
     if (!SocialUI.enabled || document.mozFullScreen)
       return false;
     return Social.providers.some(p => p.sidebarURL);
   },
 
   // Whether the user has toggled the sidebar on (for windows where it can appear)
@@ -775,16 +784,21 @@ SocialSidebar = {
 
   saveWindowState: function() {
     let broadcaster = document.getElementById("socialSidebarBroadcaster");
     let sidebarOrigin = document.getElementById("social-sidebar-browser").getAttribute("origin");
     let data = {
       "hidden": broadcaster.hidden,
       "origin": sidebarOrigin
     };
+    if (broadcaster.hidden) {
+      Services.telemetry.getHistogramById("SOCIAL_SIDEBAR_OPEN_DURATION").add(Date.now()  / 1000 - this._openStartTime);
+    } else {
+      this._openStartTime = Date.now() / 1000;
+    }
 
     // Save a global state for users who do not restore state.
     if (broadcaster.hidden)
       Services.prefs.clearUserPref("social.sidebar.provider");
     else
       Services.prefs.setCharPref("social.sidebar.provider", sidebarOrigin);
 
     try {
@@ -872,28 +886,34 @@ SocialSidebar = {
         sbrowser.addEventListener("load", SocialSidebar._loadListener, true);
       } else {
         this.setSidebarVisibilityState(true);
       }
     }
     this._updateCheckedMenuItems(this.opened && this.provider ? this.provider.origin : null);
   },
 
+  _onclick: function() {
+    Services.telemetry.getHistogramById("SOCIAL_PANEL_CLICKS").add(3);
+  },
+
   _loadListener: function SocialSidebar_loadListener() {
     let sbrowser = document.getElementById("social-sidebar-browser");
     sbrowser.removeEventListener("load", SocialSidebar._loadListener, true);
     document.getElementById("social-sidebar-button").removeAttribute("loading");
     SocialSidebar.setSidebarVisibilityState(true);
+    sbrowser.addEventListener("click", SocialSidebar._onclick, true);
   },
 
   unloadSidebar: function SocialSidebar_unloadSidebar() {
     let sbrowser = document.getElementById("social-sidebar-browser");
     if (!sbrowser.hasAttribute("origin"))
       return;
 
+    sbrowser.removeEventListener("click", SocialSidebar._onclick, true);
     sbrowser.stop();
     sbrowser.removeAttribute("origin");
     sbrowser.setAttribute("src", "about:blank");
     // We need to explicitly create a new content viewer because the old one
     // doesn't get destroyed until about:blank has loaded (which does not happen
     // as long as the element is hidden).
     sbrowser.docShell.createAboutBlankContentViewer(null);
     SocialFlyout.unload();
@@ -984,25 +1004,27 @@ SocialSidebar = {
     // always show the sidebar, and set the provider
     let broadcaster = document.getElementById("socialSidebarBroadcaster");
     broadcaster.hidden = false;
     if (origin)
       this.provider = Social._getProviderFromOrigin(origin);
     else
       SocialSidebar.update();
     this.saveWindowState();
+    Services.telemetry.getHistogramById("SOCIAL_SIDEBAR_STATE").add(true);
   },
 
   hide: function() {
     let broadcaster = document.getElementById("socialSidebarBroadcaster");
     broadcaster.hidden = true;
     this._updateCheckedMenuItems();
     this.clearProviderMenus();
     SocialSidebar.update();
     this.saveWindowState();
+    Services.telemetry.getHistogramById("SOCIAL_SIDEBAR_STATE").add(false);
   },
 
   toggleSidebar: function SocialSidebar_toggle() {
     let broadcaster = document.getElementById("socialSidebarBroadcaster");
     if (broadcaster.hidden)
       this.show();
     else
       this.hide();
@@ -1214,23 +1236,39 @@ SocialStatus = {
       // if there is a badge value, we must use a localizable string to insert it.
       if (badge)
         ariaLabel = gNavigatorBundle.getFormattedString("social.aria.toolbarButtonBadgeText",
                                                         [ariaLabel, badge]);
       button.setAttribute("aria-label", ariaLabel);
     }
   },
 
+  _onclose: function() {
+    let notificationFrameId = "social-status-" + origin;
+    let frame = document.getElementById(notificationFrameId);
+    frame.removeEventListener("close", this._onclose, true);
+    frame.removeEventListener("click", this._onclick, true);
+  },
+
+  _onclick: function() {
+    Services.telemetry.getHistogramById("SOCIAL_PANEL_CLICKS").add(1);
+  },
+
   showPopup: function(aToolbarButton) {
     // attach our notification panel if necessary
     let origin = aToolbarButton.getAttribute("origin");
     let provider = Social._getProviderFromOrigin(origin);
 
     PanelFrame.showPopup(window, PanelUI, aToolbarButton, "social", origin,
-                         provider.statusURL, provider.getPageSize("status"));
+                         provider.statusURL, provider.getPageSize("status"),
+                         (frame) => {
+                          frame.addEventListener("close", this._onclose, true);
+                          frame.addEventListener("click", this._onclick, true);
+                        });
+    Services.telemetry.getHistogramById("SOCIAL_TOOLBAR_BUTTONS").add(1);
   },
 
   setPanelErrorMessage: function(aNotificationFrame) {
     if (!aNotificationFrame)
       return;
 
     let src = aNotificationFrame.getAttribute("src");
     aNotificationFrame.removeAttribute("src");
--- a/browser/base/content/socialmarks.xml
+++ b/browser/base/content/socialmarks.xml
@@ -230,16 +230,17 @@
         }
 
         let anchor = document.getAnonymousElementByAttribute(this._anchor, "class", "toolbarbutton-icon");
         // Bug 849216 - open the popup in a setTimeout so we avoid the auto-rollup
         // handling from preventing it being opened in some cases.
         setTimeout(() => {
           panel.openPopup(anchor, "bottomcenter topright", 0, 0, false, false);
         }, 0);
+        Services.telemetry.getHistogramById("SOCIAL_TOOLBAR_BUTTONS").add(2);
         ]]></body>
        </method>
 
       <method name="markCurrentPage">
         <parameter name="aOpenPanel"/>
         <body><![CDATA[
         // we always set the src on click if it has not been set for this tab,
         // but we only want to open the panel if it was previously annotated.
@@ -325,32 +326,37 @@
             if (!uri)
               return;
 
             // we cannot size the image when we apply it via listStyleImage, so
             // use the toolbar image
             this.setAttribute("image", uri.spec);
             }
             break;
+          case "click":
+            Services.telemetry.getHistogramById("SOCIAL_PANEL_CLICKS").add(2);
+            break;
         }
         ]]></body>
       </method>
 
     </implementation>
     <handlers>
       <handler event="popupshowing"><![CDATA[
         this._anchor.setAttribute("open", "true");
+        this.content.addEventListener("click", this);
       ]]></handler>
       <handler event="popupshown"><![CDATA[
         this.onShown();
       ]]></handler>
       <handler event="popuphidden"><![CDATA[
         this.dispatchPanelEvent("socialFrameHide");
         this._anchor.removeAttribute("open");
         this.update();
+        this.content.removeEventListener("click", this);
       ]]></handler>
       <handler event="command"><![CDATA[
         this.markCurrentPage();
       ]]></handler>
     </handlers>
   </binding>
 
 </bindings>
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -4512,21 +4512,16 @@
     "extended_statistics_ok": true,
     "description": "Time (ms) it takes to build the cache of the search service"
   },
   "SOCIAL_ENABLED_ON_SESSION": {
     "expires_in_version": "never",
     "kind": "flag",
     "description": "Social has been enabled at least once on the current session"
   },
-  "SOCIAL_TOGGLED": {
-    "expires_in_version": "never",
-    "kind": "boolean",
-    "description": "Social has been toggled to on or off"
-  },
   "ENABLE_PRIVILEGE_EVER_CALLED": {
     "expires_in_version": "never",
     "kind": "flag",
     "description": "Whether enablePrivilege has ever been called during the current session"
   },
   "READ_SAVED_PING_SUCCESS": {
     "expires_in_version": "never",
     "kind": "boolean",
@@ -6559,10 +6554,34 @@
   },
   "DISPLAY_SCALING_LINUX" : {
     "expires_in_version": "never",
     "kind": "linear",
     "high": "500",
     "n_buckets": "100",
     "description": "Scaling percentage for the display where the first window is opened (Linux only)",
     "cpp_guard": "XP_LINUX"
+  },
+  "SOCIAL_SIDEBAR_STATE": {
+    "expires_in_version": "never",
+    "kind": "boolean",
+    "description": "Social Sidebar state 0: closed, 1: opened.  Toggling between providers will result in a higher opened rate."
+  },
+  "SOCIAL_TOOLBAR_BUTTONS": {
+    "expires_in_version": "never",
+    "kind": "enumerated",
+    "n_values": 3,
+    "description": "Social toolbar button has been used (0:share, 1:status, 2:bookmark)"
+  },
+  "SOCIAL_PANEL_CLICKS": {
+    "expires_in_version": "never",
+    "kind": "enumerated",
+    "n_values": 4,
+    "description": "Social content has been interacted with (0:share, 1:status, 2:bookmark, 3: sidebar)"
+  },
+  "SOCIAL_SIDEBAR_OPEN_DURATION": {
+    "expires_in_version": "never",
+    "kind": "exponential",
+    "high": "10000000",
+    "n_buckets": 10,
+    "description": "Sidebar showing: seconds that the sidebar has been opened"
   }
 }