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

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

Issue 2800853004: UKM that threads together multiple form interaction events. (Closed)
Patch Set: Uses size_t for local and server record type count. 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 #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>
11 #include <vector>
10 12
11 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/time/time.h"
12 #include "components/autofill/core/browser/autofill_client.h" 15 #include "components/autofill/core/browser/autofill_client.h"
13 #include "components/autofill/core/browser/autofill_profile.h" 16 #include "components/autofill/core/browser/autofill_profile.h"
14 #include "components/autofill/core/browser/credit_card.h" 17 #include "components/autofill/core/browser/credit_card.h"
15 #include "components/autofill/core/browser/field_types.h" 18 #include "components/autofill/core/browser/field_types.h"
16 #include "components/autofill/core/common/form_field_data.h" 19 #include "components/autofill/core/common/form_field_data.h"
17 20
18 namespace base {
19 class TimeDelta;
20 } // namespace base
21
22 namespace ukm { 21 namespace ukm {
23 class UkmService; 22 class UkmService;
24 } // namespace ukm 23 } // namespace ukm
25 24
26 namespace internal { 25 namespace internal {
27 // Name constants are exposed here so they can be referenced from tests. 26 // Name constants are exposed here so they can be referenced from tests.
28 extern const char kUKMCardUploadDecisionEntryName[]; 27 extern const char kUKMCardUploadDecisionEntryName[];
29 extern const char kUKMCardUploadDecisionMetricName[]; 28 extern const char kUKMCardUploadDecisionMetricName[];
30 extern const char kUKMDeveloperEngagementEntryName[]; 29 extern const char kUKMDeveloperEngagementEntryName[];
31 extern const char kUKMDeveloperEngagementMetricName[]; 30 extern const char kUKMDeveloperEngagementMetricName[];
31
32 // Each form interaction event has a separate |UkmEntry|.
33
34 // The first form event |UkmEntry| contains metrics for metadata that apply
35 // to all subsequent events.
36 extern const char kUKMInteractedWithFormEntryName[];
37 extern const char kUKMIsForCreditCardMetricName[];
38 extern const char kUKMLocalRecordTypeCountMetricName[];
39 extern const char kUKMServerRecordTypeCountMetricName[];
40
41 // |UkmEntry| when we show suggestions.
42 extern const char kUKMSuggestionsShownEntryName[];
43
44 // |UkmEntry| when user selects a masked server credit card.
45 extern const char kUKMSelectedMaskedServerCardEntryName[];
46
47 // Each |UkmEntry|, except the first interaction with the form, has a metric for
48 // time elapsed, in milliseconds, since we loaded the form.
49 extern const char kUKMMillisecondsSinceFormLoadedMetricName[];
50
51 // |FormEvent| for FORM_EVENT_*_SUGGESTION_FILLED in credit card forms include a
52 // |CreditCard| |record_type()| to indicate if the suggestion was for a local
53 // card, masked server card or full server card. Similarly, address/profile
54 // forms include a |AutofillProfile| |record_type()| to indicate if the
55 // profile was a local profile or server profile.
56 extern const char kUKMSuggestionFilledEntryName[];
57 extern const char kUKMRecordTypeMetricName[];
58
59 // |UkmEntry| for user editing text field. Metrics contain field's attributes.
60 extern const char kUKMTextFieldDidChangeEntryName[];
61 extern const char kUKMFieldTypeGroupMetricName[];
62 extern const char kUKMHeuristicTypeMetricName[];
63 extern const char kUKMServerTypeMetricName[];
64 extern const char kUKMHtmlFieldTypeMetricName[];
65 extern const char kUKMHtmlFieldModeMetricName[];
66 extern const char kUKMIsAutofilledMetricName[];
67 extern const char kUKMIsEmptyMetricName[];
68
69 // |UkmEntry| for |AutofillFormSubmittedState|.
70 extern const char kUKMFormSubmittedEntryName[];
71 extern const char kUKMAutofillFormSubmittedStateMetricName[];
32 } // namespace internal 72 } // namespace internal
33 73
34 namespace autofill { 74 namespace autofill {
35 75
76 class AutofillField;
77
36 class AutofillMetrics { 78 class AutofillMetrics {
37 public: 79 public:
38 enum AutofillProfileAction { 80 enum AutofillProfileAction {
39 EXISTING_PROFILE_USED, 81 EXISTING_PROFILE_USED,
40 EXISTING_PROFILE_UPDATED, 82 EXISTING_PROFILE_UPDATED,
41 NEW_PROFILE_CREATED, 83 NEW_PROFILE_CREATED,
42 AUTOFILL_PROFILE_ACTION_ENUM_SIZE, 84 AUTOFILL_PROFILE_ACTION_ENUM_SIZE,
43 }; 85 };
44 86
45 enum AutofillFormSubmittedState { 87 enum AutofillFormSubmittedState {
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 601
560 // For mesuring how wallet addresses are converted to local profiles. 602 // For mesuring how wallet addresses are converted to local profiles.
561 enum WalletAddressConversionType : int { 603 enum WalletAddressConversionType : int {
562 // The converted wallet address was merged into an existing local profile. 604 // The converted wallet address was merged into an existing local profile.
563 CONVERTED_ADDRESS_MERGED, 605 CONVERTED_ADDRESS_MERGED,
564 // The converted wallet address was added as a new local profile. 606 // The converted wallet address was added as a new local profile.
565 CONVERTED_ADDRESS_ADDED, 607 CONVERTED_ADDRESS_ADDED,
566 NUM_CONVERTED_ADDRESS_CONVERSION_TYPES 608 NUM_CONVERTED_ADDRESS_CONVERSION_TYPES
567 }; 609 };
568 610
611 // Utility to log URL keyed form interaction events.
612 class FormInteractionsUkmLogger {
613 public:
614 explicit FormInteractionsUkmLogger(ukm::UkmService* ukm_service);
615
616 const GURL& url() const { return url_; }
617
618 void OnFormsLoaded(const GURL& url);
619 void LogInteractedWithForm(bool is_for_credit_card,
620 size_t local_record_type_count,
621 size_t server_record_type_count);
622 void LogSuggestionsShown();
623 void LogSelectedMaskedServerCard();
624 void LogDidFillSuggestion(int record_type);
625 void LogTextFieldDidChange(const AutofillField& field);
626 void LogFormSubmitted(AutofillFormSubmittedState state);
627
628 // We initialize |url_| with the form's URL when we log the first form
629 // interaction. Later, we may update |url_| with the |source_url()| for the
630 // submitted form.
631 void UpdateSourceURL(const GURL& url);
632
633 private:
634 bool CanLog() const;
635 int64_t MillisecondsSinceFormLoaded() const;
636 void GetNewSourceID();
637
638 ukm::UkmService* ukm_service_; // Weak reference.
639 int32_t source_id_ = -1;
640 GURL url_;
641 base::TimeTicks form_loaded_timestamp_;
642 };
643
569 static void LogCardUploadDecisionMetric(CardUploadDecisionMetric metric); 644 static void LogCardUploadDecisionMetric(CardUploadDecisionMetric metric);
570 static void LogCreditCardInfoBarMetric(InfoBarMetric metric, 645 static void LogCreditCardInfoBarMetric(InfoBarMetric metric,
571 bool is_uploading); 646 bool is_uploading);
572 static void LogCreditCardFillingInfoBarMetric(InfoBarMetric metric); 647 static void LogCreditCardFillingInfoBarMetric(InfoBarMetric metric);
573 static void LogSaveCardPromptMetric(SaveCardPromptMetric metric, 648 static void LogSaveCardPromptMetric(SaveCardPromptMetric metric,
574 bool is_uploading, 649 bool is_uploading,
575 bool is_reshow); 650 bool is_reshow);
576 static void LogScanCreditCardPromptMetric(ScanCreditCardPromptMetric metric); 651 static void LogScanCreditCardPromptMetric(ScanCreditCardPromptMetric metric);
577 652
578 // Should be called when credit card scan is finished. |duration| should be 653 // Should be called when credit card scan is finished. |duration| should be
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 760
686 // This should be called each time a server response is parsed for a form. 761 // This should be called each time a server response is parsed for a form.
687 static void LogServerResponseHasDataForForm(bool has_data); 762 static void LogServerResponseHasDataForForm(bool has_data);
688 763
689 // This should be called at each form submission to indicate what profile 764 // This should be called at each form submission to indicate what profile
690 // action happened. 765 // action happened.
691 static void LogProfileActionOnFormSubmitted(AutofillProfileAction action); 766 static void LogProfileActionOnFormSubmitted(AutofillProfileAction action);
692 767
693 // This should be called at each form submission to indicate the autofilled 768 // This should be called at each form submission to indicate the autofilled
694 // state of the form. 769 // state of the form.
695 static void LogAutofillFormSubmittedState(AutofillFormSubmittedState state); 770 static void LogAutofillFormSubmittedState(
771 AutofillFormSubmittedState state,
772 FormInteractionsUkmLogger* form_interactions_ukm_logger);
696 773
697 // This should be called when determining the heuristic types for a form's 774 // This should be called when determining the heuristic types for a form's
698 // fields. 775 // fields.
699 static void LogDetermineHeuristicTypesTiming(const base::TimeDelta& duration); 776 static void LogDetermineHeuristicTypesTiming(const base::TimeDelta& duration);
700 777
701 // This should be called when parsing each form. 778 // This should be called when parsing each form.
702 static void LogParseFormTiming(const base::TimeDelta& duration); 779 static void LogParseFormTiming(const base::TimeDelta& duration);
703 780
704 // Log how many profiles were considered for the deduplication process. 781 // Log how many profiles were considered for the deduplication process.
705 static void LogNumberOfProfilesConsideredForDedupe(size_t num_considered); 782 static void LogNumberOfProfilesConsideredForDedupe(size_t num_considered);
(...skipping 18 matching lines...) Expand all
724 static void LogCardUploadDecisionUkm( 801 static void LogCardUploadDecisionUkm(
725 ukm::UkmService* ukm_service, 802 ukm::UkmService* ukm_service,
726 const GURL& url, 803 const GURL& url,
727 AutofillMetrics::CardUploadDecisionMetric upload_decision); 804 AutofillMetrics::CardUploadDecisionMetric upload_decision);
728 805
729 // Logs the developer engagement ukm for the specified |url| and autofill 806 // Logs the developer engagement ukm for the specified |url| and autofill
730 // fields in the form structure. 807 // fields in the form structure.
731 static void LogDeveloperEngagementUkm( 808 static void LogDeveloperEngagementUkm(
732 ukm::UkmService* ukm_service, 809 ukm::UkmService* ukm_service,
733 const GURL& url, 810 const GURL& url,
734 AutofillMetrics::DeveloperEngagementMetric metric); 811 std::vector<AutofillMetrics::DeveloperEngagementMetric> metrics);
735 812
736 // Logs the the |ukm_entry_name| with the specified |url| and the specified 813 // Logs the the |ukm_entry_name| with the specified |url| and the specified
737 // |metrics|. Returns whether the ukm was sucessfully logged. 814 // |metrics|. Returns whether the ukm was sucessfully logged.
738 static bool LogUkm(ukm::UkmService* ukm_service, 815 static bool LogUkm(ukm::UkmService* ukm_service,
739 const GURL& url, 816 const GURL& url,
740 const std::string& ukm_entry_name, 817 const std::string& ukm_entry_name,
741 const std::map<std::string, int>& metrics); 818 const std::vector<std::pair<const char*, int>>& metrics);
742 819
743 // Utility to autofill form events in the relevant histograms depending on 820 // Utility to log autofill form events in the relevant histograms depending on
744 // the presence of server and/or local data. 821 // the presence of server and/or local data.
745 class FormEventLogger { 822 class FormEventLogger {
746 public: 823 public:
747 FormEventLogger(bool is_for_credit_card); 824 FormEventLogger(bool is_for_credit_card,
825 FormInteractionsUkmLogger* form_interactions_ukm_logger);
748 826
749 inline void set_is_server_data_available(bool is_server_data_available) { 827 inline void set_server_record_type_count(size_t server_record_type_count) {
750 is_server_data_available_ = is_server_data_available; 828 server_record_type_count_ = server_record_type_count;
751 } 829 }
752 830
753 inline void set_is_local_data_available(bool is_local_data_available) { 831 inline void set_local_record_type_count(size_t local_record_type_count) {
754 is_local_data_available_ = is_local_data_available; 832 local_record_type_count_ = local_record_type_count;
755 } 833 }
756 834
757 inline void set_is_context_secure(bool is_context_secure) { 835 inline void set_is_context_secure(bool is_context_secure) {
758 is_context_secure_ = is_context_secure; 836 is_context_secure_ = is_context_secure;
759 } 837 }
760 838
761 void OnDidInteractWithAutofillableForm(); 839 void OnDidInteractWithAutofillableForm();
762 840
763 void OnDidPollSuggestions(const FormFieldData& field); 841 void OnDidPollSuggestions(const FormFieldData& field);
764 842
765 void OnDidShowSuggestions(); 843 void OnDidShowSuggestions();
766 844
767 void OnDidSelectMaskedServerCardSuggestion(); 845 void OnDidSelectMaskedServerCardSuggestion();
768 846
769 // In case of masked cards, caller must make sure this gets called before 847 // In case of masked cards, caller must make sure this gets called before
770 // the card is upgraded to a full card. 848 // the card is upgraded to a full card.
771 void OnDidFillSuggestion(const CreditCard& credit_card); 849 void OnDidFillSuggestion(const CreditCard& credit_card);
772 850
773 void OnDidFillSuggestion(const AutofillProfile& profile); 851 void OnDidFillSuggestion(const AutofillProfile& profile);
774 852
775 void OnWillSubmitForm(); 853 void OnWillSubmitForm();
776 854
777 void OnFormSubmitted(); 855 void OnFormSubmitted();
778 856
779 private: 857 private:
780 void Log(FormEvent event) const; 858 void Log(FormEvent event) const;
781 859
782 bool is_for_credit_card_; 860 bool is_for_credit_card_;
783 bool is_server_data_available_; 861 size_t server_record_type_count_;
784 bool is_local_data_available_; 862 size_t local_record_type_count_;
785 bool is_context_secure_; 863 bool is_context_secure_;
786 bool has_logged_interacted_; 864 bool has_logged_interacted_;
787 bool has_logged_suggestions_shown_; 865 bool has_logged_suggestions_shown_;
788 bool has_logged_masked_server_card_suggestion_selected_; 866 bool has_logged_masked_server_card_suggestion_selected_;
789 bool has_logged_suggestion_filled_; 867 bool has_logged_suggestion_filled_;
790 bool has_logged_will_submit_; 868 bool has_logged_will_submit_;
791 bool has_logged_submitted_; 869 bool has_logged_submitted_;
792 bool logged_suggestion_filled_was_server_data_; 870 bool logged_suggestion_filled_was_server_data_;
793 bool logged_suggestion_filled_was_masked_server_card_; 871 bool logged_suggestion_filled_was_masked_server_card_;
794 872
795 // The last field that was polled for suggestions. 873 // The last field that was polled for suggestions.
796 FormFieldData last_polled_field_; 874 FormFieldData last_polled_field_;
875
876 FormInteractionsUkmLogger*
877 form_interactions_ukm_logger_; // Weak reference.
797 }; 878 };
798 879
799 private: 880 private:
800 DISALLOW_IMPLICIT_CONSTRUCTORS(AutofillMetrics); 881 DISALLOW_IMPLICIT_CONSTRUCTORS(AutofillMetrics);
801 }; 882 };
802 883
803 } // namespace autofill 884 } // namespace autofill
804 885
805 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_ 886 #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