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

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

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 #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>
9 #include <vector>
8 10
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
11 #include "base/metrics/sparse_histogram.h" 13 #include "base/metrics/sparse_histogram.h"
12 #include "base/metrics/user_metrics.h" 14 #include "base/metrics/user_metrics.h"
13 #include "base/time/time.h" 15 #include "base/time/time.h"
14 #include "components/autofill/core/browser/autofill_experiments.h" 16 #include "components/autofill/core/browser/autofill_experiments.h"
17 #include "components/autofill/core/browser/autofill_field.h"
15 #include "components/autofill/core/browser/autofill_type.h" 18 #include "components/autofill/core/browser/autofill_type.h"
16 #include "components/autofill/core/browser/form_structure.h" 19 #include "components/autofill/core/browser/form_structure.h"
17 #include "components/autofill/core/common/form_data.h" 20 #include "components/autofill/core/common/form_data.h"
18 #include "components/ukm/ukm_entry_builder.h" 21 #include "components/ukm/ukm_entry_builder.h"
19 22
20 namespace internal { 23 namespace internal {
21 const char kUKMCardUploadDecisionEntryName[] = "Autofill.CardUploadDecision"; 24 const char kUKMCardUploadDecisionEntryName[] = "Autofill.CardUploadDecision";
22 const char kUKMCardUploadDecisionMetricName[] = "UploadDecision"; 25 const char kUKMCardUploadDecisionMetricName[] = "UploadDecision";
23 const char kUKMDeveloperEngagementEntryName[] = "Autofill.DeveloperEngagement"; 26 const char kUKMDeveloperEngagementEntryName[] = "Autofill.DeveloperEngagement";
24 const char kUKMDeveloperEngagementMetricName[] = "DeveloperEngagement"; 27 const char kUKMDeveloperEngagementMetricName[] = "DeveloperEngagement";
28 const char kUKMMillisecondsSinceFormLoadedMetricName[] =
29 "MillisecondsSinceFormLoaded";
30 const char kUKMInteractedWithFormEntryName[] = "Autofill.InteractedWithForm";
31 const char kUKMIsForCreditCardMetricName[] = "IsForCreditCard";
32 const char kUKMLocalRecordTypeCountMetricName[] = "LocalRecordTypeCount";
33 const char kUKMServerRecordTypeCountMetricName[] = "ServerRecordTypeCount";
34 const char kUKMSuggestionsShownEntryName[] = "Autofill.SuggestionsShown";
35 const char kUKMSelectedMaskedServerCardEntryName[] =
36 "Autofill.SelectedMaskedServerCard";
37 const char kUKMSuggestionFilledEntryName[] = "Autofill.SuggestionFilled";
38 const char kUKMRecordTypeMetricName[] = "RecordType";
39 const char kUKMTextFieldDidChangeEntryName[] = "Autofill.TextFieldDidChange";
40 const char kUKMFieldTypeGroupMetricName[] = "FieldTypeGroup";
41 const char kUKMHeuristicTypeMetricName[] = "HeuristicType";
42 const char kUKMServerTypeMetricName[] = "ServerType";
43 const char kUKMHtmlFieldTypeMetricName[] = "HtmlFieldType";
44 const char kUKMHtmlFieldModeMetricName[] = "HtmlFieldMode";
45 const char kUKMIsAutofilledMetricName[] = "IsAutofilled";
46 const char kUKMIsEmptyMetricName[] = "IsEmpty";
47 const char kUKMFormSubmittedEntryName[] = "Autofill.AutofillFormSubmitted";
48 const char kUKMAutofillFormSubmittedStateMetricName[] =
49 "AutofillFormSubmittedState";
25 } // namespace internal 50 } // namespace internal
26 51
27 namespace autofill { 52 namespace autofill {
28 53
29 namespace { 54 namespace {
30 55
31 // Note: if adding an enum value here, update the corresponding description for 56 // Note: if adding an enum value here, update the corresponding description for
32 // AutofillTypeQualityByFieldType in histograms.xml. 57 // AutofillTypeQualityByFieldType in histograms.xml.
33 enum FieldTypeGroupForMetrics { 58 enum FieldTypeGroupForMetrics {
34 GROUP_AMBIGUOUS = 0, 59 GROUP_AMBIGUOUS = 0,
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 634
610 // static 635 // static
611 void AutofillMetrics::LogProfileActionOnFormSubmitted( 636 void AutofillMetrics::LogProfileActionOnFormSubmitted(
612 AutofillProfileAction action) { 637 AutofillProfileAction action) {
613 UMA_HISTOGRAM_ENUMERATION("Autofill.ProfileActionOnFormSubmitted", action, 638 UMA_HISTOGRAM_ENUMERATION("Autofill.ProfileActionOnFormSubmitted", action,
614 AUTOFILL_PROFILE_ACTION_ENUM_SIZE); 639 AUTOFILL_PROFILE_ACTION_ENUM_SIZE);
615 } 640 }
616 641
617 // static 642 // static
618 void AutofillMetrics::LogAutofillFormSubmittedState( 643 void AutofillMetrics::LogAutofillFormSubmittedState(
619 AutofillFormSubmittedState state) { 644 AutofillFormSubmittedState state,
645 AutofillMetrics::FormInteractionsUkmLogger* form_interactions_ukm_logger) {
620 UMA_HISTOGRAM_ENUMERATION("Autofill.FormSubmittedState", state, 646 UMA_HISTOGRAM_ENUMERATION("Autofill.FormSubmittedState", state,
621 AUTOFILL_FORM_SUBMITTED_STATE_ENUM_SIZE); 647 AUTOFILL_FORM_SUBMITTED_STATE_ENUM_SIZE);
622 648
623 switch (state) { 649 switch (state) {
624 case NON_FILLABLE_FORM_OR_NEW_DATA: 650 case NON_FILLABLE_FORM_OR_NEW_DATA:
625 base::RecordAction( 651 base::RecordAction(
626 base::UserMetricsAction("Autofill_FormSubmitted_NonFillable")); 652 base::UserMetricsAction("Autofill_FormSubmitted_NonFillable"));
627 break; 653 break;
628 654
629 case FILLABLE_FORM_AUTOFILLED_ALL: 655 case FILLABLE_FORM_AUTOFILLED_ALL:
(...skipping 13 matching lines...) Expand all
643 669
644 case FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS: 670 case FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS:
645 base::RecordAction(base::UserMetricsAction( 671 base::RecordAction(base::UserMetricsAction(
646 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown")); 672 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown"));
647 break; 673 break;
648 674
649 default: 675 default:
650 NOTREACHED(); 676 NOTREACHED();
651 break; 677 break;
652 } 678 }
679 form_interactions_ukm_logger->LogFormSubmitted(state);
653 } 680 }
654 681
655 // static 682 // static
656 void AutofillMetrics::LogDetermineHeuristicTypesTiming( 683 void AutofillMetrics::LogDetermineHeuristicTypesTiming(
657 const base::TimeDelta& duration) { 684 const base::TimeDelta& duration) {
658 UMA_HISTOGRAM_TIMES("Autofill.Timing.DetermineHeuristicTypes", duration); 685 UMA_HISTOGRAM_TIMES("Autofill.Timing.DetermineHeuristicTypes", duration);
659 } 686 }
660 687
661 // static 688 // static
662 void AutofillMetrics::LogParseFormTiming(const base::TimeDelta& duration) { 689 void AutofillMetrics::LogParseFormTiming(const base::TimeDelta& duration) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 } 726 }
700 727
701 // static 728 // static
702 void AutofillMetrics::LogCardUploadDecisionUkm( 729 void AutofillMetrics::LogCardUploadDecisionUkm(
703 ukm::UkmService* ukm_service, 730 ukm::UkmService* ukm_service,
704 const GURL& url, 731 const GURL& url,
705 AutofillMetrics::CardUploadDecisionMetric upload_decision) { 732 AutofillMetrics::CardUploadDecisionMetric upload_decision) {
706 if (upload_decision >= AutofillMetrics::NUM_CARD_UPLOAD_DECISION_METRICS) 733 if (upload_decision >= AutofillMetrics::NUM_CARD_UPLOAD_DECISION_METRICS)
707 return; 734 return;
708 735
709 const std::map<std::string, int> metrics = { 736 const std::vector<std::pair<const char*, int>> metrics = {
710 {internal::kUKMCardUploadDecisionMetricName, 737 {internal::kUKMCardUploadDecisionMetricName,
711 static_cast<int>(upload_decision)}}; 738 static_cast<int>(upload_decision)}};
712 LogUkm(ukm_service, url, internal::kUKMCardUploadDecisionEntryName, metrics); 739 LogUkm(ukm_service, url, internal::kUKMCardUploadDecisionEntryName, metrics);
713 } 740 }
714 741
715 // static 742 // static
716 void AutofillMetrics::LogDeveloperEngagementUkm( 743 void AutofillMetrics::LogDeveloperEngagementUkm(
717 ukm::UkmService* ukm_service, 744 ukm::UkmService* ukm_service,
718 const GURL& url, 745 const GURL& url,
719 AutofillMetrics::DeveloperEngagementMetric metric) { 746 std::vector<AutofillMetrics::DeveloperEngagementMetric> metrics) {
720 const std::map<std::string, int> form_structure_metrics = { 747 std::vector<std::pair<const char*, int>> form_structure_metrics;
721 {internal::kUKMDeveloperEngagementMetricName, static_cast<int>(metric)}}; 748 for (const auto it : metrics)
749 form_structure_metrics.push_back(
750 {internal::kUKMDeveloperEngagementMetricName, static_cast<int>(it)});
751
722 LogUkm(ukm_service, url, internal::kUKMDeveloperEngagementEntryName, 752 LogUkm(ukm_service, url, internal::kUKMDeveloperEngagementEntryName,
723 form_structure_metrics); 753 form_structure_metrics);
724 } 754 }
725 755
726 // static 756 // static
727 bool AutofillMetrics::LogUkm(ukm::UkmService* ukm_service, 757 bool AutofillMetrics::LogUkm(
728 const GURL& url, 758 ukm::UkmService* ukm_service,
729 const std::string& ukm_entry_name, 759 const GURL& url,
730 const std::map<std::string, int>& metrics) { 760 const std::string& ukm_entry_name,
761 const std::vector<std::pair<const char*, int>>& metrics) {
731 if (!IsUkmLoggingEnabled() || !ukm_service || !url.is_valid() || 762 if (!IsUkmLoggingEnabled() || !ukm_service || !url.is_valid() ||
732 metrics.empty()) { 763 metrics.empty()) {
733 return false; 764 return false;
734 } 765 }
735 766
736 int32_t source_id = ukm_service->GetNewSourceID(); 767 int32_t source_id = ukm_service->GetNewSourceID();
737 ukm_service->UpdateSourceURL(source_id, url); 768 ukm_service->UpdateSourceURL(source_id, url);
738 std::unique_ptr<ukm::UkmEntryBuilder> builder = 769 std::unique_ptr<ukm::UkmEntryBuilder> builder =
739 ukm_service->GetEntryBuilder(source_id, ukm_entry_name.c_str()); 770 ukm_service->GetEntryBuilder(source_id, ukm_entry_name.c_str());
740 771
741 for (auto it = metrics.begin(); it != metrics.end(); ++it) { 772 for (auto it = metrics.begin(); it != metrics.end(); ++it) {
742 builder->AddMetric(it->first.c_str(), it->second); 773 builder->AddMetric(it->first, it->second);
743 } 774 }
744 775
745 return true; 776 return true;
746 } 777 }
747 778
748 AutofillMetrics::FormEventLogger::FormEventLogger(bool is_for_credit_card) 779 AutofillMetrics::FormEventLogger::FormEventLogger(
780 bool is_for_credit_card,
781 AutofillMetrics::FormInteractionsUkmLogger* form_interactions_ukm_logger)
749 : is_for_credit_card_(is_for_credit_card), 782 : is_for_credit_card_(is_for_credit_card),
750 is_server_data_available_(false), 783 server_record_type_count_(0),
751 is_local_data_available_(false), 784 local_record_type_count_(0),
752 is_context_secure_(false), 785 is_context_secure_(false),
753 has_logged_interacted_(false), 786 has_logged_interacted_(false),
754 has_logged_suggestions_shown_(false), 787 has_logged_suggestions_shown_(false),
755 has_logged_masked_server_card_suggestion_selected_(false), 788 has_logged_masked_server_card_suggestion_selected_(false),
756 has_logged_suggestion_filled_(false), 789 has_logged_suggestion_filled_(false),
757 has_logged_will_submit_(false), 790 has_logged_will_submit_(false),
758 has_logged_submitted_(false), 791 has_logged_submitted_(false),
759 logged_suggestion_filled_was_server_data_(false), 792 logged_suggestion_filled_was_server_data_(false),
760 logged_suggestion_filled_was_masked_server_card_(false) {} 793 logged_suggestion_filled_was_masked_server_card_(false),
794 form_interactions_ukm_logger_(form_interactions_ukm_logger) {}
761 795
762 void AutofillMetrics::FormEventLogger::OnDidInteractWithAutofillableForm() { 796 void AutofillMetrics::FormEventLogger::OnDidInteractWithAutofillableForm() {
763 if (!has_logged_interacted_) { 797 if (!has_logged_interacted_) {
764 has_logged_interacted_ = true; 798 has_logged_interacted_ = true;
799 form_interactions_ukm_logger_->LogInteractedWithForm(
800 is_for_credit_card_, local_record_type_count_,
801 server_record_type_count_);
765 Log(AutofillMetrics::FORM_EVENT_INTERACTED_ONCE); 802 Log(AutofillMetrics::FORM_EVENT_INTERACTED_ONCE);
766 } 803 }
767 } 804 }
768 805
769 void AutofillMetrics::FormEventLogger::OnDidPollSuggestions( 806 void AutofillMetrics::FormEventLogger::OnDidPollSuggestions(
770 const FormFieldData& field) { 807 const FormFieldData& field) {
771 // Record only one poll user action for consecutive polls of the same field. 808 // Record only one poll user action for consecutive polls of the same field.
772 // This is to avoid recording too many poll actions (for example when a user 809 // This is to avoid recording too many poll actions (for example when a user
773 // types in a field, triggering multiple queries) to make the analysis more 810 // types in a field, triggering multiple queries) to make the analysis more
774 // simple. 811 // simple.
775 if (!field.SameFieldAs(last_polled_field_)) { 812 if (!field.SameFieldAs(last_polled_field_)) {
776 if (is_for_credit_card_) { 813 if (is_for_credit_card_) {
777 base::RecordAction( 814 base::RecordAction(
778 base::UserMetricsAction("Autofill_PolledCreditCardSuggestions")); 815 base::UserMetricsAction("Autofill_PolledCreditCardSuggestions"));
779 } else { 816 } else {
780 base::RecordAction( 817 base::RecordAction(
781 base::UserMetricsAction("Autofill_PolledProfileSuggestions")); 818 base::UserMetricsAction("Autofill_PolledProfileSuggestions"));
782 } 819 }
783 820
784 last_polled_field_ = field; 821 last_polled_field_ = field;
785 } 822 }
786 } 823 }
787 824
788 void AutofillMetrics::FormEventLogger::OnDidShowSuggestions() { 825 void AutofillMetrics::FormEventLogger::OnDidShowSuggestions() {
826 form_interactions_ukm_logger_->LogSuggestionsShown();
827
789 Log(AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN); 828 Log(AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN);
790 if (!has_logged_suggestions_shown_) { 829 if (!has_logged_suggestions_shown_) {
791 has_logged_suggestions_shown_ = true; 830 has_logged_suggestions_shown_ = true;
792 Log(AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE); 831 Log(AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE);
793 } 832 }
794 833
795 if (is_for_credit_card_) { 834 if (is_for_credit_card_) {
796 base::RecordAction( 835 base::RecordAction(
797 base::UserMetricsAction("Autofill_ShowedCreditCardSuggestions")); 836 base::UserMetricsAction("Autofill_ShowedCreditCardSuggestions"));
798 } else { 837 } else {
799 base::RecordAction( 838 base::RecordAction(
800 base::UserMetricsAction("Autofill_ShowedProfileSuggestions")); 839 base::UserMetricsAction("Autofill_ShowedProfileSuggestions"));
801 } 840 }
802 } 841 }
803 842
804 void AutofillMetrics::FormEventLogger::OnDidSelectMaskedServerCardSuggestion() { 843 void AutofillMetrics::FormEventLogger::OnDidSelectMaskedServerCardSuggestion() {
805 DCHECK(is_for_credit_card_); 844 DCHECK(is_for_credit_card_);
845 form_interactions_ukm_logger_->LogSelectedMaskedServerCard();
846
806 Log(AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED); 847 Log(AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED);
807 if (!has_logged_masked_server_card_suggestion_selected_) { 848 if (!has_logged_masked_server_card_suggestion_selected_) {
808 has_logged_masked_server_card_suggestion_selected_ = true; 849 has_logged_masked_server_card_suggestion_selected_ = true;
809 Log(AutofillMetrics 850 Log(AutofillMetrics::
810 ::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED_ONCE); 851 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED_ONCE);
811 } 852 }
812 } 853 }
813 854
814 void AutofillMetrics::FormEventLogger::OnDidFillSuggestion( 855 void AutofillMetrics::FormEventLogger::OnDidFillSuggestion(
815 const CreditCard& credit_card) { 856 const CreditCard& credit_card) {
816 DCHECK(is_for_credit_card_); 857 DCHECK(is_for_credit_card_);
858 form_interactions_ukm_logger_->LogDidFillSuggestion(
859 static_cast<int>(credit_card.record_type()));
860
817 if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD) 861 if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD)
818 Log(AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED); 862 Log(AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED);
819 else if (credit_card.record_type() == CreditCard::FULL_SERVER_CARD) 863 else if (credit_card.record_type() == CreditCard::FULL_SERVER_CARD)
820 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED); 864 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED);
821 else 865 else
822 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED); 866 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED);
823 867
824 if (!has_logged_suggestion_filled_) { 868 if (!has_logged_suggestion_filled_) {
825 has_logged_suggestion_filled_ = true; 869 has_logged_suggestion_filled_ = true;
826 logged_suggestion_filled_was_server_data_ = 870 logged_suggestion_filled_was_server_data_ =
827 credit_card.record_type() == CreditCard::MASKED_SERVER_CARD || 871 credit_card.record_type() == CreditCard::MASKED_SERVER_CARD ||
828 credit_card.record_type() == CreditCard::FULL_SERVER_CARD; 872 credit_card.record_type() == CreditCard::FULL_SERVER_CARD;
829 logged_suggestion_filled_was_masked_server_card_ = 873 logged_suggestion_filled_was_masked_server_card_ =
830 credit_card.record_type() == CreditCard::MASKED_SERVER_CARD; 874 credit_card.record_type() == CreditCard::MASKED_SERVER_CARD;
831 if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD) { 875 if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD) {
832 Log(AutofillMetrics 876 Log(AutofillMetrics::
833 ::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE); 877 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE);
834 } else if (credit_card.record_type() == CreditCard::FULL_SERVER_CARD) { 878 } else if (credit_card.record_type() == CreditCard::FULL_SERVER_CARD) {
835 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED_ONCE); 879 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED_ONCE);
836 } else { 880 } else {
837 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE); 881 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE);
838 } 882 }
839 } 883 }
840 884
841 base::RecordAction( 885 base::RecordAction(
842 base::UserMetricsAction("Autofill_FilledCreditCardSuggestion")); 886 base::UserMetricsAction("Autofill_FilledCreditCardSuggestion"));
843 } 887 }
844 888
845 void AutofillMetrics::FormEventLogger::OnDidFillSuggestion( 889 void AutofillMetrics::FormEventLogger::OnDidFillSuggestion(
846 const AutofillProfile& profile) { 890 const AutofillProfile& profile) {
847 DCHECK(!is_for_credit_card_); 891 DCHECK(!is_for_credit_card_);
892 form_interactions_ukm_logger_->LogDidFillSuggestion(
893 static_cast<int>(profile.record_type()));
894
848 if (profile.record_type() == AutofillProfile::SERVER_PROFILE) 895 if (profile.record_type() == AutofillProfile::SERVER_PROFILE)
849 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED); 896 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED);
850 else 897 else
851 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED); 898 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED);
852 899
853 if (!has_logged_suggestion_filled_) { 900 if (!has_logged_suggestion_filled_) {
854 has_logged_suggestion_filled_ = true; 901 has_logged_suggestion_filled_ = true;
855 logged_suggestion_filled_was_server_data_ = 902 logged_suggestion_filled_was_server_data_ =
856 profile.record_type() == AutofillProfile::SERVER_PROFILE; 903 profile.record_type() == AutofillProfile::SERVER_PROFILE;
857 Log(profile.record_type() == AutofillProfile::SERVER_PROFILE 904 Log(profile.record_type() == AutofillProfile::SERVER_PROFILE
858 ? AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED_ONCE 905 ? AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED_ONCE
859 : AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE); 906 : AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE);
860 } 907 }
861 908
862 base::RecordAction( 909 base::RecordAction(
863 base::UserMetricsAction("Autofill_FilledProfileSuggestion")); 910 base::UserMetricsAction("Autofill_FilledProfileSuggestion"));
864 } 911 }
865 912
866 void AutofillMetrics::FormEventLogger::OnWillSubmitForm() { 913 void AutofillMetrics::FormEventLogger::OnWillSubmitForm() {
867 // Not logging this kind of form if we haven't logged a user interaction. 914 // Not logging this kind of form if we haven't logged a user interaction.
868 if (!has_logged_interacted_) 915 if (!has_logged_interacted_)
869 return; 916 return;
(...skipping 27 matching lines...) Expand all
897 return; 944 return;
898 945
899 // Not logging twice. 946 // Not logging twice.
900 if (has_logged_submitted_) 947 if (has_logged_submitted_)
901 return; 948 return;
902 has_logged_submitted_ = true; 949 has_logged_submitted_ = true;
903 950
904 if (!has_logged_suggestion_filled_) { 951 if (!has_logged_suggestion_filled_) {
905 Log(AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE); 952 Log(AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE);
906 } else if (logged_suggestion_filled_was_masked_server_card_) { 953 } else if (logged_suggestion_filled_was_masked_server_card_) {
907 Log(AutofillMetrics 954 Log(AutofillMetrics::
908 ::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE); 955 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE);
909 } else if (logged_suggestion_filled_was_server_data_) { 956 } else if (logged_suggestion_filled_was_server_data_) {
910 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE); 957 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE);
911 } else { 958 } else {
912 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE); 959 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE);
913 } 960 }
914 961
915 if (has_logged_suggestions_shown_) { 962 if (has_logged_suggestions_shown_) {
916 Log(AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_SUBMITTED_ONCE); 963 Log(AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_SUBMITTED_ONCE);
917 } 964 }
918 } 965 }
(...skipping 11 matching lines...) Expand all
930 // pages, so that form interactions on nonsecure pages can be analyzed on 977 // pages, so that form interactions on nonsecure pages can be analyzed on
931 // their own. 978 // their own.
932 if (is_for_credit_card_ && !is_context_secure_) { 979 if (is_for_credit_card_ && !is_context_secure_) {
933 LogUMAHistogramEnumeration(name + ".OnNonsecurePage", event, 980 LogUMAHistogramEnumeration(name + ".OnNonsecurePage", event,
934 NUM_FORM_EVENTS); 981 NUM_FORM_EVENTS);
935 } 982 }
936 983
937 // Logging again in a different histogram for segmentation purposes. 984 // Logging again in a different histogram for segmentation purposes.
938 // TODO(waltercacau): Re-evaluate if we still need such fine grained 985 // TODO(waltercacau): Re-evaluate if we still need such fine grained
939 // segmentation. http://crbug.com/454018 986 // segmentation. http://crbug.com/454018
940 if (!is_server_data_available_ && !is_local_data_available_) 987 if (server_record_type_count_ == 0 && local_record_type_count_ == 0)
941 name += ".WithNoData"; 988 name += ".WithNoData";
942 else if (is_server_data_available_ && !is_local_data_available_) 989 else if (server_record_type_count_ > 0 && local_record_type_count_ == 0)
943 name += ".WithOnlyServerData"; 990 name += ".WithOnlyServerData";
944 else if (!is_server_data_available_ && is_local_data_available_) 991 else if (server_record_type_count_ == 0 && local_record_type_count_ > 0)
945 name += ".WithOnlyLocalData"; 992 name += ".WithOnlyLocalData";
946 else 993 else
947 name += ".WithBothServerAndLocalData"; 994 name += ".WithBothServerAndLocalData";
948 LogUMAHistogramEnumeration(name, event, NUM_FORM_EVENTS); 995 LogUMAHistogramEnumeration(name, event, NUM_FORM_EVENTS);
949 } 996 }
950 997
998 AutofillMetrics::FormInteractionsUkmLogger::FormInteractionsUkmLogger(
999 ukm::UkmService* ukm_service)
1000 : ukm_service_(ukm_service) {}
1001
1002 void AutofillMetrics::FormInteractionsUkmLogger::OnFormsLoaded(
1003 const GURL& url) {
1004 if (!IsUkmLoggingEnabled() || ukm_service_ == nullptr)
1005 return;
1006
1007 url_ = url;
1008 form_loaded_timestamp_ = base::TimeTicks::Now();
1009 }
1010
1011 void AutofillMetrics::FormInteractionsUkmLogger::LogInteractedWithForm(
1012 bool is_for_credit_card,
1013 size_t local_record_type_count,
1014 size_t server_record_type_count) {
1015 if (!CanLog())
1016 return;
1017
1018 if (source_id_ == -1)
1019 GetNewSourceID();
1020
1021 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder(
1022 source_id_, internal::kUKMInteractedWithFormEntryName);
1023 builder->AddMetric(internal::kUKMIsForCreditCardMetricName,
1024 is_for_credit_card);
1025 builder->AddMetric(internal::kUKMLocalRecordTypeCountMetricName,
1026 local_record_type_count);
1027 builder->AddMetric(internal::kUKMServerRecordTypeCountMetricName,
1028 server_record_type_count);
1029 }
1030
1031 void AutofillMetrics::FormInteractionsUkmLogger::LogSuggestionsShown() {
1032 if (!CanLog())
1033 return;
1034
1035 if (source_id_ == -1)
1036 GetNewSourceID();
1037
1038 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder(
1039 source_id_, internal::kUKMSuggestionsShownEntryName);
1040 builder->AddMetric(internal::kUKMMillisecondsSinceFormLoadedMetricName,
1041 MillisecondsSinceFormLoaded());
1042 }
1043
1044 void AutofillMetrics::FormInteractionsUkmLogger::LogSelectedMaskedServerCard() {
1045 if (!CanLog())
1046 return;
1047
1048 if (source_id_ == -1)
1049 GetNewSourceID();
1050
1051 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder(
1052 source_id_, internal::kUKMSelectedMaskedServerCardEntryName);
1053 builder->AddMetric(internal::kUKMMillisecondsSinceFormLoadedMetricName,
1054 MillisecondsSinceFormLoaded());
1055 }
1056
1057 void AutofillMetrics::FormInteractionsUkmLogger::LogDidFillSuggestion(
1058 int record_type) {
1059 if (!CanLog())
1060 return;
1061
1062 if (source_id_ == -1)
1063 GetNewSourceID();
1064
1065 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder(
1066 source_id_, internal::kUKMSuggestionFilledEntryName);
1067 builder->AddMetric(internal::kUKMRecordTypeMetricName, record_type);
1068 builder->AddMetric(internal::kUKMMillisecondsSinceFormLoadedMetricName,
1069 MillisecondsSinceFormLoaded());
1070 }
1071
1072 void AutofillMetrics::FormInteractionsUkmLogger::LogTextFieldDidChange(
1073 const AutofillField& field) {
1074 if (!CanLog())
1075 return;
1076
1077 if (source_id_ == -1)
1078 GetNewSourceID();
1079
1080 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder(
1081 source_id_, internal::kUKMTextFieldDidChangeEntryName);
1082 builder->AddMetric(internal::kUKMFieldTypeGroupMetricName,
1083 static_cast<int>(field.Type().group()));
1084 builder->AddMetric(internal::kUKMHeuristicTypeMetricName,
1085 static_cast<int>(field.heuristic_type()));
1086 builder->AddMetric(internal::kUKMServerTypeMetricName,
1087 static_cast<int>(field.server_type()));
1088 builder->AddMetric(internal::kUKMHtmlFieldTypeMetricName,
1089 static_cast<int>(field.html_type()));
1090 builder->AddMetric(internal::kUKMHtmlFieldModeMetricName,
1091 static_cast<int>(field.html_mode()));
1092 builder->AddMetric(internal::kUKMIsAutofilledMetricName, field.is_autofilled);
1093 builder->AddMetric(internal::kUKMIsEmptyMetricName, field.IsEmpty());
1094 builder->AddMetric(internal::kUKMMillisecondsSinceFormLoadedMetricName,
1095 MillisecondsSinceFormLoaded());
1096 }
1097
1098 void AutofillMetrics::FormInteractionsUkmLogger::LogFormSubmitted(
1099 AutofillFormSubmittedState state) {
1100 if (!CanLog())
1101 return;
1102
1103 if (source_id_ == -1)
1104 GetNewSourceID();
1105
1106 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder(
1107 source_id_, internal::kUKMFormSubmittedEntryName);
1108 builder->AddMetric(internal::kUKMAutofillFormSubmittedStateMetricName,
1109 static_cast<int>(state));
1110 builder->AddMetric(internal::kUKMMillisecondsSinceFormLoadedMetricName,
1111 MillisecondsSinceFormLoaded());
1112 }
1113
1114 void AutofillMetrics::FormInteractionsUkmLogger::UpdateSourceURL(
1115 const GURL& url) {
1116 url_ = url;
1117 if (CanLog())
1118 ukm_service_->UpdateSourceURL(source_id_, url_);
1119 }
1120
1121 bool AutofillMetrics::FormInteractionsUkmLogger::CanLog() const {
1122 return IsUkmLoggingEnabled() && ukm_service_ && url_.is_valid();
1123 }
1124
1125 int64_t
1126 AutofillMetrics::FormInteractionsUkmLogger::MillisecondsSinceFormLoaded()
1127 const {
1128 DCHECK(!form_loaded_timestamp_.is_null());
1129 return (base::TimeTicks::Now() - form_loaded_timestamp_).InMilliseconds();
1130 }
1131
1132 void AutofillMetrics::FormInteractionsUkmLogger::GetNewSourceID() {
1133 source_id_ = ukm_service_->GetNewSourceID();
1134 ukm_service_->UpdateSourceURL(source_id_, url_);
1135 }
1136
951 } // namespace autofill 1137 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_metrics.h ('k') | components/autofill/core/browser/autofill_metrics_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698