Bug 975570 - Measure with telemetry how many times people interact with about:newtab. r=ttaubert,a=sledru
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Thu, 27 Feb 2014 18:57:05 +0100
changeset 183285 09432c0c759fc7ecb66cd37362a8941e640cf060
parent 183284 8dda3e9072e18eb857b0adb6732f5d5ae842dac5
child 183286 c43a49abc397125dbcd53d21577a4a7fe2a8d14e
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttaubert, sledru
bugs975570
milestone29.0a2
Bug 975570 - Measure with telemetry how many times people interact with about:newtab. r=ttaubert,a=sledru
browser/base/content/newtab/sites.js
toolkit/components/telemetry/Histograms.json
--- a/browser/base/content/newtab/sites.js
+++ b/browser/base/content/newtab/sites.js
@@ -159,44 +159,70 @@ Site.prototype = {
   /**
    * Adds event handlers for the site and its buttons.
    */
   _addEventHandlers: function Site_addEventHandlers() {
     // Register drag-and-drop event handlers.
     this._node.addEventListener("dragstart", this, false);
     this._node.addEventListener("dragend", this, false);
     this._node.addEventListener("mouseover", this, false);
-
-    let controls = this.node.querySelectorAll(".newtab-control");
-    for (let i = 0; i < controls.length; i++)
-      controls[i].addEventListener("click", this, false);
+    this._node.addEventListener("click", this, false);
   },
 
   /**
    * Speculatively opens a connection to the current site.
    */
   _speculativeConnect: function Site_speculativeConnect() {
     let sc = Services.io.QueryInterface(Ci.nsISpeculativeConnect);
     let uri = Services.io.newURI(this.url, null, null);
     sc.speculativeConnect(uri, null);
   },
 
   /**
+   * Record interaction with site using telemetry.
+   */
+  _recordSiteClicked: function Site_recordSiteClicked(aIndex) {
+    if (Services.prefs.prefHasUserValue("browser.newtabpage.rows") ||
+        Services.prefs.prefHasUserValue("browser.newtabpage.columns") ||
+        aIndex > 8) {
+      // We only want to get indices for the default configuration, everything
+      // else goes in the same bucket.
+      aIndex = 9;
+    }
+    Services.telemetry.getHistogramById("NEWTAB_PAGE_SITE_CLICKED")
+                      .add(aIndex);
+  },
+
+  /**
+   * Handles site click events.
+   */
+  _onClick: function Site_onClick(aEvent) {
+    let target = aEvent.target;
+    if (target.classList.contains("newtab-link") ||
+        target.parentElement.classList.contains("newtab-link")) {
+      this._recordSiteClicked(this.cell.index);
+      return;
+    }
+
+    aEvent.preventDefault();
+    if (aEvent.target.classList.contains("newtab-control-block"))
+      this.block();
+    else if (this.isPinned())
+      this.unpin();
+    else
+      this.pin();
+  },
+
+  /**
    * Handles all site events.
    */
   handleEvent: function Site_handleEvent(aEvent) {
     switch (aEvent.type) {
       case "click":
-        aEvent.preventDefault();
-        if (aEvent.target.classList.contains("newtab-control-block"))
-          this.block();
-        else if (this.isPinned())
-          this.unpin();
-        else
-          this.pin();
+        this._onClick(aEvent);
         break;
       case "mouseover":
         this._node.removeEventListener("mouseover", this, false);
         this._speculativeConnect();
         break;
       case "dragstart":
         gDrag.start(this, aEvent);
         break;
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -4014,16 +4014,22 @@
     "extended_statistics_ok": true,
     "description": "Number of sites blocked from the new tab page."
   },
   "NEWTAB_PAGE_SHOWN": {
     "expires_in_version": "35",
     "kind": "boolean",
     "description": "Number of times about:newtab was shown from opening a new tab or window."
   },
+  "NEWTAB_PAGE_SITE_CLICKED": {
+    "expires_in_version": "35",
+    "kind": "enumerated",
+    "n_values": 10,
+    "description": "Track click count on about:newtab tiles per index (0-8). For non-default row or column configurations all clicks into the '9' bucket."
+  },
   "PANORAMA_INITIALIZATION_TIME_MS": {
     "expires_in_version": "never",
     "kind": "exponential",
     "high": "10000",
     "n_buckets": 15,
     "extended_statistics_ok": true,
     "description": "Time it takes to initialize Panorama (ms)"
   },