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

Side by Side Diff: components/payments/core/journey_logger.cc

Issue 2750103005: [Payments] Move journey logger to native. (Closed)
Patch Set: Add the component_jni_registrar files 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
« no previous file with comments | « components/payments/core/journey_logger.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 namespace {
15
16 // Returns the JourneyLogger histograms name suffix based on the |section| and
17 // the |completion_status|.
18 std::string GetHistogramNameSuffix(
19 int section,
20 JourneyLogger::CompletionStatus completion_status) {
21 std::string name_suffix = "";
22
23 switch (section) {
24 case JourneyLogger::SECTION_SHIPPING_ADDRESS:
25 name_suffix = "ShippingAddress.";
26 break;
27 case JourneyLogger::SECTION_CONTACT_INFO:
28 name_suffix = "ContactInfo.";
29 break;
30 case JourneyLogger::SECTION_CREDIT_CARDS:
31 name_suffix = "CreditCards.";
32 break;
33 default:
34 break;
35 }
36
37 switch (completion_status) {
38 case JourneyLogger::COMPLETION_STATUS_COMPLETED:
39 name_suffix += "Completed";
40 break;
41 case JourneyLogger::COMPLETION_STATUS_USER_ABORTED:
42 name_suffix += "UserAborted";
43 break;
44 case JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED:
45 name_suffix += "OtherAborted";
46 break;
47 default:
48 break;
49 }
50
51 DCHECK(!name_suffix.empty());
52 return name_suffix;
53 }
54
55 } // namespace
56
57 JourneyLogger::JourneyLogger()
58 : was_can_make_payments_used_(false),
59 could_make_payment_(false),
60 was_show_called_(false) {}
61
62 JourneyLogger::~JourneyLogger() {}
63
64 void JourneyLogger::IncrementSelectionAdds(Section section) {
65 DCHECK_LT(section, SECTION_MAX);
66 sections_[section].number_selection_adds_++;
67 }
68
69 void JourneyLogger::IncrementSelectionChanges(Section section) {
70 DCHECK_LT(section, SECTION_MAX);
71 sections_[section].number_selection_changes_++;
72 }
73
74 void JourneyLogger::IncrementSelectionEdits(Section section) {
75 DCHECK_LT(section, SECTION_MAX);
76 sections_[section].number_selection_edits_++;
77 }
78
79 void JourneyLogger::SetNumberOfSuggestionsShown(Section section, int number) {
80 DCHECK_LT(section, SECTION_MAX);
81 sections_[section].number_suggestions_shown_ = number;
82 sections_[section].is_requested_ = true;
83 }
84
85 void JourneyLogger::SetCanMakePaymentValue(bool value) {
86 was_can_make_payments_used_ = true;
87 could_make_payment_ |= value;
88 }
89
90 void JourneyLogger::SetShowCalled() {
91 was_show_called_ = true;
92 }
93
94 void JourneyLogger::RecordJourneyStatsHistograms(
95 CompletionStatus completion_status) {
96 RecordSectionSpecificStats(completion_status);
97
98 // Record the CanMakePayment metrics based on whether the transaction was
99 // completed or aborted by the user (UserAborted) or otherwise (OtherAborted).
100 RecordCanMakePaymentStats(completion_status);
101 }
102
103 void JourneyLogger::RecordSectionSpecificStats(
104 CompletionStatus completion_status) {
105 // Record whether the user had suggestions for each requested information.
106 bool user_had_all_requested_information = true;
107
108 for (int i = 0; i < NUMBER_OF_SECTIONS; ++i) {
109 std::string name_suffix = GetHistogramNameSuffix(i, completion_status);
110
111 // Only log the metrics for a section if it was requested by the merchant.
112 if (sections_[i].is_requested_) {
113 base::UmaHistogramCustomCounts(
114 "PaymentRequest.NumberOfSelectionAdds." + name_suffix,
115 std::min(sections_[i].number_selection_adds_, MAX_EXPECTED_SAMPLE),
116 MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS);
117 base::UmaHistogramCustomCounts(
118 "PaymentRequest.NumberOfSelectionChanges." + name_suffix,
119 std::min(sections_[i].number_selection_changes_, MAX_EXPECTED_SAMPLE),
120 MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS);
121 base::UmaHistogramCustomCounts(
122 "PaymentRequest.NumberOfSelectionEdits." + name_suffix,
123 std::min(sections_[i].number_selection_edits_, MAX_EXPECTED_SAMPLE),
124 MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS);
125 base::UmaHistogramCustomCounts(
126 "PaymentRequest.NumberOfSuggestionsShown." + name_suffix,
127 std::min(sections_[i].number_suggestions_shown_, MAX_EXPECTED_SAMPLE),
128 MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS);
129
130 if (sections_[i].number_suggestions_shown_ == 0) {
131 user_had_all_requested_information = false;
132 }
133 }
134 }
135
136 // Record metrics about completion based on whether the user had suggestions
137 // for each requested information.
138 if (user_had_all_requested_information) {
139 base::UmaHistogramEnumeration(
140 "PaymentRequest.UserHadSuggestionsForEverything."
141 "EffectOnCompletion",
142 completion_status, COMPLETION_STATUS_MAX);
143 } else {
144 base::UmaHistogramEnumeration(
145 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
146 "EffectOnCompletion",
147 completion_status, COMPLETION_STATUS_MAX);
148 }
149 }
150
151 void JourneyLogger::RecordCanMakePaymentStats(
152 CompletionStatus completion_status) {
153 // Record CanMakePayment usage.
154 UMA_HISTOGRAM_ENUMERATION("PaymentRequest.CanMakePayment.Usage",
155 was_can_make_payments_used_
156 ? CAN_MAKE_PAYMENT_USED
157 : CAN_MAKE_PAYMENT_NOT_USED,
158 CAN_MAKE_PAYMENT_USE_MAX);
159
160 RecordCanMakePaymentEffectOnShow();
161 RecordCanMakePaymentEffectOnCompletion(completion_status);
162 }
163
164 void JourneyLogger::RecordCanMakePaymentEffectOnShow() {
165 if (!was_can_make_payments_used_)
166 return;
167
168 int effect_on_show = 0;
169 if (was_show_called_)
170 effect_on_show |= CMP_SHOW_DID_SHOW;
171 if (could_make_payment_)
172 effect_on_show |= CMP_SHOW_COULD_MAKE_PAYMENT_;
173
174 UMA_HISTOGRAM_ENUMERATION("PaymentRequest.CanMakePayment.Used.EffectOnShow",
175 effect_on_show, CMP_SHOW_MAX);
176 }
177
178 void JourneyLogger::RecordCanMakePaymentEffectOnCompletion(
179 CompletionStatus completion_status) {
180 if (!was_show_called_)
181 return;
182
183 std::string histogram_name = "PaymentRequest.CanMakePayment.";
184 if (!was_can_make_payments_used_) {
185 histogram_name += "NotUsed.WithShowEffectOnCompletion";
186 } else if (could_make_payment_) {
187 histogram_name += "Used.TrueWithShowEffectOnCompletion";
188 } else {
189 histogram_name += "Used.FalseWithShowEffectOnCompletion";
190 }
191
192 base::UmaHistogramEnumeration(histogram_name, completion_status,
193 COMPLETION_STATUS_MAX);
194 }
195
196 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/core/journey_logger.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698