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

Side by Side Diff: components/payments/core/journey_logger.cc

Issue 2808513002: [Payments] Add PaymentRequest checkout funnel UKMs. (Closed)
Patch Set: Addressed Mathp's comments Created 3 years, 8 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/payments/core/journey_logger.h" 5 #include "components/payments/core/journey_logger.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/metrics/histogram_functions.h" 9 #include "base/metrics/histogram_functions.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "components/autofill/core/browser/autofill_experiments.h"
12 #include "components/ukm/ukm_entry_builder.h"
13 #include "components/ukm/ukm_service.h"
14
15 namespace internal {
16 // Name constants are exposed here so they can be referenced from tests.
17 extern const char kUKMCheckoutFunnelEntryName[] =
18 "PaymentRequest.CheckoutFunnel";
19 extern const char kUKMCompletionStatusMetricName[] = "CompletionStatus";
20 extern const char kUKMLastStepMetricName[] = "LastStep";
21 } // namespace internal
11 22
12 namespace payments { 23 namespace payments {
13 24
14 namespace { 25 namespace {
15 26
16 // Returns the JourneyLogger histograms name suffix based on the |section| and 27 // Returns the JourneyLogger histograms name suffix based on the |section| and
17 // the |completion_status|. 28 // the |completion_status|.
18 std::string GetHistogramNameSuffix( 29 std::string GetHistogramNameSuffix(
19 int section, 30 int section,
20 JourneyLogger::CompletionStatus completion_status) { 31 JourneyLogger::CompletionStatus completion_status) {
(...skipping 26 matching lines...) Expand all
47 default: 58 default:
48 break; 59 break;
49 } 60 }
50 61
51 DCHECK(!name_suffix.empty()); 62 DCHECK(!name_suffix.empty());
52 return name_suffix; 63 return name_suffix;
53 } 64 }
54 65
55 } // namespace 66 } // namespace
56 67
57 JourneyLogger::JourneyLogger(bool is_incognito) 68 JourneyLogger::JourneyLogger(bool is_incognito,
69 GURL url,
70 ukm::UkmService* ukm_service)
58 : was_can_make_payments_used_(false), 71 : was_can_make_payments_used_(false),
59 could_make_payment_(false), 72 could_make_payment_(false),
60 was_show_called_(false), 73 was_show_called_(false),
61 is_incognito_(is_incognito) {} 74 is_incognito_(is_incognito),
75 events_(EVENT_NOT_SHOWN),
Mathieu 2017/04/10 15:56:18 I liked initiated
sebsg 2017/04/10 17:27:56 Done.
76 url_(url),
77 ukm_service_(ukm_service) {}
62 78
63 JourneyLogger::~JourneyLogger() {} 79 JourneyLogger::~JourneyLogger() {}
64 80
65 void JourneyLogger::IncrementSelectionAdds(Section section) { 81 void JourneyLogger::IncrementSelectionAdds(Section section) {
66 DCHECK_LT(section, SECTION_MAX); 82 DCHECK_LT(section, SECTION_MAX);
67 sections_[section].number_selection_adds_++; 83 sections_[section].number_selection_adds_++;
68 } 84 }
69 85
70 void JourneyLogger::IncrementSelectionChanges(Section section) { 86 void JourneyLogger::IncrementSelectionChanges(Section section) {
71 DCHECK_LT(section, SECTION_MAX); 87 DCHECK_LT(section, SECTION_MAX);
(...skipping 13 matching lines...) Expand all
85 101
86 void JourneyLogger::SetCanMakePaymentValue(bool value) { 102 void JourneyLogger::SetCanMakePaymentValue(bool value) {
87 was_can_make_payments_used_ = true; 103 was_can_make_payments_used_ = true;
88 could_make_payment_ |= value; 104 could_make_payment_ |= value;
89 } 105 }
90 106
91 void JourneyLogger::SetShowCalled() { 107 void JourneyLogger::SetShowCalled() {
92 was_show_called_ = true; 108 was_show_called_ = true;
93 } 109 }
94 110
111 void JourneyLogger::SetEventOccured(int event) {
112 DCHECK(event < EVENT_MAX);
113 events_ |= event;
114 }
115
95 void JourneyLogger::RecordJourneyStatsHistograms( 116 void JourneyLogger::RecordJourneyStatsHistograms(
96 CompletionStatus completion_status) { 117 CompletionStatus completion_status) {
97 RecordSectionSpecificStats(completion_status); 118 RecordSectionSpecificStats(completion_status);
98 119
99 // Record the CanMakePayment metrics based on whether the transaction was 120 // Record the CanMakePayment metrics based on whether the transaction was
100 // completed or aborted by the user (UserAborted) or otherwise (OtherAborted). 121 // completed or aborted by the user (UserAborted) or otherwise (OtherAborted).
101 RecordCanMakePaymentStats(completion_status); 122 RecordCanMakePaymentStats(completion_status);
123
124 RecordUrlKeyedMetrics(completion_status);
102 } 125 }
103 126
104 void JourneyLogger::RecordSectionSpecificStats( 127 void JourneyLogger::RecordSectionSpecificStats(
105 CompletionStatus completion_status) { 128 CompletionStatus completion_status) {
106 // Record whether the user had suggestions for each requested information. 129 // Record whether the user had suggestions for each requested information.
107 bool user_had_all_requested_information = true; 130 bool user_had_all_requested_information = true;
108 131
109 for (int i = 0; i < NUMBER_OF_SECTIONS; ++i) { 132 for (int i = 0; i < NUMBER_OF_SECTIONS; ++i) {
110 std::string name_suffix = GetHistogramNameSuffix(i, completion_status); 133 std::string name_suffix = GetHistogramNameSuffix(i, completion_status);
111 134
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } else if (could_make_payment_) { 215 } else if (could_make_payment_) {
193 histogram_name += "Used.TrueWithShowEffectOnCompletion"; 216 histogram_name += "Used.TrueWithShowEffectOnCompletion";
194 } else { 217 } else {
195 histogram_name += "Used.FalseWithShowEffectOnCompletion"; 218 histogram_name += "Used.FalseWithShowEffectOnCompletion";
196 } 219 }
197 220
198 base::UmaHistogramEnumeration(histogram_name, completion_status, 221 base::UmaHistogramEnumeration(histogram_name, completion_status,
199 COMPLETION_STATUS_MAX); 222 COMPLETION_STATUS_MAX);
200 } 223 }
201 224
225 void JourneyLogger::RecordUrlKeyedMetrics(CompletionStatus completion_status) {
226 if (!autofill::IsUkmLoggingEnabled() || !ukm_service_ || !url_.is_valid())
227 return;
228
229 // Record the Checkout Funnel UKM.
230 int32_t source_id = ukm_service_->GetNewSourceID();
231 ukm_service_->UpdateSourceURL(source_id, url_);
232 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder(
233 source_id, internal::kUKMCheckoutFunnelEntryName);
234 builder->AddMetric(internal::kUKMCompletionStatusMetricName,
235 completion_status);
236 builder->AddMetric(internal::kUKMLastStepMetricName, events_);
237 }
238
202 } // namespace payments 239 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698