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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 #include "components/payments/core/journey_logger.h"
6
7 #include <algorithm>
8
9 #include "base/metrics/histogram_functions.h"
10 #include "base/metrics/histogram_macros.h"
11
12 namespace payments {
13
14 JourneyLogger::JourneyLogger()
15 : was_can_make_payments_used_(false),
16 could_make_payment_(false),
17 was_show_called_(false) {}
18
19 JourneyLogger::~JourneyLogger() {}
20
21 void JourneyLogger::IncrementSelectionAdds(int section) {
22 DCHECK(section < SECTION_MAX);
23 sections_[section].number_selection_adds_++;
24 }
25
26 void JourneyLogger::IncrementSelectionChanges(int section) {
27 DCHECK(section < SECTION_MAX);
28 sections_[section].number_selection_changes_++;
29 }
30
31 void JourneyLogger::IncrementSelectionEdits(int section) {
32 DCHECK(section < SECTION_MAX);
33 sections_[section].number_selection_edits_++;
34 }
35
36 void JourneyLogger::SetNumberOfSuggestionsShown(int section, int number) {
37 DCHECK(section < SECTION_MAX);
38 sections_[section].number_suggestions_shown_ = number;
39 sections_[section].is_requested_ = true;
40 }
41
42 void JourneyLogger::SetCanMakePaymentValue(bool value) {
43 was_can_make_payments_used_ = true;
44 could_make_payment_ |= value;
45 }
46
47 void JourneyLogger::SetShowCalled() {
48 was_show_called_ = true;
49 }
50
51 void JourneyLogger::RecordJourneyStatsHistograms(
52 const std::string& submission_type) {
53 RecordSectionSpecificStats(submission_type);
54
55 // Record the CanMakePayment metrics based on whether the transaction was
56 // completed or aborted by the user (UserAborted) or otherwise (OtherAborted).
57 RecordCanMakePaymentStats(submission_type.find("Abort") != std::string::npos
58 ? COMPLETION_STATUS_ABORTED
59 : COMPLETION_STATUS_COMPLETED);
60 }
61
62 void JourneyLogger::RecordSectionSpecificStats(
63 const std::string& submission_type) {
64 // Record whether the user had suggestions for each requested information.
65 bool user_had_all_requested_information = true;
66
67 for (int i = 0; i < NUMBER_OF_SECTIONS; ++i) {
68 std::string name_suffix = "";
69 switch (i) {
70 case SECTION_SHIPPING_ADDRESS:
71 name_suffix = "ShippingAddress." + submission_type;
72 break;
73 case SECTION_CONTACT_INFO:
74 name_suffix = "ContactInfo." + submission_type;
75 break;
76 case SECTION_CREDIT_CARDS:
77 name_suffix = "CreditCards." + submission_type;
78 break;
79 default:
80 break;
81 }
82
83 DCHECK(!name_suffix.empty());
84
85 // Only log the metrics for a section if it was requested by the merchant.
86 if (sections_[i].is_requested_) {
87 base::UmaHistogramCustomCounts(
88 "PaymentRequest.NumberOfSelectionAdds." + name_suffix,
89 std::min(sections_[i].number_selection_adds_, MAX_EXPECTED_SAMPLE),
90 MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS);
91 base::UmaHistogramCustomCounts(
92 "PaymentRequest.NumberOfSelectionChanges." + name_suffix,
93 std::min(sections_[i].number_selection_changes_, MAX_EXPECTED_SAMPLE),
94 MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS);
95 base::UmaHistogramCustomCounts(
96 "PaymentRequest.NumberOfSelectionEdits." + name_suffix,
97 std::min(sections_[i].number_selection_edits_, MAX_EXPECTED_SAMPLE),
98 MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS);
99 base::UmaHistogramCustomCounts(
100 "PaymentRequest.NumberOfSuggestionsShown." + name_suffix,
101 std::min(sections_[i].number_suggestions_shown_, MAX_EXPECTED_SAMPLE),
102 MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS);
103
104 if (sections_[i].number_suggestions_shown_ == 0) {
105 user_had_all_requested_information = false;
106 }
107 }
108 }
109
110 // Record metrics about completion based on whether the user had suggestions
111 // for each requested information.
112 CompletionStatus completion_status =
113 submission_type.find("Abort") != std::string::npos
114 ? COMPLETION_STATUS_ABORTED
115 : COMPLETION_STATUS_COMPLETED;
116 if (user_had_all_requested_information) {
117 base::UmaHistogramEnumeration(
118 "PaymentRequest.UserHadSuggestionsForEverything."
119 "EffectOnCompletion",
120 completion_status, COMPLETION_STATUS_MAX);
121 } else {
122 base::UmaHistogramEnumeration(
123 "PaymentRequest.UserDidNotHaveSuggestionsForEverything."
124 "EffectOnCompletion",
125 completion_status, COMPLETION_STATUS_MAX);
126 }
127 }
128
129 void JourneyLogger::RecordCanMakePaymentStats(
130 CompletionStatus completion_status) {
131 // Record CanMakePayment usage.
132 UMA_HISTOGRAM_ENUMERATION("PaymentRequest.CanMakePayment.Usage",
133 was_can_make_payments_used_
134 ? CAN_MAKE_PAYMENT_USED
135 : CAN_MAKE_PAYMENT_NOT_USED,
136 CAN_MAKE_PAYMENT_USE_MAX);
137
138 RecordCanMakePaymentEffectOnShow();
139 RecordCanMakePaymentEffectOnCompletion(completion_status);
140 }
141
142 void JourneyLogger::RecordCanMakePaymentEffectOnShow() {
143 if (!was_can_make_payments_used_)
144 return;
145
146 int effect_on_show = 0;
147 if (was_show_called_)
148 effect_on_show |= CMP_SHOW_DID_SHOW;
149 if (could_make_payment_)
150 effect_on_show |= CMP_SHOW_COULD_MAKE_PAYMENT_;
151
152 LOG(ERROR) << "Effect is " << effect_on_show;
Mathieu 2017/03/24 13:46:44 remove?
sebsg 2017/03/24 13:53:19 Done.
153
154 UMA_HISTOGRAM_ENUMERATION("PaymentRequest.CanMakePayment.Used.EffectOnShow",
155 effect_on_show, CMP_SHOW_MAX);
156 }
157
158 void JourneyLogger::RecordCanMakePaymentEffectOnCompletion(
159 CompletionStatus completion_status) {
160 if (!was_show_called_)
161 return;
162
163 std::string histogram_name = "PaymentRequest.CanMakePayment.";
164 if (!was_can_make_payments_used_) {
165 histogram_name += "NotUsed.WithShowEffectOnCompletion";
166 } else if (could_make_payment_) {
167 histogram_name += "Used.TrueWithShowEffectOnCompletion";
168 } else {
169 histogram_name += "Used.FalseWithShowEffectOnCompletion";
170 }
171
172 base::UmaHistogramEnumeration(histogram_name, completion_status,
173 COMPLETION_STATUS_MAX);
174 }
175
176 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698