Bug 973294 - Firefox counts the number of times that users pick 'Show Original'. r=felipe.

This commit is contained in:
Asaf Romano 2014-06-24 08:36:56 +03:00
parent d1b3d852f0
commit 834aa3ccc5
4 changed files with 56 additions and 8 deletions

View File

@ -184,6 +184,7 @@ TranslationUI.prototype = {
this.originalShown = true;
this.showURLBarIcon();
this.browser.messageManager.sendAsyncMessage("Translation:ShowOriginal");
TranslationHealthReport.recordShowOriginalContent();
},
showTranslatedContent: function() {
@ -323,6 +324,13 @@ let TranslationHealthReport = {
this._withProvider(provider => provider.recordDeniedTranslationOffer());
},
/**
* Record a "Show Original" command use.
*/
recordShowOriginalContent: function () {
this._withProvider(provider => provider.recordShowOriginalContent());
},
/**
* Retrieve the translation provider and pass it to the given function.
*
@ -382,6 +390,7 @@ TranslationMeasurement1.prototype = Object.freeze({
detectedLanguageChangedBefore: DAILY_COUNTER_FIELD,
detectedLanguageChangedAfter: DAILY_COUNTER_FIELD,
deniedTranslationOffer: DAILY_COUNTER_FIELD,
showOriginalContent: DAILY_COUNTER_FIELD,
detectLanguageEnabled: DAILY_LAST_NUMERIC_FIELD,
showTranslationUI: DAILY_LAST_NUMERIC_FIELD,
},
@ -527,6 +536,15 @@ TranslationProvider.prototype = Object.freeze({
}.bind(this));
},
recordShowOriginalContent: function () {
let m = this.getMeasurement(TranslationMeasurement1.prototype.name,
TranslationMeasurement1.prototype.version);
return this._enqueueTelemetryStorageTask(function* recordTask() {
yield m.incrementDailyCounter("showOriginalContent");
}.bind(this));
},
collectDailyData: function () {
let m = this.getMeasurement(TranslationMeasurement1.prototype.name,
TranslationMeasurement1.prototype.version);

View File

@ -32,7 +32,8 @@ let MetricsChecker = {
this._metrics = {
pageCount: day.get("pageTranslatedCount") || 0,
charCount: day.get("charactersTranslatedCount") || 0,
deniedOffers: day.get("deniedTranslationOffer") || 0
deniedOffers: day.get("deniedTranslationOffer") || 0,
showOriginal: day.get("showOriginalContent") || 0
};
this._metricsTime = metricsTime;
}),
@ -103,6 +104,15 @@ add_task(function* test_deny_translation_metric() {
gBrowser.removeTab(tab);
});
add_task(function* test_show_original() {
let tab =
yield translate("<h1>Hallo Welt!</h1><h1>Bratwurst!</h1>", "de", "en", false);
yield MetricsChecker.checkAdditions({ pageCount: 1, showOriginal: 0 });
getInfobarElement(tab.linkedBrowser, "showOriginal").doCommand();
yield MetricsChecker.checkAdditions({ pageCount: 0, showOriginal: 1 });
gBrowser.removeTab(tab);
});
function getInfobarElement(browser, anonid) {
let notif = browser.translationUI
.notificationBox.getNotificationWithValue("translation");

View File

@ -196,14 +196,14 @@ add_task(function* test_record_translation() {
yield storage.close();
});
add_task(function* test_denied_translation_offer() {
function* test_simple_counter(aProviderFuncName, aCounterName) {
let storage = yield Metrics.Storage("translation");
let provider = new TranslationProvider();
yield provider.init(storage);
let now = new Date();
yield provider.recordDeniedTranslationOffer();
yield provider.recordDeniedTranslationOffer();
yield provider[aProviderFuncName]();
yield provider[aProviderFuncName]();
let m = provider.getMeasurement("translation", 1);
let values = yield m.getValues();
@ -211,11 +211,19 @@ add_task(function* test_denied_translation_offer() {
Assert.ok(values.days.hasDay(now));
let day = values.days.getDay(now);
Assert.ok(day.has("deniedTranslationOffer"));
Assert.equal(day.get("deniedTranslationOffer"), 2);
Assert.ok(day.has(aCounterName));
Assert.equal(day.get(aCounterName), 2);
yield provider.shutdown();
yield storage.close();
}
add_task(function* test_denied_translation_offer() {
yield test_simple_counter("recordDeniedTranslationOffer", "deniedTranslationOffer");
});
add_task(function* test_show_original() {
yield test_simple_counter("recordShowOriginalContent", "showOriginalContent");
});
add_task(function* test_collect_daily() {
@ -277,6 +285,8 @@ add_task(function* test_healthreporter_json() {
yield provider.recordDeniedTranslationOffer();
yield provider.recordShowOriginalContent();
yield reporter.collectMeasurements();
let payload = yield reporter.getJSONPayload(true);
let today = reporter._formatDate(now);
@ -312,6 +322,9 @@ add_task(function* test_healthreporter_json() {
Assert.ok("deniedTranslationOffer" in translations);
Assert.equal(translations["deniedTranslationOffer"], 1);
Assert.ok("showOriginalContent" in translations);
Assert.equal(translations["showOriginalContent"], 1);
} finally {
reporter._shutdown();
}
@ -338,6 +351,8 @@ add_task(function* test_healthreporter_json2() {
yield provider.recordDeniedTranslationOffer();
yield provider.recordShowOriginalContent();
yield reporter.collectMeasurements();
let payload = yield reporter.getJSONPayload(true);
let today = reporter._formatDate(now);
@ -357,6 +372,7 @@ add_task(function* test_healthreporter_json2() {
Assert.ok(!("detectedLanguageChangedBefore" in translations));
Assert.ok(!("detectedLanguageChangedAfter" in translations));
Assert.ok(!("deniedTranslationOffer" in translations));
Assert.ok(!("showOriginalContent" in translations));
} finally {
reporter._shutdown();
}

View File

@ -1557,9 +1557,12 @@ 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
Integer count of the number 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.
showOriginalContent
Integer count of the number of times the user activated the Show Original
command.
Additional daily counts broken down by language are reported in the following
properties:
@ -1596,7 +1599,8 @@ Example
"charactersTranslatedCount": "1126",
"detectedLanguageChangedBefore": 1,
"detectedLanguageChangedAfter": 2,
"deniedTranslationOffer": 3
"deniedTranslationOffer": 3,
showOriginalContent: 2,
"translationOpportunityCountsByLanguage": {
"fr": 100,
"es": 34