Bug 977774 - Metric for tracking opts out of Instant Translation. r=felipe. a=gavin
authorAsaf Romano <mano@mozilla.com>
Sun, 22 Jun 2014 12:23:40 +0300
changeset 208432 aa4cb3562ef13b0e1b7428f71e71068ba3946367
parent 208431 d9ac8792c337ca5dec794cf2019cfad741e0380d
child 208433 7717946aeb52207db46230eb0e95f3ff5491e93f
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe, gavin
bugs977774
milestone32.0a2
Bug 977774 - Metric for tracking opts out of Instant Translation. r=felipe. a=gavin
browser/components/translation/Translation.jsm
browser/components/translation/test/unit/test_healthreport.js
services/healthreport/docs/dataformat.rst
--- a/browser/components/translation/Translation.jsm
+++ b/browser/components/translation/Translation.jsm
@@ -307,16 +307,23 @@ let TranslationHealthReport = {
    *        the user has manually adjusted the detected language false should
    *        be passed.
    */
   recordLanguageChange: function (beforeFirstTranslation) {
     this._withProvider(provider => provider.recordLanguageChange(beforeFirstTranslation));
   },
 
   /**
+   * Record a denied translation offer.
+   */
+  recordDeniedTranslationOffer: function () {
+    this._withProvider(provider => provider.recordDeniedTranslationOffer());
+  },
+
+  /**
    * Retrieve the translation provider and pass it to the given function.
    *
    * @param callback
    *        The function that will be passed the translation provider.
    */
   _withProvider: function (callback) {
     try {
       let reporter = Cc["@mozilla.org/datareporting/service;1"]
@@ -364,16 +371,17 @@ TranslationMeasurement1.prototype = Obje
     missedTranslationOpportunityCount: DAILY_COUNTER_FIELD,
     pageTranslatedCount: DAILY_COUNTER_FIELD,
     charactersTranslatedCount: DAILY_COUNTER_FIELD,
     translationOpportunityCountsByLanguage: DAILY_LAST_TEXT_FIELD,
     missedTranslationOpportunityCountsByLanguage: DAILY_LAST_TEXT_FIELD,
     pageTranslatedCountsByLanguage: DAILY_LAST_TEXT_FIELD,
     detectedLanguageChangedBefore: DAILY_COUNTER_FIELD,
     detectedLanguageChangedAfter: DAILY_COUNTER_FIELD,
+    deniedTranslationOffer: DAILY_COUNTER_FIELD,
     detectLanguageEnabled: DAILY_LAST_NUMERIC_FIELD,
     showTranslationUI: DAILY_LAST_NUMERIC_FIELD,
   },
 
   shouldIncludeField: function (field) {
     if (!Services.prefs.getBoolPref("toolkit.telemetry.enabled")) {
       // This measurement should only be included when telemetry is
       // enabled, so we will not include any fields.
@@ -500,16 +508,25 @@ TranslationProvider.prototype = Object.f
       if (beforeFirstTranslation) {
           yield m.incrementDailyCounter("detectedLanguageChangedBefore");
         } else {
           yield m.incrementDailyCounter("detectedLanguageChangedAfter");
         }
     }.bind(this));
   },
 
+  recordDeniedTranslationOffer: function () {
+    let m = this.getMeasurement(TranslationMeasurement1.prototype.name,
+                                TranslationMeasurement1.prototype.version);
+
+    return this._enqueueTelemetryStorageTask(function* recordTask() {
+      yield m.incrementDailyCounter("deniedTranslationOffer");
+    }.bind(this));
+  },
+
   collectDailyData: function () {
     let m = this.getMeasurement(TranslationMeasurement1.prototype.name,
                                 TranslationMeasurement1.prototype.version);
 
     return this._enqueueTelemetryStorageTask(function* recordTask() {
       let detectLanguageEnabled = Services.prefs.getBoolPref("browser.translation.detectLanguage");
       yield m.setDailyLastNumeric("detectLanguageEnabled", detectLanguageEnabled ? 1 : 0);
 
--- a/browser/components/translation/test/unit/test_healthreport.js
+++ b/browser/components/translation/test/unit/test_healthreport.js
@@ -191,16 +191,38 @@ add_task(function* test_record_translati
   Assert.equal(day.get("detectedLanguageChangedBefore"), 1);
   Assert.ok(day.has("detectedLanguageChangedAfter"));
   Assert.equal(day.get("detectedLanguageChangedAfter"), 2);
 
   yield provider.shutdown();
   yield storage.close();
 });
 
+add_task(function* test_denied_translation_offer() {
+  let storage = yield Metrics.Storage("translation");
+  let provider = new TranslationProvider();
+  yield provider.init(storage);
+  let now = new Date();
+
+  yield provider.recordDeniedTranslationOffer();
+  yield provider.recordDeniedTranslationOffer();
+
+  let m = provider.getMeasurement("translation", 1);
+  let values = yield m.getValues();
+  Assert.equal(values.days.size, 1);
+  Assert.ok(values.days.hasDay(now));
+  let day = values.days.getDay(now);
+
+  Assert.ok(day.has("deniedTranslationOffer"));
+  Assert.equal(day.get("deniedTranslationOffer"), 2);
+
+  yield provider.shutdown();
+  yield storage.close();
+});
+
 add_task(function* test_collect_daily() {
   let storage = yield Metrics.Storage("translation");
   let provider = new TranslationProvider();
   yield provider.init(storage);
   let now = new Date();
 
   // Set the prefs we test here to `false` initially.
   const kPrefDetectLanguage = "browser.translation.detectLanguage";
@@ -248,16 +270,18 @@ add_task(function* test_healthreporter_j
     yield provider.recordTranslationOpportunity("fr", now);
     yield provider.recordLanguageChange(true);
     yield provider.recordTranslation("fr", "en", 1000, now);
     yield provider.recordLanguageChange(false);
 
     yield provider.recordTranslationOpportunity("es", now);
     yield provider.recordTranslation("es", "en", 1000, now);
 
+    yield provider.recordDeniedTranslationOffer();
+
     yield reporter.collectMeasurements();
     let payload = yield reporter.getJSONPayload(true);
     let today = reporter._formatDate(now);
 
     Assert.ok(today in payload.data.days);
     let day = payload.data.days[today];
 
     Assert.ok("org.mozilla.translation.translation" in day);
@@ -280,16 +304,19 @@ add_task(function* test_healthreporter_j
     Assert.ok("es" in translations["pageTranslatedCountsByLanguage"]);
     Assert.equal(translations["pageTranslatedCountsByLanguage"]["es"]["total"], 1);
     Assert.equal(translations["pageTranslatedCountsByLanguage"]["es"]["en"], 1);
 
     Assert.ok("detectedLanguageChangedBefore" in translations);
     Assert.equal(translations["detectedLanguageChangedBefore"], 1);
     Assert.ok("detectedLanguageChangedAfter" in translations);
     Assert.equal(translations["detectedLanguageChangedAfter"], 1);
+    
+    Assert.ok("deniedTranslationOffer" in translations);
+    Assert.equal(translations["deniedTranslationOffer"], 1);
   } finally {
     reporter._shutdown();
   }
 });
 
 // Test the payload after recording with telemetry disabled.
 add_task(function* test_healthreporter_json2() {
   Services.prefs.setBoolPref("toolkit.telemetry.enabled", false);
@@ -304,16 +331,18 @@ add_task(function* test_healthreporter_j
     yield provider.recordTranslationOpportunity("fr", now);
     yield provider.recordLanguageChange(true);
     yield provider.recordTranslation("fr", "en", 1000, now);
     yield provider.recordLanguageChange(false);
 
     yield provider.recordTranslationOpportunity("es", now);
     yield provider.recordTranslation("es", "en", 1000, now);
 
+    yield provider.recordDeniedTranslationOffer();
+
     yield reporter.collectMeasurements();
     let payload = yield reporter.getJSONPayload(true);
     let today = reporter._formatDate(now);
 
     Assert.ok(today in payload.data.days);
     let day = payload.data.days[today];
 
     Assert.ok("org.mozilla.translation.translation" in day);
@@ -322,12 +351,13 @@ add_task(function* test_healthreporter_j
 
     Assert.ok(!("translationOpportunityCount" in translations));
     Assert.ok(!("pageTranslatedCount" in translations));
     Assert.ok(!("charactersTranslatedCount" in translations));
     Assert.ok(!("translationOpportunityCountsByLanguage" in translations));
     Assert.ok(!("pageTranslatedCountsByLanguage" in translations));
     Assert.ok(!("detectedLanguageChangedBefore" in translations));
     Assert.ok(!("detectedLanguageChangedAfter" in translations));
+    Assert.ok(!("deniedTranslationOffer" in translations));
   } finally {
     reporter._shutdown();
   }
 });
--- a/services/healthreport/docs/dataformat.rst
+++ b/services/healthreport/docs/dataformat.rst
@@ -1551,16 +1551,20 @@ pageTranslatedCount
 charactersTranslatedCount
     Integer count of the number of characters translated.
 detectedLanguageChangedBefore
     Integer count of the number of times the user manually adjusted the detected
     language before translating.
 detectedLanguageChangedAfter
     Integer count of the number of times the user manually adjusted the detected
     language after having first translated the page.
+deniedTranslationOffer
+    Integer count of the numbers of times the user opted-out offered
+    page translation, either by the Not Now button or by the notification's
+    close button in the "offer" state.
 
 Additional daily counts broken down by language are reported in the following
 properties:
 
 translationOpportunityCountsByLanguage
     A mapping from language to count of opportunities to translate that
     language.
 missedTranslationOpportunityCountsByLanguage
@@ -1587,16 +1591,17 @@ Example
       "_v": 1,
       "detectLanguageEnabled": 1,
       "showTranslationUI": 1,
       "translationOpportunityCount": 134,
       "pageTranslatedCount": 6,
       "charactersTranslatedCount": "1126",
       "detectedLanguageChangedBefore": 1,
       "detectedLanguageChangedAfter": 2,
+      "deniedTranslationOffer": 3
       "translationOpportunityCountsByLanguage": {
         "fr": 100,
         "es": 34
       },
       "pageTranslatedCountsByLanguage": {
         "fr": {
           "total": 6,
           "es": 5,