OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/payments/core/journey_logger.h" | |
6 | |
7 #include <algorithm> | |
8 | |
9 #include "base/metrics/histogram_functions.h" | |
10 #include "base/metrics/histogram_macros.h" | |
11 | |
12 namespace payments { | |
13 | |
14 JourneyLogger::JourneyLogger() | |
15 : was_can_make_payments_used_(false), | |
16 could_make_payment_(false), | |
17 was_show_called_(false) {} | |
18 | |
19 void JourneyLogger::IncrementSelectionAdds(int section) { | |
20 DCHECK(section < SECTION_MAX); | |
21 sections_[section].number_selection_adds_++; | |
22 } | |
23 | |
24 void JourneyLogger::IncrementSelectionChanges(int section) { | |
25 DCHECK(section < SECTION_MAX); | |
26 sections_[section].number_selection_changes_++; | |
27 } | |
28 | |
29 void JourneyLogger::IncrementSelectionEdits(int section) { | |
30 DCHECK(section < SECTION_MAX); | |
31 sections_[section].number_selection_edits_++; | |
32 } | |
33 | |
34 void JourneyLogger::SetNumberOfSuggestionsShown(int section, int number) { | |
35 DCHECK(section < SECTION_MAX); | |
36 sections_[section].number_suggestions_shown_ = number; | |
37 sections_[section].is_requested_ = true; | |
38 } | |
39 | |
40 void JourneyLogger::SetCanMakePaymentValue(bool value) { | |
41 was_can_make_payments_used_ = true; | |
42 could_make_payment_ |= value; | |
43 } | |
44 | |
45 void JourneyLogger::SetShowCalled() { | |
46 was_show_called_ = true; | |
47 } | |
48 | |
49 void JourneyLogger::RecordJourneyStatsHistograms( | |
50 const std::string& submission_type) { | |
51 RecordSectionSpecificStats(submission_type); | |
52 | |
53 // Record the CanMakePayment metrics based on whether the transaction was | |
54 // completed or aborted by the user (UserAborted) or otherwise (OtherAborted). | |
55 RecordCanMakePaymentStats(submission_type.find("Abort") != std::string::npos | |
56 ? COMPLETION_STATUS_ABORTED | |
57 : COMPLETION_STATUS_COMPLETED); | |
58 } | |
59 | |
60 void JourneyLogger::RecordSectionSpecificStats( | |
61 const std::string& submission_type) { | |
62 // Record whether the user had suggestions for each requested information. | |
63 bool user_had_all_requested_information = true; | |
64 | |
65 for (int i = 0; i < NUMBER_OF_SECTIONS; ++i) { | |
66 std::string name_suffix = ""; | |
67 switch (i) { | |
68 case SECTION_SHIPPING_ADDRESS: | |
69 name_suffix = "ShippingAddress." + submission_type; | |
70 break; | |
71 case SECTION_CONTACT_INFO: | |
72 name_suffix = "ContactInfo." + submission_type; | |
73 break; | |
74 case SECTION_CREDIT_CARDS: | |
75 name_suffix = "CreditCards." + submission_type; | |
76 break; | |
77 default: | |
78 break; | |
79 } | |
80 | |
81 DCHECK(!name_suffix.empty()); | |
82 | |
83 // Only log the metrics for a section if it was requested by the merchant. | |
84 if (sections_[i].is_requested_) { | |
85 base::UmaHistogramCustomCounts( | |
86 "PaymentRequest.NumberOfSelectionAdds." + name_suffix, | |
87 std::min(sections_[i].number_selection_adds_, MAX_EXPECTED_SAMPLE), | |
88 MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS); | |
89 base::UmaHistogramCustomCounts( | |
90 "PaymentRequest.NumberOfSelectionChanges." + name_suffix, | |
91 std::min(sections_[i].number_selection_changes_, MAX_EXPECTED_SAMPLE), | |
92 MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS); | |
93 base::UmaHistogramCustomCounts( | |
94 "PaymentRequest.NumberOfSelectionEdits." + name_suffix, | |
95 std::min(sections_[i].number_selection_edits_, MAX_EXPECTED_SAMPLE), | |
96 MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS); | |
97 base::UmaHistogramCustomCounts( | |
98 "PaymentRequest.NumberOfSuggestionsShown." + name_suffix, | |
99 std::min(sections_[i].number_suggestions_shown_, MAX_EXPECTED_SAMPLE), | |
100 MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS); | |
101 | |
102 if (sections_[i].number_suggestions_shown_ == 0) { | |
103 user_had_all_requested_information = false; | |
104 } | |
105 } | |
106 } | |
107 | |
108 // Record metrics about completion based on whether the user had suggestions | |
109 // for each requested information. | |
110 int completion_status = submission_type.find("Abort") != std::string::npos | |
111 ? COMPLETION_STATUS_ABORTED | |
112 : COMPLETION_STATUS_COMPLETED; | |
113 if (user_had_all_requested_information) { | |
114 UMA_HISTOGRAM_ENUMERATION( | |
115 "PaymentRequest.UserHadSuggestionsForEverything." | |
116 "EffectOnCompletion", | |
117 completion_status, COMPLETION_STATUS_MAX); | |
118 } else { | |
119 UMA_HISTOGRAM_ENUMERATION( | |
120 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." | |
121 "EffectOnCompletion", | |
122 completion_status, COMPLETION_STATUS_MAX); | |
123 } | |
124 } | |
125 | |
126 void JourneyLogger::RecordCanMakePaymentStats(int completion_status) { | |
127 // Record CanMakePayment usage. | |
128 UMA_HISTOGRAM_ENUMERATION("PaymentRequest.CanMakePayment.Usage", | |
129 was_can_make_payments_used_ | |
130 ? CAN_MAKE_PAYMENT_USED | |
131 : CAN_MAKE_PAYMENT_NOT_USED, | |
132 CAN_MAKE_PAYMENT_USE_MAX); | |
133 | |
134 RecordCanMakePaymentEffectOnShow(); | |
135 RecordCanMakePaymentEffectOnCompletion(completion_status); | |
136 } | |
137 | |
138 void JourneyLogger::RecordCanMakePaymentEffectOnShow() { | |
139 if (!was_can_make_payments_used_) | |
140 return; | |
141 | |
142 int effect_on_show = 0; | |
143 if (was_show_called_) | |
144 effect_on_show |= CMP_SHOW_DID_SHOW; | |
145 if (could_make_payment_) | |
146 effect_on_show |= CMP_SHOW_could_make_payment_; | |
Mathieu
2017/03/23 21:19:48
fix
sebsg
2017/03/24 13:35:29
Done.
| |
147 | |
148 UMA_HISTOGRAM_ENUMERATION("PaymentRequest.CanMakePayment.Used.EffectOnShow", | |
149 effect_on_show, CMP_SHOW_MAX); | |
150 } | |
151 | |
152 void JourneyLogger::RecordCanMakePaymentEffectOnCompletion( | |
153 int completion_status) { | |
154 if (!was_show_called_) | |
155 return; | |
156 | |
157 std::string histogram_name = "PaymentRequest.CanMakePayment."; | |
158 | |
Mathieu
2017/03/23 21:19:48
remove extra line
sebsg
2017/03/24 13:35:29
Done.
| |
159 if (!was_can_make_payments_used_) { | |
160 histogram_name += "NotUsed.WithShowEffectOnCompletion"; | |
161 } else if (could_make_payment_) { | |
162 histogram_name += "Used.TrueWithShowEffectOnCompletion"; | |
163 } else { | |
164 histogram_name += "Used.FalseWithShowEffectOnCompletion"; | |
165 } | |
166 | |
167 UMA_HISTOGRAM_ENUMERATION(histogram_name, completion_status, | |
Mathieu
2017/03/23 21:19:48
this is wrong. this macro statically caches the hi
sebsg
2017/03/24 13:35:29
Done.
| |
168 COMPLETION_STATUS_MAX); | |
169 } | |
170 | |
171 } // namespace payments | |
OLD | NEW |