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

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

Issue 2750103005: [Payments] Move journey logger to native. (Closed)
Patch Set: 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..9ae8d9a0daa93b4c6e5994a7e5700fde65b25ba1
--- /dev/null
+++ b/components/payments/core/journey_logger.cc
@@ -0,0 +1,171 @@
+// 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) {}
+
+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.
+ int completion_status = submission_type.find("Abort") != std::string::npos
+ ? COMPLETION_STATUS_ABORTED
+ : COMPLETION_STATUS_COMPLETED;
+ if (user_had_all_requested_information) {
+ UMA_HISTOGRAM_ENUMERATION(
+ "PaymentRequest.UserHadSuggestionsForEverything."
+ "EffectOnCompletion",
+ completion_status, COMPLETION_STATUS_MAX);
+ } else {
+ UMA_HISTOGRAM_ENUMERATION(
+ "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
+ "EffectOnCompletion",
+ completion_status, COMPLETION_STATUS_MAX);
+ }
+}
+
+void JourneyLogger::RecordCanMakePaymentStats(int 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_;
Mathieu 2017/03/23 21:19:48 fix
sebsg 2017/03/24 13:35:29 Done.
+
+ UMA_HISTOGRAM_ENUMERATION("PaymentRequest.CanMakePayment.Used.EffectOnShow",
+ effect_on_show, CMP_SHOW_MAX);
+}
+
+void JourneyLogger::RecordCanMakePaymentEffectOnCompletion(
+ int completion_status) {
+ if (!was_show_called_)
+ return;
+
+ std::string histogram_name = "PaymentRequest.CanMakePayment.";
+
Mathieu 2017/03/23 21:19:48 remove extra line
sebsg 2017/03/24 13:35:29 Done.
+ if (!was_can_make_payments_used_) {
+ histogram_name += "NotUsed.WithShowEffectOnCompletion";
+ } else if (could_make_payment_) {
+ histogram_name += "Used.TrueWithShowEffectOnCompletion";
+ } else {
+ histogram_name += "Used.FalseWithShowEffectOnCompletion";
+ }
+
+ UMA_HISTOGRAM_ENUMERATION(histogram_name, completion_status,
Mathieu 2017/03/23 21:19:48 this is wrong. this macro statically caches the hi
sebsg 2017/03/24 13:35:29 Done.
+ COMPLETION_STATUS_MAX);
+}
+
+} // namespace payments
« components/payments/core/journey_logger.h ('K') | « components/payments/core/journey_logger.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698