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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestJourneyLogger.java

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
OLDNEW
(Empty)
1 // Copyright 2016 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 package org.chromium.chrome.browser.payments;
6
7 import org.chromium.base.metrics.RecordHistogram;
8
9 /**
10 * A class used to record journey metrics for the Payment Request feature.
11 */
12 public class PaymentRequestJourneyLogger {
13 // The index of the different sections of a Payment Request. Used to record journey stats.
14 public static final int SECTION_CONTACT_INFO = 0;
15 public static final int SECTION_CREDIT_CARDS = 1;
16 public static final int SECTION_SHIPPING_ADDRESS = 2;
17 public static final int SECTION_MAX = 3;
18
19 // For the CanMakePayment histograms.
20 public static final int CAN_MAKE_PAYMENT_USED = 0;
21 public static final int CAN_MAKE_PAYMENT_NOT_USED = 1;
22 public static final int CAN_MAKE_PAYMENT_USE_MAX = 2;
23
24 // Used to log different parameters' effect on whether the transaction was c ompleted.
25 public static final int COMPLETION_STATUS_COMPLETED = 0;
26 public static final int COMPLETION_STATUS_ABORTED = 1;
27 public static final int COMPLETION_STATUS_MAX = 2;
28
29 // Used to mesure the impact of the CanMakePayment return value on whether t he Payment Request
30 // is shown to the user.
31 public static final int CMP_SHOW_COULD_NOT_MAKE_PAYMENT_AND_DID_NOT_SHOW = 0 ;
32 public static final int CMP_SHOW_DID_SHOW = 1 << 0;
33 public static final int CMP_SHOW_COULD_MAKE_PAYMENT = 1 << 1;
34 public static final int CMP_SHOW_MAX = 4;
35
36 // The minimum expected value of CustomCountHistograms is always set to 1. I t is still possible
37 // to log the value 0 to that type of histogram.
38 private static final int MIN_EXPECTED_SAMPLE = 1;
39 private static final int MAX_EXPECTED_SAMPLE = 49;
40 private static final int NUMBER_BUCKETS = 50;
41
42 private static class SectionStats {
43 private int mNumberSuggestionsShown;
44 private int mNumberSelectionChanges;
45 private int mNumberSelectionEdits;
46 private int mNumberSelectionAdds;
47 private boolean mIsRequested;
48 }
49
50 private SectionStats[] mSections;
51
52 private boolean mWasCanMakePaymentUsed;
53 private boolean mCouldMakePayment;
54 private boolean mWasShowCalled;
55
56 public PaymentRequestJourneyLogger() {
57 mSections = new SectionStats[SECTION_MAX];
58 for (int i = 0; i < mSections.length; ++i) {
59 mSections[i] = new SectionStats();
60 }
61 }
62
63 /**
64 * Sets the number of suggestions shown for the specified section.
65 *
66 * @param section The section for which to log.
67 * @param number The number of suggestions.
68 */
69 public void setNumberOfSuggestionsShown(int section, int number) {
70 assert section < SECTION_MAX;
71 mSections[section].mNumberSuggestionsShown = number;
72 mSections[section].mIsRequested = true;
73 }
74
75 /**
76 * Increments the number of selection changes for the specified section.
77 *
78 * @param section The section for which to log.
79 */
80 public void incrementSelectionChanges(int section) {
81 assert section < SECTION_MAX;
82 mSections[section].mNumberSelectionChanges++;
83 }
84
85 /**
86 * Increments the number of selection edits for the specified section.
87 *
88 * @param section The section for which to log.
89 */
90 public void incrementSelectionEdits(int section) {
91 assert section < SECTION_MAX;
92 mSections[section].mNumberSelectionEdits++;
93 }
94
95 /**
96 * Increments the number of selection adds for the specified section.
97 *
98 * @param section The section for which to log.
99 */
100 public void incrementSelectionAdds(int section) {
101 assert section < SECTION_MAX;
102 mSections[section].mNumberSelectionAdds++;
103 }
104
105 /**
106 * Records the fact that the merchant called CanMakePayment and records it's return value.
107 *
108 * @param value The return value of the CanMakePayment call.
109 */
110 public void setCanMakePaymentValue(boolean value) {
111 mWasCanMakePaymentUsed = true;
112 mCouldMakePayment |= value;
113 }
114
115 /**
116 * Records the fact that the Payment Request was shown to the user.
117 */
118 public void setShowCalled() {
119 mWasShowCalled = true;
120 }
121
122 /*
123 * Records the histograms for all the sections that were requested by the me rchant and for the
124 * usage of the CanMakePayment method and its effect on the transaction. Thi s method should be
125 * called when the payment request has either been completed or aborted.
126 *
127 * @param submissionType A string indicating the way the payment request was concluded.
128 */
129 public void recordJourneyStatsHistograms(String submissionType) {
130 recordSectionSpecificStats(submissionType);
131
132 // Record the CanMakePayment metrics based on whether the transaction wa s completed or
133 // aborted by the user (UserAborted) or otherwise (OtherAborted).
134 recordCanMakePaymentStats(submissionType.contains("Abort") ? COMPLETION_ STATUS_ABORTED
135 : COMPLETION_ STATUS_COMPLETED);
136 }
137
138 /**
139 * Records the histograms for all the sections that were requested by the me rchant.
140 *
141 * @param submissionType A string indicating the way the payment request was concluded.
142 */
143 private void recordSectionSpecificStats(String submissionType) {
144 // Record whether the user had suggestions for each requested informatio n.
145 boolean userHadAllRequestedInformation = true;
146
147 for (int i = 0; i < mSections.length; ++i) {
148 String nameSuffix = "";
149 switch (i) {
150 case SECTION_SHIPPING_ADDRESS:
151 nameSuffix = "ShippingAddress." + submissionType;
152 break;
153 case SECTION_CONTACT_INFO:
154 nameSuffix = "ContactInfo." + submissionType;
155 break;
156 case SECTION_CREDIT_CARDS:
157 nameSuffix = "CreditCards." + submissionType;
158 break;
159 default:
160 break;
161 }
162
163 assert !nameSuffix.isEmpty();
164
165 // Only log the metrics for a section if it was requested by the mer chant.
166 if (mSections[i].mIsRequested) {
167 RecordHistogram.recordCustomCountHistogram(
168 "PaymentRequest.NumberOfSelectionAdds." + nameSuffix,
169 Math.min(mSections[i].mNumberSelectionAdds, MAX_EXPECTED _SAMPLE),
170 MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS );
171 RecordHistogram.recordCustomCountHistogram(
172 "PaymentRequest.NumberOfSelectionChanges." + nameSuffix,
173 Math.min(mSections[i].mNumberSelectionChanges, MAX_EXPEC TED_SAMPLE),
174 MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS );
175 RecordHistogram.recordCustomCountHistogram(
176 "PaymentRequest.NumberOfSelectionEdits." + nameSuffix,
177 Math.min(mSections[i].mNumberSelectionEdits, MAX_EXPECTE D_SAMPLE),
178 MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS );
179 RecordHistogram.recordCustomCountHistogram(
180 "PaymentRequest.NumberOfSuggestionsShown." + nameSuffix,
181 Math.min(mSections[i].mNumberSuggestionsShown, MAX_EXPEC TED_SAMPLE),
182 MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS );
183
184 if (mSections[i].mNumberSuggestionsShown == 0) {
185 userHadAllRequestedInformation = false;
186 }
187 }
188 }
189
190 // Record metrics about completion based on whether the user had suggest ions for each
191 // requested information.
192 int completionStatus = submissionType.contains("Abort") ? COMPLETION_STA TUS_ABORTED
193 : COMPLETION_STA TUS_COMPLETED;
194 if (userHadAllRequestedInformation) {
195 RecordHistogram.recordEnumeratedHistogram(
196 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnComp letion",
197 completionStatus, COMPLETION_STATUS_MAX);
198 } else {
199 RecordHistogram.recordEnumeratedHistogram(
200 "PaymentRequest.UserDidNotHaveSuggestionsForEverything.Effec tOnCompletion",
201 completionStatus, COMPLETION_STATUS_MAX);
202 }
203 }
204
205 /**
206 * Records the metrics related the the CanMakePayment method.
207 *
208 * @param completionStatus Whether the transaction was completed or aborted.
209 */
210 private void recordCanMakePaymentStats(int completionStatus) {
211 // Record CanMakePayment usage.
212 RecordHistogram.recordEnumeratedHistogram("PaymentRequest.CanMakePayment .Usage",
213 mWasCanMakePaymentUsed ? CAN_MAKE_PAYMENT_USED : CAN_MAKE_PAYMEN T_NOT_USED,
214 CAN_MAKE_PAYMENT_USE_MAX);
215
216 recordCanMakePaymentEffectOnShow();
217 recordCanMakePaymentEffectOnCompletion(completionStatus);
218 }
219
220 /**
221 * Records CanMakePayment's return value effect on whether the Payment Reque st was shown or not.
222 */
223 private void recordCanMakePaymentEffectOnShow() {
224 if (!mWasCanMakePaymentUsed) return;
225
226 int effectOnShow = 0;
227 if (mWasShowCalled) effectOnShow |= CMP_SHOW_DID_SHOW;
228 if (mCouldMakePayment) effectOnShow |= CMP_SHOW_COULD_MAKE_PAYMENT;
229
230 RecordHistogram.recordEnumeratedHistogram(
231 "PaymentRequest.CanMakePayment.Used.EffetOnShow", effectOnShow, CMP_SHOW_MAX);
232 }
233
234 /**
235 * Records the completion status depending on the the usage and return value of the
236 * CanMakePaymentMethod.
237 *
238 * @param completionStatus Whether the transaction was completed or aborted.
239 */
240 private void recordCanMakePaymentEffectOnCompletion(int completionStatus) {
241 if (!mWasShowCalled) return;
242
243 String histogramName = "PaymentRequest.CanMakePayment.";
244
245 if (!mWasCanMakePaymentUsed) {
246 histogramName += "NotUsed.WithShowEffectOnCompletion";
247 } else if (mCouldMakePayment) {
248 histogramName += "Used.TrueWithShowEffectOnCompletion";
249 } else {
250 histogramName += "Used.FalseWithShowEffectOnCompletion";
251 }
252
253 RecordHistogram.recordEnumeratedHistogram(
254 histogramName, completionStatus, COMPLETION_STATUS_MAX);
255 }
256 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698