Chromium Code Reviews| OLD | NEW |
|---|---|
| 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. | |
|
Mathieu
2017/04/10 01:03:01
remove
sebsg
2017/04/10 15:30:28
Done.
| |
| 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 Loading... | |
| 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 current_step_(STEP_INITIATED), | |
| 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 Loading... | |
| 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::SetCurrentStep(CompletionStep step) { | |
| 112 current_step_ = step; | |
|
Mathieu
2017/04/10 01:03:01
Should we dcheck that step > current_step_?
sebsg
2017/04/10 15:30:28
Changed to bitfield as per you other suggestion
| |
| 113 } | |
| 114 | |
| 95 void JourneyLogger::RecordJourneyStatsHistograms( | 115 void JourneyLogger::RecordJourneyStatsHistograms( |
| 96 CompletionStatus completion_status) { | 116 CompletionStatus completion_status) { |
| 97 RecordSectionSpecificStats(completion_status); | 117 RecordSectionSpecificStats(completion_status); |
| 98 | 118 |
| 99 // Record the CanMakePayment metrics based on whether the transaction was | 119 // Record the CanMakePayment metrics based on whether the transaction was |
| 100 // completed or aborted by the user (UserAborted) or otherwise (OtherAborted). | 120 // completed or aborted by the user (UserAborted) or otherwise (OtherAborted). |
| 101 RecordCanMakePaymentStats(completion_status); | 121 RecordCanMakePaymentStats(completion_status); |
| 122 | |
| 123 RecordUkms(completion_status); | |
| 102 } | 124 } |
| 103 | 125 |
| 104 void JourneyLogger::RecordSectionSpecificStats( | 126 void JourneyLogger::RecordSectionSpecificStats( |
| 105 CompletionStatus completion_status) { | 127 CompletionStatus completion_status) { |
| 106 // Record whether the user had suggestions for each requested information. | 128 // Record whether the user had suggestions for each requested information. |
| 107 bool user_had_all_requested_information = true; | 129 bool user_had_all_requested_information = true; |
| 108 | 130 |
| 109 for (int i = 0; i < NUMBER_OF_SECTIONS; ++i) { | 131 for (int i = 0; i < NUMBER_OF_SECTIONS; ++i) { |
| 110 std::string name_suffix = GetHistogramNameSuffix(i, completion_status); | 132 std::string name_suffix = GetHistogramNameSuffix(i, completion_status); |
| 111 | 133 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 } else if (could_make_payment_) { | 214 } else if (could_make_payment_) { |
| 193 histogram_name += "Used.TrueWithShowEffectOnCompletion"; | 215 histogram_name += "Used.TrueWithShowEffectOnCompletion"; |
| 194 } else { | 216 } else { |
| 195 histogram_name += "Used.FalseWithShowEffectOnCompletion"; | 217 histogram_name += "Used.FalseWithShowEffectOnCompletion"; |
| 196 } | 218 } |
| 197 | 219 |
| 198 base::UmaHistogramEnumeration(histogram_name, completion_status, | 220 base::UmaHistogramEnumeration(histogram_name, completion_status, |
| 199 COMPLETION_STATUS_MAX); | 221 COMPLETION_STATUS_MAX); |
| 200 } | 222 } |
| 201 | 223 |
| 224 void JourneyLogger::RecordUkms(CompletionStatus completion_status) { | |
| 225 if (!autofill::IsUkmLoggingEnabled() || !ukm_service_ || !url_.is_valid()) | |
| 226 return; | |
| 227 | |
| 228 // Record the Checkout Funnel UKM. | |
| 229 int32_t source_id = ukm_service_->GetNewSourceID(); | |
| 230 ukm_service_->UpdateSourceURL(source_id, url_); | |
| 231 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder( | |
| 232 source_id, internal::kUKMCheckoutFunnelEntryName); | |
| 233 builder->AddMetric(internal::kUKMCompletionStatusMetricName, | |
| 234 completion_status); | |
| 235 builder->AddMetric(internal::kUKMLastStepMetricName, current_step_); | |
| 236 } | |
| 237 | |
| 202 } // namespace payments | 238 } // namespace payments |
| OLD | NEW |