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

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

Issue 2396643002: [Payments] Add Payment Request journey metrics. (Closed)
Patch Set: Nit Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
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..8b1c621aff4081c87d67db629d97bf83a3439269
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestJourneyLogger.java
@@ -0,0 +1,127 @@
+// 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 static 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;
+ mSections[section].mIsRequested = true;
+ }
+
+ /*
+ * 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++;
+ }
+
+ /*
+ * 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 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;
+ default:
+ 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);
+ }
+ }
+ }
+}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java ('k') | chrome/android/java_sources.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698