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

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

Issue 2940983003: [autofill] Add UKM for field type prediction quality and autofill outcome. (Closed)
Patch Set: fix a comment Created 3 years, 5 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 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_ 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_ 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/strings/string_piece_forward.h"
15 #include "base/time/time.h" 14 #include "base/time/time.h"
16 #include "components/autofill/core/browser/autofill_client.h" 15 #include "components/autofill/core/browser/autofill_client.h"
17 #include "components/autofill/core/browser/autofill_profile.h" 16 #include "components/autofill/core/browser/autofill_profile.h"
18 #include "components/autofill/core/browser/credit_card.h" 17 #include "components/autofill/core/browser/credit_card.h"
19 #include "components/autofill/core/browser/field_types.h" 18 #include "components/autofill/core/browser/field_types.h"
20 #include "components/autofill/core/common/autofill_pref_names.h" 19 #include "components/autofill/core/common/autofill_pref_names.h"
21 #include "components/autofill/core/common/form_field_data.h" 20 #include "components/autofill/core/common/form_field_data.h"
21 #include "components/autofill/core/common/signatures_util.h"
22 #include "components/ukm/public/ukm_recorder.h" 22 #include "components/ukm/public/ukm_recorder.h"
23 23
24 namespace internal { 24 namespace internal {
25 // Name constants are exposed here so they can be referenced from tests. 25 // Name constants are exposed here so they can be referenced from tests.
26 extern const char kUKMCardUploadDecisionEntryName[]; 26 extern const char kUKMCardUploadDecisionEntryName[];
27 extern const char kUKMCardUploadDecisionMetricName[]; 27 extern const char kUKMCardUploadDecisionMetricName[];
28 extern const char kUKMDeveloperEngagementEntryName[]; 28 extern const char kUKMDeveloperEngagementEntryName[];
29 extern const char kUKMDeveloperEngagementMetricName[]; 29 extern const char kUKMDeveloperEngagementMetricName[];
30 30
31 // Each form interaction event has a separate |UkmEntry|. 31 // Each form interaction event has a separate |UkmEntry|.
(...skipping 30 matching lines...) Expand all
62 // |UkmEntry| for user editing text field. Metrics contain field's attributes. 62 // |UkmEntry| for user editing text field. Metrics contain field's attributes.
63 extern const char kUKMTextFieldDidChangeEntryName[]; 63 extern const char kUKMTextFieldDidChangeEntryName[];
64 extern const char kUKMFieldTypeGroupMetricName[]; 64 extern const char kUKMFieldTypeGroupMetricName[];
65 extern const char kUKMHtmlFieldModeMetricName[]; 65 extern const char kUKMHtmlFieldModeMetricName[];
66 extern const char kUKMIsAutofilledMetricName[]; 66 extern const char kUKMIsAutofilledMetricName[];
67 extern const char kUKMIsEmptyMetricName[]; 67 extern const char kUKMIsEmptyMetricName[];
68 68
69 // |UkmEntry| for |AutofillFormSubmittedState|. 69 // |UkmEntry| for |AutofillFormSubmittedState|.
70 extern const char kUKMFormSubmittedEntryName[]; 70 extern const char kUKMFormSubmittedEntryName[];
71 extern const char kUKMAutofillFormSubmittedStateMetricName[]; 71 extern const char kUKMAutofillFormSubmittedStateMetricName[];
72
73 // |UkmEntry| for capturing field fill status and type prediction quality.
74 extern const char kUKMFieldTypeEntryName[];
75 extern const char kUKMFieldFillStatusEntryName[];
76 extern const char kUKMFormSignatureMetricName[];
77 extern const char kUKMFieldSignatureMetricName[];
78 extern const char kUKMValidationEventMetricName[];
79 extern const char kUKMPredictionSourceMetricName[];
80 extern const char kUKMPredictedTypeMetricName[];
81 extern const char kUKMActualTypeMetricName[];
82 extern const char kUKMWasSuggestionShownMetricName[];
83 extern const char kUKMWasPreviouslyAutofilledMetricName[];
84
72 } // namespace internal 85 } // namespace internal
73 86
74 namespace autofill { 87 namespace autofill {
75 88
76 class AutofillField; 89 class AutofillField;
77 90
78 class AutofillMetrics { 91 class AutofillMetrics {
79 public: 92 public:
80 enum AutofillProfileAction { 93 enum AutofillProfileAction {
81 EXISTING_PROFILE_USED, 94 EXISTING_PROFILE_USED,
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 // UNKNOWN not in (T,U). 417 // UNKNOWN not in (T,U).
405 // 418 //
406 // This is captured as a type-specific log entry for T. Is is also captured 419 // This is captured as a type-specific log entry for T. Is is also captured
407 // as an aggregate (non-type-specific) log entry. 420 // as an aggregate (non-type-specific) log entry.
408 FALSE_NEGATIVE_MISMATCH, 421 FALSE_NEGATIVE_MISMATCH,
409 422
410 // This must be last. 423 // This must be last.
411 NUM_FIELD_TYPE_QUALITY_METRICS 424 NUM_FIELD_TYPE_QUALITY_METRICS
412 }; 425 };
413 426
427 enum QualityMetricPredictionSource {
428 PREDICTION_SOURCE_UNKNOWN, // Not used. The prediction source is unknown.
429 PREDICTION_SOURCE_HEURISTIC, // Local heuristic field-type prediction.
430 PREDICTION_SOURCE_SERVER, // Crowd-sourced server field type prediction.
431 PREDICTION_SOURCE_OVERALL, // Overall field-type prediction seen by user.
432 NUM_QUALITY_METRIC_SOURCES
433 };
434
414 enum QualityMetricType { 435 enum QualityMetricType {
415 TYPE_SUBMISSION = 0, // Logged based on user's submitted data. 436 TYPE_SUBMISSION = 0, // Logged based on user's submitted data.
416 TYPE_NO_SUBMISSION, // Logged based on user's entered data. 437 TYPE_NO_SUBMISSION, // Logged based on user's entered data.
417 TYPE_AUTOCOMPLETE_BASED, // Logged based on the value of autocomplete attr. 438 TYPE_AUTOCOMPLETE_BASED, // Logged based on the value of autocomplete attr.
418 NUM_QUALITY_METRIC_TYPES, 439 NUM_QUALITY_METRIC_TYPES,
419 }; 440 };
420 441
421 // Each of these is logged at most once per query to the server, which in turn 442 // Each of these is logged at most once per query to the server, which in turn
422 // occurs at most once per page load. 443 // occurs at most once per page load.
423 enum ServerQueryMetric { 444 enum ServerQueryMetric {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 // The converted wallet address was added as a new local profile. 711 // The converted wallet address was added as a new local profile.
691 CONVERTED_ADDRESS_ADDED, 712 CONVERTED_ADDRESS_ADDED,
692 NUM_CONVERTED_ADDRESS_CONVERSION_TYPES 713 NUM_CONVERTED_ADDRESS_CONVERSION_TYPES
693 }; 714 };
694 715
695 // Utility to log URL keyed form interaction events. 716 // Utility to log URL keyed form interaction events.
696 class FormInteractionsUkmLogger { 717 class FormInteractionsUkmLogger {
697 public: 718 public:
698 explicit FormInteractionsUkmLogger(ukm::UkmRecorder* ukm_recorder); 719 explicit FormInteractionsUkmLogger(ukm::UkmRecorder* ukm_recorder);
699 720
721 bool has_pinned_timestamp() const { return !pinned_timestamp_.is_null(); }
722 void set_pinned_timestamp(base::TimeTicks t) { pinned_timestamp_ = t; }
723
700 const GURL& url() const { return url_; } 724 const GURL& url() const { return url_; }
701 725
702 void OnFormsParsed(const GURL& url); 726 void OnFormsParsed(const GURL& url);
703 void LogInteractedWithForm(bool is_for_credit_card, 727 void LogInteractedWithForm(bool is_for_credit_card,
704 size_t local_record_type_count, 728 size_t local_record_type_count,
705 size_t server_record_type_count); 729 size_t server_record_type_count);
706 void LogSuggestionsShown(const AutofillField& field); 730 void LogSuggestionsShown(const AutofillField& field);
707 void LogSelectedMaskedServerCard(); 731 void LogSelectedMaskedServerCard();
708 void LogDidFillSuggestion(int record_type); 732 void LogDidFillSuggestion(int record_type);
709 void LogTextFieldDidChange(const AutofillField& field); 733 void LogTextFieldDidChange(const AutofillField& field);
734 void LogFieldFillStatus(const FormStructure& form,
735 const AutofillField& field,
736 QualityMetricType metric_type);
737 void LogFieldType(FormSignature form_signature,
738 FieldSignature field_signature,
739 QualityMetricPredictionSource prediction_source,
740 QualityMetricType metric_type,
741 ServerFieldType predicted_type,
742 ServerFieldType actual_type);
710 void LogFormSubmitted(AutofillFormSubmittedState state); 743 void LogFormSubmitted(AutofillFormSubmittedState state);
711 744
712 // We initialize |url_| with the form's URL when we log the first form 745 // We initialize |url_| with the form's URL when we log the first form
713 // interaction. Later, we may update |url_| with the |source_url()| for the 746 // interaction. Later, we may update |url_| with the |source_url()| for the
714 // submitted form. 747 // submitted form.
715 void UpdateSourceURL(const GURL& url); 748 void UpdateSourceURL(const GURL& url);
716 749
717 private: 750 private:
718 bool CanLog() const; 751 bool CanLog() const;
719 int64_t MillisecondsSinceFormParsed() const; 752 int64_t MillisecondsSinceFormParsed() const;
720 void GetNewSourceID(); 753 void GetNewSourceID();
721 754
722 ukm::UkmRecorder* ukm_recorder_; // Weak reference. 755 ukm::UkmRecorder* ukm_recorder_; // Weak reference.
723 ukm::SourceId source_id_ = -1; 756 ukm::SourceId source_id_ = -1;
724 GURL url_; 757 GURL url_;
725 base::TimeTicks form_parsed_timestamp_; 758 base::TimeTicks form_parsed_timestamp_;
759 base::TimeTicks pinned_timestamp_;
760 };
761
762 // Utility class to pin the timestamp used by the FormInteractionsUkmLogger
763 // while an instance of this class is in scope. Pinned timestamps cannot be
764 // nested.
765 class UkmTimestampPin {
766 public:
767 UkmTimestampPin(FormInteractionsUkmLogger* logger);
768 ~UkmTimestampPin();
769
770 private:
771 FormInteractionsUkmLogger* const logger_;
772 DISALLOW_IMPLICIT_CONSTRUCTORS(UkmTimestampPin);
726 }; 773 };
727 774
728 // |upload_decision_metrics| is a bitmask of |CardUploadDecisionMetric|. 775 // |upload_decision_metrics| is a bitmask of |CardUploadDecisionMetric|.
729 static void LogCardUploadDecisionMetrics(int upload_decision_metrics); 776 static void LogCardUploadDecisionMetrics(int upload_decision_metrics);
730 static void LogCreditCardInfoBarMetric( 777 static void LogCreditCardInfoBarMetric(
731 InfoBarMetric metric, 778 InfoBarMetric metric,
732 bool is_uploading, 779 bool is_uploading,
733 int previous_save_credit_card_prompt_user_decision); 780 int previous_save_credit_card_prompt_user_decision);
734 static void LogCreditCardFillingInfoBarMetric(InfoBarMetric metric); 781 static void LogCreditCardFillingInfoBarMetric(InfoBarMetric metric);
735 static void LogSaveCardPromptMetric( 782 static void LogSaveCardPromptMetric(
736 SaveCardPromptMetric metric, 783 SaveCardPromptMetric metric,
737 bool is_uploading, 784 bool is_uploading,
738 bool is_reshow, 785 bool is_reshow,
739 int previous_save_credit_card_prompt_user_decision); 786 int previous_save_credit_card_prompt_user_decision);
740 static void LogScanCreditCardPromptMetric(ScanCreditCardPromptMetric metric); 787 static void LogScanCreditCardPromptMetric(ScanCreditCardPromptMetric metric);
741 788
742 // Should be called when credit card scan is finished. |duration| should be 789 // Should be called when credit card scan is finished. |duration| should be
743 // the time elapsed between launching the credit card scanner and getting back 790 // the time elapsed between launching the credit card scanner and getting back
744 // the result. |completed| should be true if a credit card was scanned, false 791 // the result. |completed| should be true if a credit card was scanned, false
745 // if the scan was cancelled. 792 // if the scan was cancelled.
746 static void LogScanCreditCardCompleted(const base::TimeDelta& duration, 793 static void LogScanCreditCardCompleted(const base::TimeDelta& duration,
747 bool completed); 794 bool completed);
748 795
749 static void LogDeveloperEngagementMetric(DeveloperEngagementMetric metric); 796 static void LogDeveloperEngagementMetric(DeveloperEngagementMetric metric);
750 797
751 static void LogHeuristicPredictionQualityMetrics( 798 static void LogHeuristicPredictionQualityMetrics(
752 const ServerFieldTypeSet& possible_types, 799 FormInteractionsUkmLogger* form_interactions_ukm_logger,
753 ServerFieldType predicted_type, 800 const FormStructure& form,
801 const AutofillField& field,
754 QualityMetricType metric_type); 802 QualityMetricType metric_type);
755 static void LogServerPredictionQualityMetrics( 803 static void LogServerPredictionQualityMetrics(
756 const ServerFieldTypeSet& possible_types, 804 FormInteractionsUkmLogger* form_interactions_ukm_logger,
757 ServerFieldType predicted_type, 805 const FormStructure& form,
806 const AutofillField& field,
758 QualityMetricType metric_type); 807 QualityMetricType metric_type);
759 static void LogOverallPredictionQualityMetrics( 808 static void LogOverallPredictionQualityMetrics(
760 const ServerFieldTypeSet& possible_types, 809 FormInteractionsUkmLogger* form_interactions_ukm_logger,
761 ServerFieldType predicted_type, 810 const FormStructure& form,
811 const AutofillField& field,
762 QualityMetricType metric_type); 812 QualityMetricType metric_type);
763 813
764 static void LogServerQueryMetric(ServerQueryMetric metric); 814 static void LogServerQueryMetric(ServerQueryMetric metric);
765 815
766 static void LogUserHappinessMetric(UserHappinessMetric metric); 816 static void LogUserHappinessMetric(UserHappinessMetric metric);
767 817
768 // Logs |event| to the unmask prompt events histogram. 818 // Logs |event| to the unmask prompt events histogram.
769 static void LogUnmaskPromptEvent(UnmaskPromptEvent event); 819 static void LogUnmaskPromptEvent(UnmaskPromptEvent event);
770 820
771 // Logs the time elapsed between the unmask prompt being shown and it 821 // Logs the time elapsed between the unmask prompt being shown and it
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 1029
980 private: 1030 private:
981 static const int kNumCardUploadDecisionMetrics = 12; 1031 static const int kNumCardUploadDecisionMetrics = 12;
982 1032
983 DISALLOW_IMPLICIT_CONSTRUCTORS(AutofillMetrics); 1033 DISALLOW_IMPLICIT_CONSTRUCTORS(AutofillMetrics);
984 }; 1034 };
985 1035
986 } // namespace autofill 1036 } // namespace autofill
987 1037
988 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_ 1038 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | components/autofill/core/browser/autofill_metrics.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698