From 6809cfbb58271baf86e902db6d44a1502ef45b53 Mon Sep 17 00:00:00 2001 From: Greg Tatum Date: Mon, 29 Aug 2022 13:30:39 +0000 Subject: [PATCH] Bug 1783261 - Measure the result text length in the text recognition modal; r=nordzilla Differential Revision: https://phabricator.services.mozilla.com/D154895 --- .../tests/browser/browser_textrecognition.js | 11 ++++++++--- .../components/textrecognition/tests/browser/head.js | 1 + .../components/textrecognition/textrecognition.mjs | 12 ++++++++++++ toolkit/components/telemetry/Histograms.json | 12 ++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/browser/components/textrecognition/tests/browser/browser_textrecognition.js b/browser/components/textrecognition/tests/browser/browser_textrecognition.js index 1b3f197a88d2..eac1e56eba9c 100644 --- a/browser/components/textrecognition/tests/browser/browser_textrecognition.js +++ b/browser/components/textrecognition/tests/browser/browser_textrecognition.js @@ -97,10 +97,15 @@ add_task(async function() { const close = contentDocument.querySelector("#text-recognition-close"); close.click(); + const expectedResultText = "Mozilla\nFirefox\n"; + is(getTextFromClipboard(), expectedResultText, "The copied text matches."); + is( - getTextFromClipboard(), - "Mozilla\nFirefox\n", - "The copied text matches." + Services.telemetry + .getHistogramById("TEXT_RECOGNITION_TEXT_LENGTH") + .snapshot().sum, + expectedResultText.length, + "The length of the text was recorded." ); info("Waiting for the dialog frame to close."); diff --git a/browser/components/textrecognition/tests/browser/head.js b/browser/components/textrecognition/tests/browser/head.js index f0682e5d18ac..819ae1b3a942 100644 --- a/browser/components/textrecognition/tests/browser/head.js +++ b/browser/components/textrecognition/tests/browser/head.js @@ -51,4 +51,5 @@ function clearTelemetry() { Services.telemetry .getHistogramById("TEXT_RECOGNITION_INTERACTION_TIMING") .clear(); + Services.telemetry.getHistogramById("TEXT_RECOGNITION_TEXT_LENGTH").clear(); } diff --git a/browser/components/textrecognition/textrecognition.mjs b/browser/components/textrecognition/textrecognition.mjs index 3e1c4081007b..950d7b2fd541 100644 --- a/browser/components/textrecognition/textrecognition.mjs +++ b/browser/components/textrecognition/textrecognition.mjs @@ -112,6 +112,17 @@ class TextRecognitionModal { window.addEventListener("unload", finish); } + /** + * After the results are shown, measure how long a user interacts with the modal. + * @param {number} length + */ + static recordTextLengthTelemetry(length) { + const histogram = Services.telemetry.getHistogramById( + "TEXT_RECOGNITION_TEXT_LENGTH" + ); + histogram.add(length); + } + setupCloseHandler() { document .querySelector("#text-recognition-close") @@ -215,6 +226,7 @@ class TextRecognitionModal { this.textEl.style.display = "block"; TextRecognitionModal.copy(text); + TextRecognitionModal.recordTextLengthTelemetry(text.length); } } diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index 0ab1618d3ab9..5bda546a99b8 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -17101,6 +17101,18 @@ "bug_numbers": [1783261], "description": "The milliseconds of time that a user viewed the text results." }, + "TEXT_RECOGNITION_TEXT_LENGTH": { + "record_in_processes": ["main"], + "products": ["firefox"], + "releaseChannelCollection": "opt-out", + "alert_emails": ["gtatum@mozilla.com", "nordzilla@mozilla.com"], + "expires_in_version": "109", + "kind": "exponential", + "high": 50000, + "n_buckets": 20, + "bug_numbers": [1783261], + "description": "Measures the length of the text that was recognized, in code units." + }, "DOWNLOADS_USER_ACTION_ON_BLOCKED_DOWNLOAD": { "record_in_processes": ["main"], "products": ["firefox"],