Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(587)

Unified Diff: components/autofill/core/browser/autofill_metrics.cc

Issue 2800853004: UKM that threads together multiple form interaction events. (Closed)
Patch Set: Moves UkmLogger as parameter to LogAutofillFormSubmittedState. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/autofill_metrics.cc
diff --git a/components/autofill/core/browser/autofill_metrics.cc b/components/autofill/core/browser/autofill_metrics.cc
index e813b1836f15f987cf2b02cadc879399f5e49b74..f5749faed0bcac918599427e87b2255ca5d59a03 100644
--- a/components/autofill/core/browser/autofill_metrics.cc
+++ b/components/autofill/core/browser/autofill_metrics.cc
@@ -5,6 +5,7 @@
#include "components/autofill/core/browser/autofill_metrics.h"
#include <algorithm>
+#include <utility>
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
@@ -22,6 +23,17 @@ const char kUKMCardUploadDecisionEntryName[] = "Autofill.CardUploadDecision";
const char kUKMCardUploadDecisionMetricName[] = "UploadDecision";
const char kUKMDeveloperEngagementEntryName[] = "Autofill.DeveloperEngagement";
const char kUKMDeveloperEngagementMetricName[] = "DeveloperEngagement";
+const char kUKMFormInteractionsEntryName[] = "Autofill.FormInteractions";
+const char kUKMFormInteractionsAutofillFormSubmittedStateMetricName[] =
+ "AutofillFormSubmittedState";
+const char kUKMFormInteractionsUserHappinessMetricMetricName[] =
+ "UserHappinessMetric";
+const char kUKMFormInteractionsAddressFormEventMetricName[] =
+ "FormEvent.Address";
+const char kUKMFormInteractionsCreditCardFormEventMetricName[] =
+ "FormEvent.CreditCard";
+const char kUKMFormInteractionsUnmaskPromptEventMetricName[] =
+ "UnmaskPromptEvent";
} // namespace internal
namespace autofill {
@@ -616,7 +628,8 @@ void AutofillMetrics::LogProfileActionOnFormSubmitted(
// static
void AutofillMetrics::LogAutofillFormSubmittedState(
- AutofillFormSubmittedState state) {
+ AutofillFormSubmittedState state,
+ AutofillMetrics::UkmLogger* ukm_logger) {
UMA_HISTOGRAM_ENUMERATION("Autofill.FormSubmittedState", state,
AUTOFILL_FORM_SUBMITTED_STATE_ENUM_SIZE);
@@ -650,6 +663,7 @@ void AutofillMetrics::LogAutofillFormSubmittedState(
NOTREACHED();
break;
}
+ ukm_logger->LogAutofillFormSubmittedState(state);
}
// static
@@ -745,7 +759,9 @@ bool AutofillMetrics::LogUkm(ukm::UkmService* ukm_service,
return true;
}
-AutofillMetrics::FormEventLogger::FormEventLogger(bool is_for_credit_card)
+AutofillMetrics::FormEventLogger::FormEventLogger(
+ bool is_for_credit_card,
+ AutofillMetrics::UkmLogger* ukm_logger)
: is_for_credit_card_(is_for_credit_card),
is_server_data_available_(false),
is_local_data_available_(false),
@@ -757,7 +773,8 @@ AutofillMetrics::FormEventLogger::FormEventLogger(bool is_for_credit_card)
has_logged_will_submit_(false),
has_logged_submitted_(false),
logged_suggestion_filled_was_server_data_(false),
- logged_suggestion_filled_was_masked_server_card_(false) {}
+ logged_suggestion_filled_was_masked_server_card_(false),
+ ukm_logger_(ukm_logger) {}
void AutofillMetrics::FormEventLogger::OnDidInteractWithAutofillableForm() {
if (!has_logged_interacted_) {
@@ -946,6 +963,88 @@ void AutofillMetrics::FormEventLogger::Log(FormEvent event) const {
else
name += ".WithBothServerAndLocalData";
LogUMAHistogramEnumeration(name, event, NUM_FORM_EVENTS);
+
+ if (is_for_credit_card_)
+ ukm_logger_->LogCreditCardFormEvent(event);
+ else
+ ukm_logger_->LogAddressFormEvent(event);
+}
+
+AutofillMetrics::UkmLogger::UkmLogger(ukm::UkmService* ukm_service)
+ : ukm_service_(ukm_service) {}
+
+AutofillMetrics::UkmLogger::~UkmLogger() {
+ LogUkm();
sebsg 2017/04/07 13:17:24 Wouldn't this cause us to log twice if LogAutofill
csashi 2017/04/09 19:17:26 I meant to clear |metrics_| after logging but forg
+}
+
+void AutofillMetrics::UkmLogger::LogAutofillFormSubmittedState(
+ AutofillFormSubmittedState state) {
+ metrics_.push_back(
+ std::make_pair(AUTOFILL_FORM_SUBMITTED_STATE, static_cast<int>(state)));
+ // User submitted form, we can finalize the events for this form.
+ LogUkm();
+}
+
+void AutofillMetrics::UkmLogger::LogUserHappinessMetric(
+ UserHappinessMetric metric) {
+ metrics_.push_back(
+ std::make_pair(USER_HAPPINESS_METRIC, static_cast<int>(metric)));
+}
+
+void AutofillMetrics::UkmLogger::LogAddressFormEvent(FormEvent event) {
+ metrics_.push_back(
+ std::make_pair(ADDRESS_FORM_EVENT, static_cast<int>(event)));
+}
+
+void AutofillMetrics::UkmLogger::LogCreditCardFormEvent(FormEvent event) {
+ metrics_.push_back(
+ std::make_pair(CREDIT_CARD_FORM_EVENT, static_cast<int>(event)));
+}
+
+void AutofillMetrics::UkmLogger::LogUnmaskPromptEvent(UnmaskPromptEvent event) {
+ metrics_.push_back(
+ std::make_pair(UNMASK_PROMPT_EVENT, static_cast<int>(event)));
+}
+
+void AutofillMetrics::UkmLogger::LogUkm() {
+ // TODO(csashi): Merge with |LogUkm| that takes a std::map of
+ // metric_name->value.
+ if (!IsUkmLoggingEnabled() || !ukm_service_ || !url_.is_valid() ||
+ metrics_.empty()) {
+ return;
+ }
+
+ int32_t source_id = ukm_service_->GetNewSourceID();
+ ukm_service_->UpdateSourceURL(source_id, url_);
+ std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder(
+ source_id, internal::kUKMFormInteractionsEntryName);
+
+ for (auto it = metrics_.begin(); it != metrics_.end(); ++it) {
+ const char* metric_name = nullptr;
+ switch (it->first) {
+ case AutofillMetrics::UkmLogger::AUTOFILL_FORM_SUBMITTED_STATE:
+ metric_name =
+ internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName;
+ break;
+ case AutofillMetrics::UkmLogger::USER_HAPPINESS_METRIC:
+ metric_name =
+ internal::kUKMFormInteractionsUserHappinessMetricMetricName;
+ break;
+ case AutofillMetrics::UkmLogger::ADDRESS_FORM_EVENT:
+ metric_name = internal::kUKMFormInteractionsAddressFormEventMetricName;
+ break;
+ case AutofillMetrics::UkmLogger::CREDIT_CARD_FORM_EVENT:
+ metric_name =
+ internal::kUKMFormInteractionsCreditCardFormEventMetricName;
+ break;
+ case AutofillMetrics::UkmLogger::UNMASK_PROMPT_EVENT:
+ metric_name = internal::kUKMFormInteractionsUnmaskPromptEventMetricName;
+ break;
+ default:
+ NOTREACHED();
+ }
+ builder->AddMetric(metric_name, it->second);
+ }
}
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698