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

Side by Side Diff: components/autofill/core/browser/autofill_metrics.cc

Issue 2800853004: UKM that threads together multiple form interaction events. (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/autofill_metrics.h" 5 #include "components/autofill/core/browser/autofill_metrics.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility>
8 9
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
11 #include "base/metrics/sparse_histogram.h" 12 #include "base/metrics/sparse_histogram.h"
12 #include "base/metrics/user_metrics.h" 13 #include "base/metrics/user_metrics.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "components/autofill/core/browser/autofill_experiments.h" 15 #include "components/autofill/core/browser/autofill_experiments.h"
15 #include "components/autofill/core/browser/autofill_type.h" 16 #include "components/autofill/core/browser/autofill_type.h"
16 #include "components/autofill/core/browser/form_structure.h" 17 #include "components/autofill/core/browser/form_structure.h"
17 #include "components/autofill/core/common/form_data.h" 18 #include "components/autofill/core/common/form_data.h"
18 #include "components/ukm/ukm_entry_builder.h" 19 #include "components/ukm/ukm_entry_builder.h"
19 20
20 namespace internal { 21 namespace internal {
21 const char kUKMCardUploadDecisionEntryName[] = "Autofill.CardUploadDecision"; 22 const char kUKMCardUploadDecisionEntryName[] = "Autofill.CardUploadDecision";
22 const char kUKMCardUploadDecisionMetricName[] = "UploadDecision"; 23 const char kUKMCardUploadDecisionMetricName[] = "UploadDecision";
23 const char kUKMDeveloperEngagementEntryName[] = "Autofill.DeveloperEngagement"; 24 const char kUKMDeveloperEngagementEntryName[] = "Autofill.DeveloperEngagement";
24 const char kUKMDeveloperEngagementMetricName[] = "DeveloperEngagement"; 25 const char kUKMDeveloperEngagementMetricName[] = "DeveloperEngagement";
26 const char kUKMFormInteractionsEntryName[] = "Autofill.FormInteractions";
27 const char kUKMFormInteractionsAutofillFormSubmittedStateMetricName[] =
28 "AutofillFormSubmittedState";
29 const char kUKMFormInteractionsUserHappinessMetricMetricName[] =
30 "UserHappinessMetric";
31 const char kUKMFormInteractionsAddressFormEventMetricName[] =
32 "FormEvent.Address";
33 const char kUKMFormInteractionsCreditCardFormEventMetricName[] =
34 "FormEvent.CreditCard";
35 const char kUKMFormInteractionsUnmaskPromptEventMetricName[] =
36 "UnmaskPromptEvent";
25 } // namespace internal 37 } // namespace internal
26 38
27 namespace autofill { 39 namespace autofill {
28 40
29 namespace { 41 namespace {
30 42
31 // Note: if adding an enum value here, update the corresponding description for 43 // Note: if adding an enum value here, update the corresponding description for
32 // AutofillTypeQualityByFieldType in histograms.xml. 44 // AutofillTypeQualityByFieldType in histograms.xml.
33 enum FieldTypeGroupForMetrics { 45 enum FieldTypeGroupForMetrics {
34 GROUP_AMBIGUOUS = 0, 46 GROUP_AMBIGUOUS = 0,
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 std::unique_ptr<ukm::UkmEntryBuilder> builder = 750 std::unique_ptr<ukm::UkmEntryBuilder> builder =
739 ukm_service->GetEntryBuilder(source_id, ukm_entry_name.c_str()); 751 ukm_service->GetEntryBuilder(source_id, ukm_entry_name.c_str());
740 752
741 for (auto it = metrics.begin(); it != metrics.end(); ++it) { 753 for (auto it = metrics.begin(); it != metrics.end(); ++it) {
742 builder->AddMetric(it->first.c_str(), it->second); 754 builder->AddMetric(it->first.c_str(), it->second);
743 } 755 }
744 756
745 return true; 757 return true;
746 } 758 }
747 759
748 AutofillMetrics::FormEventLogger::FormEventLogger(bool is_for_credit_card) 760 AutofillMetrics::FormEventLogger::FormEventLogger(
761 bool is_for_credit_card,
762 AutofillMetrics::UkmLogger* ukm_logger)
749 : is_for_credit_card_(is_for_credit_card), 763 : is_for_credit_card_(is_for_credit_card),
750 is_server_data_available_(false), 764 is_server_data_available_(false),
751 is_local_data_available_(false), 765 is_local_data_available_(false),
752 is_context_secure_(false), 766 is_context_secure_(false),
753 has_logged_interacted_(false), 767 has_logged_interacted_(false),
754 has_logged_suggestions_shown_(false), 768 has_logged_suggestions_shown_(false),
755 has_logged_masked_server_card_suggestion_selected_(false), 769 has_logged_masked_server_card_suggestion_selected_(false),
756 has_logged_suggestion_filled_(false), 770 has_logged_suggestion_filled_(false),
757 has_logged_will_submit_(false), 771 has_logged_will_submit_(false),
758 has_logged_submitted_(false), 772 has_logged_submitted_(false),
759 logged_suggestion_filled_was_server_data_(false), 773 logged_suggestion_filled_was_server_data_(false),
760 logged_suggestion_filled_was_masked_server_card_(false) {} 774 logged_suggestion_filled_was_masked_server_card_(false),
775 ukm_logger_(ukm_logger) {}
761 776
762 void AutofillMetrics::FormEventLogger::OnDidInteractWithAutofillableForm() { 777 void AutofillMetrics::FormEventLogger::OnDidInteractWithAutofillableForm() {
763 if (!has_logged_interacted_) { 778 if (!has_logged_interacted_) {
764 has_logged_interacted_ = true; 779 has_logged_interacted_ = true;
765 Log(AutofillMetrics::FORM_EVENT_INTERACTED_ONCE); 780 Log(AutofillMetrics::FORM_EVENT_INTERACTED_ONCE);
766 } 781 }
767 } 782 }
768 783
769 void AutofillMetrics::FormEventLogger::OnDidPollSuggestions( 784 void AutofillMetrics::FormEventLogger::OnDidPollSuggestions(
770 const FormFieldData& field) { 785 const FormFieldData& field) {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 // segmentation. http://crbug.com/454018 954 // segmentation. http://crbug.com/454018
940 if (!is_server_data_available_ && !is_local_data_available_) 955 if (!is_server_data_available_ && !is_local_data_available_)
941 name += ".WithNoData"; 956 name += ".WithNoData";
942 else if (is_server_data_available_ && !is_local_data_available_) 957 else if (is_server_data_available_ && !is_local_data_available_)
943 name += ".WithOnlyServerData"; 958 name += ".WithOnlyServerData";
944 else if (!is_server_data_available_ && is_local_data_available_) 959 else if (!is_server_data_available_ && is_local_data_available_)
945 name += ".WithOnlyLocalData"; 960 name += ".WithOnlyLocalData";
946 else 961 else
947 name += ".WithBothServerAndLocalData"; 962 name += ".WithBothServerAndLocalData";
948 LogUMAHistogramEnumeration(name, event, NUM_FORM_EVENTS); 963 LogUMAHistogramEnumeration(name, event, NUM_FORM_EVENTS);
964
965 if (is_for_credit_card_)
966 ukm_logger_->LogCreditCardFormEvent(event);
967 else
968 ukm_logger_->LogAddressFormEvent(event);
969 }
970
971 AutofillMetrics::UkmLogger::UkmLogger(ukm::UkmService* ukm_service)
972 : ukm_service_(ukm_service) {}
973
974 AutofillMetrics::UkmLogger::~UkmLogger() {
975 LogUkm();
976 }
977
978 void AutofillMetrics::UkmLogger::LogAutofillFormSubmittedState(
979 const GURL& source_url,
980 AutofillFormSubmittedState state) {
981 if (source_url != url_) {
982 LOG(ERROR) << "source_url=" << source_url << ", url_=" << url_;
983 url_ = source_url;
984 }
985 metrics_.push_back(
986 std::make_pair(AUTOFILL_FORM_SUBMITTED_STATE, static_cast<int>(state)));
987 }
988
989 void AutofillMetrics::UkmLogger::LogUserHappinessMetric(
990 UserHappinessMetric metric) {
991 metrics_.push_back(
992 std::make_pair(USER_HAPPINESS_METRIC, static_cast<int>(metric)));
993 }
994
995 void AutofillMetrics::UkmLogger::LogAddressFormEvent(FormEvent event) {
996 metrics_.push_back(
997 std::make_pair(ADDRESS_FORM_EVENT, static_cast<int>(event)));
998 }
999
1000 void AutofillMetrics::UkmLogger::LogCreditCardFormEvent(FormEvent event) {
1001 metrics_.push_back(
1002 std::make_pair(CREDIT_CARD_FORM_EVENT, static_cast<int>(event)));
1003 }
1004
1005 void AutofillMetrics::UkmLogger::LogUnmaskPromptEvent(UnmaskPromptEvent event) {
1006 metrics_.push_back(
1007 std::make_pair(UNMASK_PROMPT_EVENT, static_cast<int>(event)));
1008 }
1009
1010 void AutofillMetrics::UkmLogger::LogUkm() {
1011 if (!IsUkmLoggingEnabled() || !ukm_service_ || !url_.is_valid() ||
1012 metrics_.empty()) {
1013 return;
1014 }
1015
1016 int32_t source_id = ukm_service_->GetNewSourceID();
1017 ukm_service_->UpdateSourceURL(source_id, url_);
1018 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder(
1019 source_id, internal::kUKMFormInteractionsEntryName);
1020
1021 for (auto it = metrics_.begin(); it != metrics_.end(); ++it) {
1022 const char* metric_name = nullptr;
1023 switch (it->first) {
1024 case AutofillMetrics::UkmLogger::AUTOFILL_FORM_SUBMITTED_STATE:
1025 metric_name =
1026 internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName;
1027 break;
1028 case AutofillMetrics::UkmLogger::USER_HAPPINESS_METRIC:
1029 metric_name =
1030 internal::kUKMFormInteractionsUserHappinessMetricMetricName;
1031 break;
1032 case AutofillMetrics::UkmLogger::ADDRESS_FORM_EVENT:
1033 metric_name = internal::kUKMFormInteractionsAddressFormEventMetricName;
1034 break;
1035 case AutofillMetrics::UkmLogger::CREDIT_CARD_FORM_EVENT:
1036 metric_name =
1037 internal::kUKMFormInteractionsCreditCardFormEventMetricName;
1038 break;
1039 case AutofillMetrics::UkmLogger::UNMASK_PROMPT_EVENT:
1040 metric_name = internal::kUKMFormInteractionsUnmaskPromptEventMetricName;
1041 break;
1042 default:
1043 NOTREACHED();
1044 }
1045 builder->AddMetric(metric_name, it->second);
1046 }
949 } 1047 }
950 1048
951 } // namespace autofill 1049 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698