Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestJourneyLogger.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestJourneyLogger.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestJourneyLogger.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..35c1d5cdaee0f86062a5b841b0a565be0c8c7f2b |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestJourneyLogger.java |
| @@ -0,0 +1,134 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.payments; |
| + |
| +import org.chromium.base.metrics.RecordHistogram; |
| + |
| +/** |
| + * A class used to record journey metrics for the Payment Request feature. |
| + */ |
| +public class PaymentRequestJourneyLogger { |
| + public static final int SECTION_CONTACT_INFO = 0; |
| + public static final int SECTION_CREDIT_CARDS = 1; |
| + public static final int SECTION_SHIPPING_ADDRESS = 2; |
| + public static final int SECTION_MAX = 3; |
| + |
| + private static final int MIN_EXPECTED_SAMPLE = 0; |
| + private static final int MAX_EXPECTED_SAMPLE = 49; |
| + private static final int NUMBER_BUCKETS = 50; |
| + |
| + private class SectionStats { |
| + private int mNumberSuggestionsShown; |
| + private int mNumberSelectionChanges; |
| + private int mNumberSelectionEdits; |
| + private int mNumberSelectionAdds; |
| + private boolean mIsRequested; |
| + } |
| + |
| + private SectionStats[] mSections; |
| + |
| + public PaymentRequestJourneyLogger() { |
| + mSections = new SectionStats[SECTION_MAX]; |
| + for (int i = 0; i < mSections.length; ++i) { |
| + mSections[i] = new SectionStats(); |
| + } |
| + } |
| + |
| + /* |
| + * Sets the number of suggestions shown for the specified section. |
| + * |
| + * @param section The section for which to log. |
| + * @param number The number of suggestions. |
| + */ |
| + public void setNumberOfSuggestionsShown(int section, int number) { |
| + assert section < SECTION_MAX; |
| + mSections[section].mNumberSuggestionsShown = number; |
| + } |
| + |
| + /* |
| + * Increments the number of selection changes for the specified section. |
| + * |
| + * @param section The section for which to log. |
| + */ |
| + public void incrementSelectionChanges(int section) { |
| + assert section < SECTION_MAX; |
| + ++mSections[section].mNumberSelectionChanges; |
|
gone
2016/10/07 18:54:28
I'd post-increment just to make it clearer.
sebsg
2016/10/07 19:40:32
Done.
|
| + } |
| + |
| + /* |
| + * Increments the number of selection edits for the specified section. |
| + * |
| + * @param section The section for which to log. |
| + */ |
| + public void incrementSelectionEdits(int section) { |
| + assert section < SECTION_MAX; |
| + ++mSections[section].mNumberSelectionEdits; |
| + } |
| + |
| + /* |
| + * Increments the number of selection adds for the specified section. |
| + * |
| + * @param section The section for which to log. |
| + */ |
| + public void incrementSelectionAdds(int section) { |
| + assert section < SECTION_MAX; |
| + ++mSections[section].mNumberSelectionAdds; |
| + } |
| + |
| + /* |
| + * Records that the section was requested by the merchant so the metrics for it will be logged. |
| + * |
| + * @param section The section that was requested by the merchant. |
| + */ |
| + public void sectionIsRequested(int section) { |
| + assert section < SECTION_MAX; |
| + mSections[section].mIsRequested = true; |
| + } |
| + |
| + /* |
| + * Records the histograms for all the sections that were requested by the merchant. This method |
| + * should be called when the payment request has either been completed or aborted. |
| + * |
| + * @param submissionType A string indicating the way the payment request was concluded. |
| + */ |
| + public void recordJourneyStatsHistograms(String submissionType) { |
| + for (int i = 0; i < mSections.length; ++i) { |
| + String nameSuffix = ""; |
| + switch (i) { |
| + case SECTION_SHIPPING_ADDRESS: |
| + nameSuffix = "ShippingAddress." + submissionType; |
| + break; |
| + case SECTION_CONTACT_INFO: |
| + nameSuffix = "ContactInfo." + submissionType; |
| + break; |
| + case SECTION_CREDIT_CARDS: |
| + nameSuffix = "CreditCards." + submissionType; |
| + break; |
| + } |
| + |
| + assert !nameSuffix.isEmpty(); |
| + |
| + // Only log the metrics for a section if it was requested by the merchant. |
| + if (mSections[i].mIsRequested) { |
| + RecordHistogram.recordCustomCountHistogram( |
| + "PaymentRequest.NumberOfSelectionAdds." + nameSuffix, |
| + Math.min(mSections[i].mNumberSelectionAdds, MAX_EXPECTED_SAMPLE), |
| + MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS); |
| + RecordHistogram.recordCustomCountHistogram( |
| + "PaymentRequest.NumberOfSelectionChanges." + nameSuffix, |
| + Math.min(mSections[i].mNumberSelectionChanges, MAX_EXPECTED_SAMPLE), |
| + MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS); |
| + RecordHistogram.recordCustomCountHistogram( |
| + "PaymentRequest.NumberOfSelectionEdits." + nameSuffix, |
| + Math.min(mSections[i].mNumberSelectionEdits, MAX_EXPECTED_SAMPLE), |
| + MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS); |
| + RecordHistogram.recordCustomCountHistogram( |
| + "PaymentRequest.NumberOfSuggestionsShown." + nameSuffix, |
| + Math.min(mSections[i].mNumberSuggestionsShown, MAX_EXPECTED_SAMPLE), |
| + MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS); |
| + } |
| + } |
| + } |
| +} |