Commit 7187698b authored by Max Curran's avatar Max Curran Committed by Chromium LUCI CQ

Added logging of the new page-load frequency Translate metrics to UKM.

This CL adds logging of proposed Translate proto to UKM. This proto
captures a summary of the user's interaction with Translate from the
beginning of the page load to when the proto is logged. In the event
that the user backgrounds Chrome and later returns, there may be more
than one proto logged per page load. In this case the sequence number of
each proto can be used distinguish the order that the protos were
logged.

Full design doc: https://docs.google.com/document/d/1dyWh1Xw5VgUA00VA-5PTgKQ6ItziPBnSyeDR8saJ9vM/edit?usp=sharing
UKM collection review: https://docs.google.com/document/d/1UNVJ2HC35Cy2C6zCb6DdwKFhafURGeV9gDzY5Jm5id8/edit?usp=sharing

Bug: 1114868
Change-Id: If970d2b656c7355e6a05fa06729978265d9ecb64
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2590754
Commit-Queue: Max Curran <curranmax@chromium.org>
Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Reviewed-by: default avatarScott Little <sclittle@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841292}
parent abd87a46
......@@ -42,6 +42,14 @@ TranslatePageLoadMetricsObserver::OnStart(
return CONTINUE_OBSERVING;
}
page_load_metrics::PageLoadMetricsObserver::ObservePolicy
TranslatePageLoadMetricsObserver::OnCommit(
content::NavigationHandle* navigation_handle,
ukm::SourceId source_id) {
translate_metrics_logger_->SetUkmSourceId(source_id);
return CONTINUE_OBSERVING;
}
page_load_metrics::PageLoadMetricsObserver::ObservePolicy
TranslatePageLoadMetricsObserver::OnHidden(
const page_load_metrics::mojom::PageLoadTiming& timing) {
......
......@@ -41,6 +41,8 @@ class TranslatePageLoadMetricsObserver
ObservePolicy OnStart(content::NavigationHandle* navigation_handle,
const GURL& currently_committed_url,
bool started_in_foreground) override;
ObservePolicy OnCommit(content::NavigationHandle* navigation_handle,
ukm::SourceId source_id) override;
ObservePolicy OnHidden(
const page_load_metrics::mojom::PageLoadTiming& timing) override;
ObservePolicy OnShown() override;
......
......@@ -34,6 +34,10 @@ class MockTranslateMetricsLoggerContainer
mock_translate_metrics_logger_->RecordMetrics(is_final);
}
void SetUkmSourceId(ukm::SourceId ukm_source_id) override {
mock_translate_metrics_logger_->SetUkmSourceId(ukm_source_id);
}
void LogRankerMetrics(translate::RankerDecision ranker_decision,
uint32_t ranker_version) override {
mock_translate_metrics_logger_->LogRankerMetrics(ranker_decision,
......
......@@ -9,5 +9,8 @@ include_rules = [
specific_include_rules = {
"translate_ranker_impl_unittest\.cc": [
"+components/ukm",
],
"translate_metrics_logger_impl_unittest\.cc": [
"+components/ukm",
]
}
......@@ -30,6 +30,7 @@ class MockTranslateMetricsLogger : public TranslateMetricsLogger {
MOCK_METHOD1(OnPageLoadStart, void(bool));
MOCK_METHOD1(OnForegroundChange, void(bool));
MOCK_METHOD1(RecordMetrics, void(bool));
MOCK_METHOD1(SetUkmSourceId, void(ukm::SourceId));
MOCK_METHOD2(LogRankerMetrics, void(RankerDecision, uint32_t));
MOCK_METHOD1(LogTriggerDecision, void(TriggerDecision));
MOCK_METHOD0(LogAutofillAssistantDeferredTriggerDecision, void());
......
......@@ -9,6 +9,7 @@
#include <string>
#include "components/translate/core/common/translate_errors.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
namespace translate {
......@@ -57,6 +58,8 @@ enum class TriggerDecision {
kMaxValue = kAutomaticTranslationByPref,
};
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class UIInteraction {
kUninitialized = 0,
kTranslate = 1,
......@@ -89,6 +92,9 @@ class TranslateMetricsLogger {
// won't be called again.
virtual void RecordMetrics(bool is_final) = 0;
// Sets the UKM source ID for the current page load.
virtual void SetUkmSourceId(ukm::SourceId ukm_source_id) = 0;
virtual void LogRankerMetrics(RankerDecision ranker_decision,
uint32_t ranker_version) = 0;
......
......@@ -8,6 +8,9 @@
#include "base/metrics/metrics_hashes.h"
#include "base/time/default_tick_clock.h"
#include "components/translate/core/browser/translate_manager.h"
#include "services/metrics/public/cpp/metrics_utils.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
namespace translate {
......@@ -63,18 +66,74 @@ void TranslateMetricsLoggerImpl::OnForegroundChange(bool is_foreground) {
void TranslateMetricsLoggerImpl::RecordMetrics(bool is_final) {
UpdateTimeTranslated(current_state_is_translated_, is_foreground_);
// If a translation is still in progress, then use the previous state.
bool this_initial_state_is_translated =
is_initial_state_dependent_on_in_progress_translation_
? previous_state_is_translated_
: initial_state_is_translated_;
bool this_current_state_is_translated = is_translation_in_progress_
? previous_state_is_translated_
: current_state_is_translated_;
// The first time |RecordMetrics| is called, record all page load frequency
// UMA metrcis.
if (sequence_no_ == 0)
RecordPageLoadUmaMetrics();
// TODO(curranmax): Log UKM metrics now that the page load is.
// completed. https://crbug.com/1114868.
RecordPageLoadUmaMetrics(this_initial_state_is_translated,
this_current_state_is_translated);
// Record metrics to UKM.
ukm::UkmRecorder* ukm_recorder = ukm::UkmRecorder::Get();
ukm::builders::TranslatePageLoad(ukm_source_id_)
.SetSequenceNumber(sequence_no_)
.SetTriggerDecision(int(trigger_decision_))
.SetRankerDecision(int(ranker_decision_))
.SetRankerVersion(int(ranker_version_))
.SetInitialState(int(ConvertToTranslateState(
this_initial_state_is_translated, initial_state_is_ui_shown_,
initial_state_is_omnibox_icon_shown_)))
.SetFinalState(int(ConvertToTranslateState(
this_current_state_is_translated, current_state_is_ui_shown_,
current_state_is_omnibox_icon_shown_)))
.SetNumTranslations(
ukm::GetExponentialBucketMinForCounts1000(num_translations_))
.SetNumReversions(
ukm::GetExponentialBucketMinForCounts1000(num_reversions_))
.SetInitialSourceLanguage(
int(base::HashMetricName(initial_source_language_)))
.SetFinalSourceLanguage(
int(base::HashMetricName(current_source_language_)))
.SetInitialSourceLanguageInContentLanguages(
int(is_initial_source_language_in_users_content_languages_))
.SetInitialTargetLanguage(
int(base::HashMetricName(initial_target_language_)))
.SetFinalTargetLanguage(
int(base::HashMetricName(current_target_language_)))
.SetNumTargetLanguageChanges(ukm::GetExponentialBucketMinForCounts1000(
num_target_language_changes_))
.SetFirstUIInteraction(int(first_ui_interaction_))
.SetNumUIInteractions(
ukm::GetExponentialBucketMinForCounts1000(num_ui_interactions_))
.SetFirstTranslateError(int(first_translate_error_type_))
.SetNumTranslateErrors(
ukm::GetExponentialBucketMinForCounts1000(num_translate_errors_))
.SetTotalTimeTranslated(ukm::GetExponentialBucketMinForUserTiming(
total_time_translated_.InSeconds()))
.SetTotalTimeNotTranslated(ukm::GetExponentialBucketMinForUserTiming(
total_time_not_translated_.InSeconds()))
.SetMaxTimeToTranslate(ukm::GetExponentialBucketMinForUserTiming(
max_time_to_translate_.InMilliseconds()))
.Record(ukm_recorder);
sequence_no_++;
}
void TranslateMetricsLoggerImpl::RecordPageLoadUmaMetrics() {
void TranslateMetricsLoggerImpl::SetUkmSourceId(ukm::SourceId ukm_source_id) {
ukm_source_id_ = ukm_source_id;
}
void TranslateMetricsLoggerImpl::RecordPageLoadUmaMetrics(
bool initial_state_is_translated,
bool current_state_is_translated) {
base::UmaHistogramEnumeration(kTranslatePageLoadRankerDecision,
ranker_decision_);
base::UmaHistogramSparse(kTranslatePageLoadRankerVersion,
......@@ -85,23 +144,14 @@ void TranslateMetricsLoggerImpl::RecordPageLoadUmaMetrics() {
kTranslatePageLoadAutofillAssistantDeferredTriggerDecision,
autofill_assistant_deferred_trigger_decision_);
// If a translation is still in progress, then use the previous state.
bool this_initial_state_is_translated =
is_initial_state_dependent_on_in_progress_translation_
? previous_state_is_translated_
: initial_state_is_translated_;
bool this_current_state_is_translated = is_translation_in_progress_
? previous_state_is_translated_
: current_state_is_translated_;
base::UmaHistogramEnumeration(
kTranslatePageLoadInitialState,
ConvertToTranslateState(this_initial_state_is_translated,
ConvertToTranslateState(initial_state_is_translated,
initial_state_is_ui_shown_,
initial_state_is_omnibox_icon_shown_));
base::UmaHistogramEnumeration(
kTranslatePageLoadFinalState,
ConvertToTranslateState(this_current_state_is_translated,
ConvertToTranslateState(current_state_is_translated,
current_state_is_ui_shown_,
current_state_is_omnibox_icon_shown_));
base::UmaHistogramCounts10000(kTranslatePageLoadNumTranslations,
......
......@@ -41,6 +41,7 @@ class NullTranslateMetricsLogger : public TranslateMetricsLogger {
void OnPageLoadStart(bool is_foreground) override {}
void OnForegroundChange(bool is_foreground) override {}
void RecordMetrics(bool is_final) override {}
void SetUkmSourceId(ukm::SourceId ukm_source_id) override {}
void LogRankerMetrics(RankerDecision ranker_decision,
uint32_t ranker_version) override {}
void LogTriggerDecision(TriggerDecision trigger_decision) override {}
......@@ -85,6 +86,7 @@ class TranslateMetricsLoggerImpl : public TranslateMetricsLogger {
void OnPageLoadStart(bool is_foreground) override;
void OnForegroundChange(bool is_foreground) override;
void RecordMetrics(bool is_final) override;
void SetUkmSourceId(ukm::SourceId ukm_source_id) override;
void LogRankerMetrics(RankerDecision ranker_decision,
uint32_t ranker_version) override;
void LogTriggerDecision(TriggerDecision trigger_decision) override;
......@@ -108,7 +110,8 @@ class TranslateMetricsLoggerImpl : public TranslateMetricsLogger {
friend class testing::TranslateMetricsLoggerImplTest;
// Logs all page load frequency UMA metrics based on the stored state.
void RecordPageLoadUmaMetrics();
void RecordPageLoadUmaMetrics(bool initial_state_is_translated,
bool current_stat_is_translated);
// Helpter function to get the correct |TranslateState| value based on the
// different dimensions we care about.
......@@ -128,6 +131,9 @@ class TranslateMetricsLoggerImpl : public TranslateMetricsLogger {
// recorded UKM protos.
unsigned int sequence_no_ = 0;
// The UKM source ID for the current page load.
ukm::SourceId ukm_source_id_ = ukm::kInvalidSourceId;
// Tracks if the associated page is in the foreground (|true|) or the
// background (|false|)
bool is_foreground_ = false;
......
......@@ -74325,6 +74325,19 @@ Full version information for the fingerprint enum values:
<int value="15" label="Automatic translation, by user preference"/>
</enum>
<enum name="TranslateUIInteraction">
<int value="0" label="Uninitialized"/>
<int value="1" label="Translate page"/>
<int value="2" label="Revert translation"/>
<int value="3" label="Always translate language"/>
<int value="4" label="Change source language"/>
<int value="5" label="Change target language"/>
<int value="6" label="Never translate language"/>
<int value="7" label="Never translate site"/>
<int value="8" label="Close UI explicitly"/>
<int value="9" label="Close UI by lost focus"/>
</enum>
<enum name="TrendingTileEvent">
<int value="0" label="Tile was shown"/>
<int value="1" label="Tile was removed"/>
......@@ -13373,6 +13373,154 @@ be describing additional metrics about the same event.
<metric name="TargetLanguage" semantic_type="ST_DEMOGRAPHIC_INFO"/>
</event>
<event name="TranslatePageLoad">
<owner>curranmax@chromium.org</owner>
<owner>megjablon@chromium.org</owner>
<owner>chrome-language@google.com</owner>
<summary>
Summary of the user's interaction with Translate from the beginning of the
page load to when the event is recorded. This event is recorded when a page
load is completed and every time that Chrome is backgrounded during the
course of the page load. This means we can record multiple events for a
single page load, but it guarentees that we will still record data in
instances where the user backgrounds then kills Chrome.
</summary>
<metric name="FinalSourceLanguage" semantic_type="ST_DEMOGRAPHIC_INFO"
enum="CLD3LanguageCode">
<summary>
The source language at the time the event is recorded. In most cases this
will match the intial source language, but the user can change the source
language manually if they want. Note that the semantic_type attribute is
included in order to remain consistent with the previous Translate UKM
proto.
</summary>
</metric>
<metric name="FinalState" enum="TranslateState">
<summary>
At the time this event is recorded, the state of Translate. This includes
whether the page is translated or not and if no UI is shown, just the
omnibox icon is shown, or the full translate UI is shown.
</summary>
</metric>
<metric name="FinalTargetLanguage" semantic_type="ST_DEMOGRAPHIC_INFO"
enum="CLD3LanguageCode">
<summary>
The target language at the time the event is recorded. In most cases this
will match the initial target language, but the user can change the target
language manually if they want. Note that the semantic_type attribute is
included in order to remain consistent with the previous Translate UKM
proto.
</summary>
</metric>
<metric name="FirstTranslateError" enum="TranslateError">
<summary>
The first error to occur within Translate for this page load.
</summary>
</metric>
<metric name="FirstUIInteraction" enum="TranslateUIInteraction">
<summary>
The user's first interaction with the Translate UI.
</summary>
</metric>
<metric name="InitialSourceLanguage" semantic_type="ST_DEMOGRAPHIC_INFO"
enum="CLD3LanguageCode">
<summary>
The initial source language that Translate determines for the page. Note
that the semantic_type attribute is included in order to remain consistent
with the previous Translate UKM proto.
</summary>
</metric>
<metric name="InitialSourceLanguageInContentLanguages" enum="Boolean">
<summary>
Signals whether the initial source language is in the list of the user's
content languages. The user's content languages loosely match with the
languages the user has translated to before or has blocked for
translation.
</summary>
</metric>
<metric name="InitialState" enum="TranslateState">
<summary>
At the beginning of the page load, the state of Translate. This includes
whether the page is translated or not and if no UI is shown, just the
omnibox icon is shown, or the full translate UI is shown.
</summary>
</metric>
<metric name="InitialTargetLanguage" semantic_type="ST_DEMOGRAPHIC_INFO"
enum="CLD3LanguageCode">
<summary>
The initial target language that Translate thinks it should translate to.
Note that the semantic_type attribute is included in order to remain
consistent with the previous Translate UKM proto.
</summary>
</metric>
<metric name="MaxTimeToTranslate">
<summary>
Across all translations during this page load, the maximum amount of time
(in milliseconds) it took to translate the page.
</summary>
</metric>
<metric name="NumReversions">
<summary>
The number of times a translation was reverted.
</summary>
</metric>
<metric name="NumTargetLanguageChanges">
<summary>
The number of times that the target language was changed by the user over
the course of this page load.
</summary>
</metric>
<metric name="NumTranslateErrors">
<summary>
The number of errors to occur within Translate for this page load.
</summary>
</metric>
<metric name="NumTranslations">
<summary>
The number of times the page was translated.
</summary>
</metric>
<metric name="NumUIInteractions">
<summary>
The number of times that the user interacts with the Translate UI.
</summary>
</metric>
<metric name="RankerDecision" enum="TranslateRankerDecision">
<summary>
Decision of the Ranker whether to show the UI or not.
</summary>
</metric>
<metric name="RankerVersion">
<summary>
Version of Ranker used for this page load.
</summary>
</metric>
<metric name="SequenceNumber">
<summary>
In case multiple events are logged for one page load, we track the
sequence in the order each event is logged.
</summary>
</metric>
<metric name="TotalTimeNotTranslated">
<summary>
The amount of time (in seconds) this page was in the foreground and not
translated.
</summary>
</metric>
<metric name="TotalTimeTranslated">
<summary>
The amount of time (in seconds) this page was in the foreground and
translated.
</summary>
</metric>
<metric name="TriggerDecision" enum="TranslateTriggerDecision">
<summary>
The highest priority trigger that determined the initial state of
Translate for this page load.
</summary>
</metric>
</event>
<event name="TrustedWebActivity.Open" singular="True">
<owner>peconn@chromium.org</owner>
<summary>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment