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

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

Issue 2808513002: [Payments] Add PaymentRequest checkout funnel UKMs. (Closed)
Patch Set: Rebase 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"
11 14
12 namespace payments { 15 namespace payments {
13 16
17 namespace internal {
18 extern const char kUKMCheckoutEventsEntryName[] =
19 "PaymentRequest.CheckoutEvents";
20 extern const char kUKMCompletionStatusMetricName[] = "CompletionStatus";
21 extern const char kUKMEventsMetricName[] = "Events";
22 } // namespace internal
23
14 namespace { 24 namespace {
15 25
16 // Returns the JourneyLogger histograms name suffix based on the |section| and 26 // Returns the JourneyLogger histograms name suffix based on the |section| and
17 // the |completion_status|. 27 // the |completion_status|.
18 std::string GetHistogramNameSuffix( 28 std::string GetHistogramNameSuffix(
19 int section, 29 int section,
20 JourneyLogger::CompletionStatus completion_status) { 30 JourneyLogger::CompletionStatus completion_status) {
21 std::string name_suffix = ""; 31 std::string name_suffix = "";
22 32
23 switch (section) { 33 switch (section) {
(...skipping 23 matching lines...) Expand all
47 default: 57 default:
48 break; 58 break;
49 } 59 }
50 60
51 DCHECK(!name_suffix.empty()); 61 DCHECK(!name_suffix.empty());
52 return name_suffix; 62 return name_suffix;
53 } 63 }
54 64
55 } // namespace 65 } // namespace
56 66
57 JourneyLogger::JourneyLogger(bool is_incognito) 67 JourneyLogger::JourneyLogger(bool is_incognito,
68 const GURL& url,
69 ukm::UkmService* ukm_service)
58 : was_can_make_payments_used_(false), 70 : was_can_make_payments_used_(false),
59 could_make_payment_(false), 71 could_make_payment_(false),
60 was_show_called_(false), 72 was_show_called_(false),
61 is_incognito_(is_incognito) {} 73 is_incognito_(is_incognito),
74 events_(EVENT_INITIATED),
75 url_(url),
76 ukm_service_(ukm_service) {}
62 77
63 JourneyLogger::~JourneyLogger() {} 78 JourneyLogger::~JourneyLogger() {}
64 79
65 void JourneyLogger::IncrementSelectionAdds(Section section) { 80 void JourneyLogger::IncrementSelectionAdds(Section section) {
66 DCHECK_LT(section, SECTION_MAX); 81 DCHECK_LT(section, SECTION_MAX);
67 sections_[section].number_selection_adds_++; 82 sections_[section].number_selection_adds_++;
68 } 83 }
69 84
70 void JourneyLogger::IncrementSelectionChanges(Section section) { 85 void JourneyLogger::IncrementSelectionChanges(Section section) {
71 DCHECK_LT(section, SECTION_MAX); 86 DCHECK_LT(section, SECTION_MAX);
(...skipping 13 matching lines...) Expand all
85 100
86 void JourneyLogger::SetCanMakePaymentValue(bool value) { 101 void JourneyLogger::SetCanMakePaymentValue(bool value) {
87 was_can_make_payments_used_ = true; 102 was_can_make_payments_used_ = true;
88 could_make_payment_ |= value; 103 could_make_payment_ |= value;
89 } 104 }
90 105
91 void JourneyLogger::SetShowCalled() { 106 void JourneyLogger::SetShowCalled() {
92 was_show_called_ = true; 107 was_show_called_ = true;
93 } 108 }
94 109
110 void JourneyLogger::SetEventOccurred(Event event) {
111 events_ |= event;
112 }
113
95 void JourneyLogger::RecordJourneyStatsHistograms( 114 void JourneyLogger::RecordJourneyStatsHistograms(
96 CompletionStatus completion_status) { 115 CompletionStatus completion_status) {
97 RecordSectionSpecificStats(completion_status); 116 RecordSectionSpecificStats(completion_status);
98 117
99 // Record the CanMakePayment metrics based on whether the transaction was 118 // Record the CanMakePayment metrics based on whether the transaction was
100 // completed or aborted by the user (UserAborted) or otherwise (OtherAborted). 119 // completed or aborted by the user (UserAborted) or otherwise (OtherAborted).
101 RecordCanMakePaymentStats(completion_status); 120 RecordCanMakePaymentStats(completion_status);
121
122 RecordUrlKeyedMetrics(completion_status);
102 } 123 }
103 124
104 void JourneyLogger::RecordSectionSpecificStats( 125 void JourneyLogger::RecordSectionSpecificStats(
105 CompletionStatus completion_status) { 126 CompletionStatus completion_status) {
106 // Record whether the user had suggestions for each requested information. 127 // Record whether the user had suggestions for each requested information.
107 bool user_had_all_requested_information = true; 128 bool user_had_all_requested_information = true;
108 129
109 for (int i = 0; i < NUMBER_OF_SECTIONS; ++i) { 130 for (int i = 0; i < NUMBER_OF_SECTIONS; ++i) {
110 std::string name_suffix = GetHistogramNameSuffix(i, completion_status); 131 std::string name_suffix = GetHistogramNameSuffix(i, completion_status);
111 132
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } else if (could_make_payment_) { 213 } else if (could_make_payment_) {
193 histogram_name += "Used.TrueWithShowEffectOnCompletion"; 214 histogram_name += "Used.TrueWithShowEffectOnCompletion";
194 } else { 215 } else {
195 histogram_name += "Used.FalseWithShowEffectOnCompletion"; 216 histogram_name += "Used.FalseWithShowEffectOnCompletion";
196 } 217 }
197 218
198 base::UmaHistogramEnumeration(histogram_name, completion_status, 219 base::UmaHistogramEnumeration(histogram_name, completion_status,
199 COMPLETION_STATUS_MAX); 220 COMPLETION_STATUS_MAX);
200 } 221 }
201 222
223 void JourneyLogger::RecordUrlKeyedMetrics(CompletionStatus completion_status) {
224 if (!autofill::IsUkmLoggingEnabled() || !ukm_service_ || !url_.is_valid())
225 return;
226
227 // Record the Checkout Funnel UKM.
228 int32_t source_id = ukm_service_->GetNewSourceID();
229 ukm_service_->UpdateSourceURL(source_id, url_);
230 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder(
231 source_id, internal::kUKMCheckoutEventsEntryName);
232 builder->AddMetric(internal::kUKMCompletionStatusMetricName,
233 completion_status);
234 builder->AddMetric(internal::kUKMEventsMetricName, events_);
235 }
236
202 } // namespace payments 237 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/core/journey_logger.h ('k') | components/payments/core/journey_logger_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698