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

Unified Diff: components/payments/core/journey_logger.cc

Issue 2750103005: [Payments] Move journey logger to native. (Closed)
Patch Set: Addressed comments Created 3 years, 9 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: components/payments/core/journey_logger.cc
diff --git a/components/payments/core/journey_logger.cc b/components/payments/core/journey_logger.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6b48fadfe3855e6fd2671aba0012095438086350
--- /dev/null
+++ b/components/payments/core/journey_logger.cc
@@ -0,0 +1,176 @@
+// Copyright 2017 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.
+
+#include "components/payments/core/journey_logger.h"
+
+#include <algorithm>
+
+#include "base/metrics/histogram_functions.h"
+#include "base/metrics/histogram_macros.h"
+
+namespace payments {
+
+JourneyLogger::JourneyLogger()
+ : was_can_make_payments_used_(false),
+ could_make_payment_(false),
+ was_show_called_(false) {}
+
+JourneyLogger::~JourneyLogger() {}
+
+void JourneyLogger::IncrementSelectionAdds(int section) {
+ DCHECK(section < SECTION_MAX);
+ sections_[section].number_selection_adds_++;
+}
+
+void JourneyLogger::IncrementSelectionChanges(int section) {
+ DCHECK(section < SECTION_MAX);
+ sections_[section].number_selection_changes_++;
+}
+
+void JourneyLogger::IncrementSelectionEdits(int section) {
+ DCHECK(section < SECTION_MAX);
+ sections_[section].number_selection_edits_++;
+}
+
+void JourneyLogger::SetNumberOfSuggestionsShown(int section, int number) {
+ DCHECK(section < SECTION_MAX);
+ sections_[section].number_suggestions_shown_ = number;
+ sections_[section].is_requested_ = true;
+}
+
+void JourneyLogger::SetCanMakePaymentValue(bool value) {
+ was_can_make_payments_used_ = true;
+ could_make_payment_ |= value;
+}
+
+void JourneyLogger::SetShowCalled() {
+ was_show_called_ = true;
+}
+
+void JourneyLogger::RecordJourneyStatsHistograms(
+ const std::string& submission_type) {
+ RecordSectionSpecificStats(submission_type);
+
+ // Record the CanMakePayment metrics based on whether the transaction was
+ // completed or aborted by the user (UserAborted) or otherwise (OtherAborted).
+ RecordCanMakePaymentStats(submission_type.find("Abort") != std::string::npos
+ ? COMPLETION_STATUS_ABORTED
+ : COMPLETION_STATUS_COMPLETED);
+}
+
+void JourneyLogger::RecordSectionSpecificStats(
+ const std::string& submission_type) {
+ // Record whether the user had suggestions for each requested information.
+ bool user_had_all_requested_information = true;
+
+ for (int i = 0; i < NUMBER_OF_SECTIONS; ++i) {
+ std::string name_suffix = "";
+ switch (i) {
+ case SECTION_SHIPPING_ADDRESS:
+ name_suffix = "ShippingAddress." + submission_type;
+ break;
+ case SECTION_CONTACT_INFO:
+ name_suffix = "ContactInfo." + submission_type;
+ break;
+ case SECTION_CREDIT_CARDS:
+ name_suffix = "CreditCards." + submission_type;
+ break;
+ default:
+ break;
+ }
+
+ DCHECK(!name_suffix.empty());
+
+ // Only log the metrics for a section if it was requested by the merchant.
+ if (sections_[i].is_requested_) {
+ base::UmaHistogramCustomCounts(
+ "PaymentRequest.NumberOfSelectionAdds." + name_suffix,
+ std::min(sections_[i].number_selection_adds_, MAX_EXPECTED_SAMPLE),
+ MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS);
+ base::UmaHistogramCustomCounts(
+ "PaymentRequest.NumberOfSelectionChanges." + name_suffix,
+ std::min(sections_[i].number_selection_changes_, MAX_EXPECTED_SAMPLE),
+ MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS);
+ base::UmaHistogramCustomCounts(
+ "PaymentRequest.NumberOfSelectionEdits." + name_suffix,
+ std::min(sections_[i].number_selection_edits_, MAX_EXPECTED_SAMPLE),
+ MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS);
+ base::UmaHistogramCustomCounts(
+ "PaymentRequest.NumberOfSuggestionsShown." + name_suffix,
+ std::min(sections_[i].number_suggestions_shown_, MAX_EXPECTED_SAMPLE),
+ MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS);
+
+ if (sections_[i].number_suggestions_shown_ == 0) {
+ user_had_all_requested_information = false;
+ }
+ }
+ }
+
+ // Record metrics about completion based on whether the user had suggestions
+ // for each requested information.
+ CompletionStatus completion_status =
+ submission_type.find("Abort") != std::string::npos
+ ? COMPLETION_STATUS_ABORTED
+ : COMPLETION_STATUS_COMPLETED;
+ if (user_had_all_requested_information) {
+ base::UmaHistogramEnumeration(
+ "PaymentRequest.UserHadSuggestionsForEverything."
+ "EffectOnCompletion",
+ completion_status, COMPLETION_STATUS_MAX);
+ } else {
+ base::UmaHistogramEnumeration(
+ "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
+ "EffectOnCompletion",
+ completion_status, COMPLETION_STATUS_MAX);
+ }
+}
+
+void JourneyLogger::RecordCanMakePaymentStats(
+ CompletionStatus completion_status) {
+ // Record CanMakePayment usage.
+ UMA_HISTOGRAM_ENUMERATION("PaymentRequest.CanMakePayment.Usage",
+ was_can_make_payments_used_
+ ? CAN_MAKE_PAYMENT_USED
+ : CAN_MAKE_PAYMENT_NOT_USED,
+ CAN_MAKE_PAYMENT_USE_MAX);
+
+ RecordCanMakePaymentEffectOnShow();
+ RecordCanMakePaymentEffectOnCompletion(completion_status);
+}
+
+void JourneyLogger::RecordCanMakePaymentEffectOnShow() {
+ if (!was_can_make_payments_used_)
+ return;
+
+ int effect_on_show = 0;
+ if (was_show_called_)
+ effect_on_show |= CMP_SHOW_DID_SHOW;
+ if (could_make_payment_)
+ effect_on_show |= CMP_SHOW_COULD_MAKE_PAYMENT_;
+
+ LOG(ERROR) << "Effect is " << effect_on_show;
Mathieu 2017/03/24 13:46:44 remove?
sebsg 2017/03/24 13:53:19 Done.
+
+ UMA_HISTOGRAM_ENUMERATION("PaymentRequest.CanMakePayment.Used.EffectOnShow",
+ effect_on_show, CMP_SHOW_MAX);
+}
+
+void JourneyLogger::RecordCanMakePaymentEffectOnCompletion(
+ CompletionStatus completion_status) {
+ if (!was_show_called_)
+ return;
+
+ std::string histogram_name = "PaymentRequest.CanMakePayment.";
+ if (!was_can_make_payments_used_) {
+ histogram_name += "NotUsed.WithShowEffectOnCompletion";
+ } else if (could_make_payment_) {
+ histogram_name += "Used.TrueWithShowEffectOnCompletion";
+ } else {
+ histogram_name += "Used.FalseWithShowEffectOnCompletion";
+ }
+
+ base::UmaHistogramEnumeration(histogram_name, completion_status,
+ COMPLETION_STATUS_MAX);
+}
+
+} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698