| 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 #ifndef COMPONENTS_PAYMENTS_CORE_JOURNEY_LOGGER_H_ | 5 #ifndef COMPONENTS_PAYMENTS_CORE_JOURNEY_LOGGER_H_ |
| 6 #define COMPONENTS_PAYMENTS_CORE_JOURNEY_LOGGER_H_ | 6 #define COMPONENTS_PAYMENTS_CORE_JOURNEY_LOGGER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "url/gurl.h" |
| 12 |
| 13 namespace ukm { |
| 14 class UkmService; |
| 15 } |
| 11 | 16 |
| 12 namespace payments { | 17 namespace payments { |
| 13 | 18 |
| 19 namespace internal { |
| 20 // Name constants are exposed here so they can be referenced from tests. |
| 21 extern const char kUKMCheckoutEventsEntryName[]; |
| 22 extern const char kUKMCompletionStatusMetricName[]; |
| 23 extern const char kUKMEventsMetricName[]; |
| 24 } // namespace internal |
| 25 |
| 14 // A class to keep track of different stats during a Payment Request journey. It | 26 // A class to keep track of different stats during a Payment Request journey. It |
| 15 // collects different metrics during the course of the checkout flow, like the | 27 // collects different metrics during the course of the checkout flow, like the |
| 16 // number of credit cards that the user added or edited. The metrics will be | 28 // number of credit cards that the user added or edited. The metrics will be |
| 17 // logged when RecordJourneyStatsHistograms is called with the completion status | 29 // logged when RecordJourneyStatsHistograms is called with the completion status |
| 18 // of the Payment Request. | 30 // of the Payment Request. |
| 19 class JourneyLogger { | 31 class JourneyLogger { |
| 20 public: | 32 public: |
| 21 // Note: These constants should always be in sync with their counterpart in | 33 // Note: These constants should always be in sync with their counterpart in |
| 22 // components/payments/content/android/java/src/org/chromium/components/ | 34 // components/payments/content/android/java/src/org/chromium/components/ |
| 23 // payments/JourneyLogger.java. | 35 // payments/JourneyLogger.java. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 39 | 51 |
| 40 // Used to log different parameters' effect on whether the transaction was | 52 // Used to log different parameters' effect on whether the transaction was |
| 41 // completed. | 53 // completed. |
| 42 enum CompletionStatus { | 54 enum CompletionStatus { |
| 43 COMPLETION_STATUS_COMPLETED = 0, | 55 COMPLETION_STATUS_COMPLETED = 0, |
| 44 COMPLETION_STATUS_USER_ABORTED = 1, | 56 COMPLETION_STATUS_USER_ABORTED = 1, |
| 45 COMPLETION_STATUS_OTHER_ABORTED = 2, | 57 COMPLETION_STATUS_OTHER_ABORTED = 2, |
| 46 COMPLETION_STATUS_MAX, | 58 COMPLETION_STATUS_MAX, |
| 47 }; | 59 }; |
| 48 | 60 |
| 61 // Used to record the different events that happened during the Payment |
| 62 // Request. |
| 63 enum Event { |
| 64 EVENT_INITIATED = 0, |
| 65 EVENT_SHOWN = 1 << 0, |
| 66 EVENT_PAY_CLICKED = 1 << 1, |
| 67 EVENT_RECEIVED_INSTRUMENT_DETAILS = 1 << 2, |
| 68 EVENT_MAX = 8, |
| 69 }; |
| 70 |
| 49 // Used to mesure the impact of the CanMakePayment return value on whether the | 71 // Used to mesure the impact of the CanMakePayment return value on whether the |
| 50 // Payment Request is shown to the user. | 72 // Payment Request is shown to the user. |
| 51 static const int CMP_SHOW_COULD_NOT_MAKE_PAYMENT_AND_DID_NOT_SHOW = 0; | 73 static const int CMP_SHOW_COULD_NOT_MAKE_PAYMENT_AND_DID_NOT_SHOW = 0; |
| 52 static const int CMP_SHOW_DID_SHOW = 1 << 0; | 74 static const int CMP_SHOW_DID_SHOW = 1 << 0; |
| 53 static const int CMP_SHOW_COULD_MAKE_PAYMENT = 1 << 1; | 75 static const int CMP_SHOW_COULD_MAKE_PAYMENT = 1 << 1; |
| 54 static const int CMP_SHOW_MAX = 4; | 76 static const int CMP_SHOW_MAX = 4; |
| 55 | 77 |
| 56 explicit JourneyLogger(bool is_incognito); | 78 JourneyLogger(bool is_incognito, |
| 79 const GURL& url, |
| 80 ukm::UkmService* ukm_service); |
| 57 ~JourneyLogger(); | 81 ~JourneyLogger(); |
| 58 | 82 |
| 59 // Increments the number of selection adds for the specified section. | 83 // Increments the number of selection adds for the specified section. |
| 60 void IncrementSelectionAdds(Section section); | 84 void IncrementSelectionAdds(Section section); |
| 61 | 85 |
| 62 // Increments the number of selection changes for the specified section. | 86 // Increments the number of selection changes for the specified section. |
| 63 void IncrementSelectionChanges(Section section); | 87 void IncrementSelectionChanges(Section section); |
| 64 | 88 |
| 65 // Increments the number of selection edits for the specified section. | 89 // Increments the number of selection edits for the specified section. |
| 66 void IncrementSelectionEdits(Section section); | 90 void IncrementSelectionEdits(Section section); |
| 67 | 91 |
| 68 // Sets the number of suggestions shown for the specified section. | 92 // Sets the number of suggestions shown for the specified section. |
| 69 void SetNumberOfSuggestionsShown(Section section, int number); | 93 void SetNumberOfSuggestionsShown(Section section, int number); |
| 70 | 94 |
| 71 // Records the fact that the merchant called CanMakePayment and records it's | 95 // Records the fact that the merchant called CanMakePayment and records it's |
| 72 // return value. | 96 // return value. |
| 73 void SetCanMakePaymentValue(bool value); | 97 void SetCanMakePaymentValue(bool value); |
| 74 | 98 |
| 75 // Records the fact that the Payment Request was shown to the user. | 99 // Records the fact that the Payment Request was shown to the user. |
| 76 void SetShowCalled(); | 100 void SetShowCalled(); |
| 77 | 101 |
| 102 // Records that an event occurred. |
| 103 void SetEventOccurred(Event event); |
| 104 |
| 78 // Records the histograms for all the sections that were requested by the | 105 // Records the histograms for all the sections that were requested by the |
| 79 // merchant and for the usage of the CanMakePayment method and its effect on | 106 // merchant and for the usage of the CanMakePayment method and its effect on |
| 80 // the transaction. This method should be called when the Payment Request has | 107 // the transaction. This method should be called when the Payment Request has |
| 81 // either been completed or aborted. | 108 // either been completed or aborted. |
| 82 void RecordJourneyStatsHistograms(CompletionStatus completion_status); | 109 void RecordJourneyStatsHistograms(CompletionStatus completion_status); |
| 83 | 110 |
| 84 private: | 111 private: |
| 85 static const int NUMBER_OF_SECTIONS = 3; | 112 static const int NUMBER_OF_SECTIONS = 3; |
| 86 | 113 |
| 87 // Note: These constants should always be in sync with their counterpart in | 114 // Note: These constants should always be in sync with their counterpart in |
| (...skipping 30 matching lines...) Expand all Loading... |
| 118 | 145 |
| 119 // Records CanMakePayment's return value effect on whether the Payment Request | 146 // Records CanMakePayment's return value effect on whether the Payment Request |
| 120 // was shown or not. | 147 // was shown or not. |
| 121 void RecordCanMakePaymentEffectOnShow(); | 148 void RecordCanMakePaymentEffectOnShow(); |
| 122 | 149 |
| 123 // Records the completion status depending on the the usage and return value | 150 // Records the completion status depending on the the usage and return value |
| 124 // of the CanMakePaymentMethod. | 151 // of the CanMakePaymentMethod. |
| 125 void RecordCanMakePaymentEffectOnCompletion( | 152 void RecordCanMakePaymentEffectOnCompletion( |
| 126 CompletionStatus completion_status); | 153 CompletionStatus completion_status); |
| 127 | 154 |
| 155 // Records the Payment Request Url Keyed Metrics. |
| 156 void RecordUrlKeyedMetrics(CompletionStatus completion_status); |
| 157 |
| 128 SectionStats sections_[NUMBER_OF_SECTIONS]; | 158 SectionStats sections_[NUMBER_OF_SECTIONS]; |
| 129 bool was_can_make_payments_used_; | 159 bool was_can_make_payments_used_; |
| 130 bool could_make_payment_; | 160 bool could_make_payment_; |
| 131 bool was_show_called_; | 161 bool was_show_called_; |
| 132 bool is_incognito_; | 162 bool is_incognito_; |
| 133 | 163 |
| 164 // Accumulates the many events that have happened during the Payment Request. |
| 165 int events_; |
| 166 |
| 167 const GURL url_; |
| 168 |
| 169 // Not owned, will outlive this object. |
| 170 ukm::UkmService* ukm_service_; |
| 171 |
| 134 DISALLOW_COPY_AND_ASSIGN(JourneyLogger); | 172 DISALLOW_COPY_AND_ASSIGN(JourneyLogger); |
| 135 }; | 173 }; |
| 136 | 174 |
| 137 } // namespace payments | 175 } // namespace payments |
| 138 | 176 |
| 139 #endif // COMPONENTS_PAYMENTS_CORE_JOURNEY_LOGGER_H_ | 177 #endif // COMPONENTS_PAYMENTS_CORE_JOURNEY_LOGGER_H_ |
| OLD | NEW |