1 // Copyright 2013 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.
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_
11 #include "base/basictypes.h"
12 #include "components/autofill/core/browser/autofill_manager_delegate.h"
13 #include "components/autofill/core/browser/field_types.h"
21 class AutofillMetrics {
23 enum DeveloperEngagementMetric {
24 // Parsed a form that is potentially autofillable.
25 FILLABLE_FORM_PARSED = 0,
26 // Parsed a form that is potentially autofillable and contains at least one
27 // web developer-specified field type hint, a la
28 // http://is.gd/whatwg_autocomplete
29 FILLABLE_FORM_CONTAINS_TYPE_HINTS,
30 NUM_DEVELOPER_ENGAGEMENT_METRICS,
33 // The action the user took to dismiss a dialog.
34 enum DialogDismissalAction {
35 DIALOG_ACCEPTED = 0, // The user accepted, i.e. submitted, the dialog.
36 DIALOG_CANCELED, // The user canceled out of the dialog.
39 // The state of the Autofill dialog when it was dismissed.
40 enum DialogDismissalState {
41 // The user submitted with no data available to save.
42 DIALOG_ACCEPTED_EXISTING_DATA,
43 // The saved details to Online Wallet on submit.
44 DIALOG_ACCEPTED_SAVE_TO_WALLET,
45 // The saved details to the local Autofill database on submit.
46 DIALOG_ACCEPTED_SAVE_TO_AUTOFILL,
47 // The user submitted without saving any edited sections.
48 DIALOG_ACCEPTED_NO_SAVE,
49 // The user canceled with no edit UI showing.
50 DIALOG_CANCELED_NO_EDITS,
51 // The user canceled with edit UI showing, but no invalid fields.
52 DIALOG_CANCELED_NO_INVALID_FIELDS,
53 // The user canceled with at least one invalid field.
54 DIALOG_CANCELED_WITH_INVALID_FIELDS,
55 // The user canceled while the sign-in form was showing.
56 DIALOG_CANCELED_DURING_SIGNIN,
57 NUM_DIALOG_DISMISSAL_STATES
60 // The initial state of user that's interacting with a freshly shown Autofill
62 enum DialogInitialUserStateMetric {
63 // Could not determine the user's state due to failure to communicate with
65 DIALOG_USER_STATE_UNKNOWN = 0,
66 // Not signed in, no verified Autofill profiles.
67 DIALOG_USER_NOT_SIGNED_IN_NO_AUTOFILL,
68 // Not signed in, has verified Autofill profiles.
69 DIALOG_USER_NOT_SIGNED_IN_HAS_AUTOFILL,
70 // Signed in, no Wallet items, no verified Autofill profiles.
71 DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL,
72 // Signed in, no Wallet items, has verified Autofill profiles.
73 DIALOG_USER_SIGNED_IN_NO_WALLET_HAS_AUTOFILL,
74 // Signed in, has Wallet items, no verified Autofill profiles.
75 DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL,
76 // Signed in, has Wallet items, has verified Autofill profiles.
77 DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL,
78 NUM_DIALOG_INITIAL_USER_STATE_METRICS
81 // Events related to the Autofill popup shown in a requestAutocomplete
83 enum DialogPopupEvent {
84 // An Autofill popup was shown.
85 DIALOG_POPUP_SHOWN = 0,
86 // The user chose to fill the form with a suggestion from the popup.
87 DIALOG_POPUP_FORM_FILLED,
88 NUM_DIALOG_POPUP_EVENTS
91 // For measuring the frequency of security warnings or errors that can come
92 // up as part of the requestAutocomplete flow.
93 enum DialogSecurityMetric {
94 // Baseline metric: The dialog was shown.
95 SECURITY_METRIC_DIALOG_SHOWN = 0,
96 // Credit card requested over non-secure protocol.
97 SECURITY_METRIC_CREDIT_CARD_OVER_HTTP,
98 // Autocomplete data requested from a frame hosted on an origin not matching
99 // the main frame's origin.
100 SECURITY_METRIC_CROSS_ORIGIN_FRAME,
101 NUM_DIALOG_SECURITY_METRICS
104 // For measuring how users are interacting with the Autofill dialog UI.
106 // Baseline metric: The dialog was shown.
109 // Dialog dismissal actions:
113 // Selections within the account switcher:
114 // Switched from a Wallet account to local Autofill data.
115 DIALOG_UI_ACCOUNT_CHOOSER_SWITCHED_TO_AUTOFILL,
116 // Switched from local Autofill data to a Wallet account.
117 DIALOG_UI_ACCOUNT_CHOOSER_SWITCHED_TO_WALLET,
118 // Switched from one Wallet account to another one.
119 DIALOG_UI_ACCOUNT_CHOOSER_SWITCHED_WALLET_ACCOUNT,
121 // The sign-in UI was shown.
122 DIALOG_UI_SIGNIN_SHOWN,
124 // Selecting a different item from a suggestion menu dropdown:
125 DEPRECATED_DIALOG_UI_EMAIL_SELECTED_SUGGESTION_CHANGED,
126 DIALOG_UI_BILLING_SELECTED_SUGGESTION_CHANGED,
127 DIALOG_UI_CC_BILLING_SELECTED_SUGGESTION_CHANGED,
128 DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED,
129 DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED,
131 // Showing the editing UI for a section of the dialog:
132 DEPRECATED_DIALOG_UI_EMAIL_EDIT_UI_SHOWN,
133 DEPRECATED_DIALOG_UI_BILLING_EDIT_UI_SHOWN,
134 DEPRECATED_DIALOG_UI_CC_BILLING_EDIT_UI_SHOWN,
135 DEPRECATED_DIALOG_UI_SHIPPING_EDIT_UI_SHOWN,
136 DEPRECATED_DIALOG_UI_CC_EDIT_UI_SHOWN,
138 // Adding a new item in a section of the dialog:
139 DEPRECATED_DIALOG_UI_EMAIL_ITEM_ADDED,
140 DIALOG_UI_BILLING_ITEM_ADDED,
141 DIALOG_UI_CC_BILLING_ITEM_ADDED,
142 DIALOG_UI_SHIPPING_ITEM_ADDED,
143 DIALOG_UI_CC_ITEM_ADDED,
149 INFOBAR_SHOWN = 0, // We showed an infobar, e.g. prompting to save credit
151 INFOBAR_ACCEPTED, // The user explicitly accepted the infobar.
152 INFOBAR_DENIED, // The user explicitly denied the infobar.
153 INFOBAR_IGNORED, // The user completely ignored the infobar (logged on
155 NUM_INFO_BAR_METRICS,
158 // Metrics measuring how well we predict field types. Exactly three such
159 // metrics are logged for each fillable field in a submitted form: for
160 // the heuristic prediction, for the crowd-sourced prediction, and for the
161 // overall prediction.
162 enum FieldTypeQualityMetric {
163 TYPE_UNKNOWN = 0, // Offered no prediction.
164 TYPE_MATCH, // Predicted correctly.
165 TYPE_MISMATCH, // Predicted incorrectly.
166 NUM_FIELD_TYPE_QUALITY_METRICS,
170 // Logged for each potentially fillable field in a submitted form.
173 // A simple successs metric, logged for each field that returns true for
174 // |is_autofilled()|.
177 // A simple failure metric, logged for each field that returns false for
178 // |is_autofilled()| but has a value that is present in the personal data
180 FIELD_NOT_AUTOFILLED,
182 // The below are only logged when |FIELD_AUTOFILL_FAILED| is also logged.
183 NOT_AUTOFILLED_HEURISTIC_TYPE_UNKNOWN,
184 NOT_AUTOFILLED_HEURISTIC_TYPE_MATCH,
185 NOT_AUTOFILLED_HEURISTIC_TYPE_MISMATCH,
186 NOT_AUTOFILLED_SERVER_TYPE_UNKNOWN,
187 NOT_AUTOFILLED_SERVER_TYPE_MATCH,
188 NOT_AUTOFILLED_SERVER_TYPE_MISMATCH,
192 // Each of these is logged at most once per query to the server, which in turn
193 // occurs at most once per page load.
194 enum ServerQueryMetric {
195 QUERY_SENT = 0, // Sent a query to the server.
196 QUERY_RESPONSE_RECEIVED, // Received a response.
197 QUERY_RESPONSE_PARSED, // Successfully parsed the server response.
199 // The response was parseable, but provided no improvements relative to our
201 QUERY_RESPONSE_MATCHED_LOCAL_HEURISTICS,
203 // Our heuristics detected at least one auto-fillable field, and the server
204 // response overrode the type of at least one field.
205 QUERY_RESPONSE_OVERRODE_LOCAL_HEURISTICS,
207 // Our heuristics did not detect any auto-fillable fields, but the server
208 // response did detect at least one.
209 QUERY_RESPONSE_WITH_NO_LOCAL_HEURISTICS,
210 NUM_SERVER_QUERY_METRICS,
213 // Each of these metrics is logged only for potentially autofillable forms,
214 // i.e. forms with at least three fields, etc.
215 // These are used to derive certain "user happiness" metrics. For example, we
216 // can compute the ratio (USER_DID_EDIT_AUTOFILLED_FIELD / USER_DID_AUTOFILL)
217 // to see how often users have to correct autofilled data.
218 enum UserHappinessMetric {
219 // Loaded a page containing forms.
221 // Submitted a fillable form -- i.e. one with at least three field values
222 // that match the user's stored Autofill data -- and all matching fields
224 SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL,
225 // Submitted a fillable form and some (but not all) matching fields were
227 SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME,
228 // Submitted a fillable form and no fields were autofilled.
229 SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE,
230 // Submitted a non-fillable form.
231 SUBMITTED_NON_FILLABLE_FORM,
233 // User manually filled one of the form fields.
235 // We showed a popup containing Autofill suggestions.
237 // Same as above, but only logged once per page load.
238 SUGGESTIONS_SHOWN_ONCE,
239 // User autofilled at least part of the form.
241 // Same as above, but only logged once per page load.
242 USER_DID_AUTOFILL_ONCE,
243 // User edited a previously autofilled field.
244 USER_DID_EDIT_AUTOFILLED_FIELD,
245 // Same as above, but only logged once per page load.
246 USER_DID_EDIT_AUTOFILLED_FIELD_ONCE,
247 NUM_USER_HAPPINESS_METRICS,
250 // For measuring the network request time of various Wallet API calls. See
251 // WalletClient::RequestType.
252 enum WalletApiCallMetric {
253 UNKNOWN_API_CALL, // Catch all. Should never be used.
254 ACCEPT_LEGAL_DOCUMENTS,
255 AUTHENTICATE_INSTRUMENT,
262 // For measuring the frequency of errors while communicating with the Wallet
264 enum WalletErrorMetric {
265 // Baseline metric: Issued a request to the Wallet server.
266 WALLET_ERROR_BASELINE_ISSUED_REQUEST = 0,
267 // A fatal error occured while communicating with the Wallet server. This
268 // value has been deprecated.
269 WALLET_FATAL_ERROR_DEPRECATED,
270 // Received a malformed response from the Wallet server.
271 WALLET_MALFORMED_RESPONSE,
272 // A network error occured while communicating with the Wallet server.
273 WALLET_NETWORK_ERROR,
274 // The request was malformed.
276 // Risk deny, unsupported country, or account closed.
277 WALLET_BUYER_ACCOUNT_ERROR,
278 // Unknown server side error.
279 WALLET_INTERNAL_ERROR,
280 // API call had missing or invalid parameters.
281 WALLET_INVALID_PARAMS,
282 // Online Wallet is down.
283 WALLET_SERVICE_UNAVAILABLE,
284 // User needs make a cheaper transaction or not use Online Wallet. This
285 // value has been deprecated.
286 WALLET_SPENDING_LIMIT_EXCEEDED_DEPRECATED,
287 // The server API version of the request is no longer supported.
288 WALLET_UNSUPPORTED_API_VERSION,
289 // Catch all error type.
290 WALLET_UNKNOWN_ERROR,
291 // The merchant has been blacklisted for Online Wallet due to some manner
292 // of compliance violation.
293 WALLET_UNSUPPORTED_MERCHANT,
294 // Buyer Legal Address has a country which is unsupported by Wallet.
295 WALLET_BUYER_LEGAL_ADDRESS_NOT_SUPPORTED,
296 // Wallet's Know Your Customer(KYC) action is pending/failed for this user.
297 WALLET_UNVERIFIED_KNOW_YOUR_CUSTOMER_STATUS,
298 NUM_WALLET_ERROR_METRICS
301 // For measuring the frequency of "required actions" returned by the Wallet
302 // server. This is similar to the autofill::wallet::RequiredAction enum;
303 // but unlike that enum, the values in this one must remain constant over
304 // time, so that the metrics can be consistently interpreted on the
306 enum WalletRequiredActionMetric {
307 // Baseline metric: Issued a request to the Wallet server.
308 WALLET_REQUIRED_ACTION_BASELINE_ISSUED_REQUEST = 0,
309 // Values from the autofill::wallet::RequiredAction enum:
310 UNKNOWN_REQUIRED_ACTION, // Catch all type.
315 UPDATE_EXPIRATION_DATE,
317 CHOOSE_ANOTHER_INSTRUMENT_OR_ADDRESS,
320 REQUIRE_PHONE_NUMBER,
321 NUM_WALLET_REQUIRED_ACTIONS
325 virtual ~AutofillMetrics();
327 virtual void LogCreditCardInfoBarMetric(InfoBarMetric metric) const;
329 virtual void LogDeveloperEngagementMetric(
330 DeveloperEngagementMetric metric) const;
332 virtual void LogHeuristicTypePrediction(
333 FieldTypeQualityMetric metric,
334 ServerFieldType field_type,
335 const std::string& experiment_id) const;
336 virtual void LogOverallTypePrediction(
337 FieldTypeQualityMetric metric,
338 ServerFieldType field_type,
339 const std::string& experiment_id) const;
340 virtual void LogServerTypePrediction(FieldTypeQualityMetric metric,
341 ServerFieldType field_type,
342 const std::string& experiment_id) const;
344 virtual void LogQualityMetric(QualityMetric metric,
345 const std::string& experiment_id) const;
347 virtual void LogServerQueryMetric(ServerQueryMetric metric) const;
349 virtual void LogUserHappinessMetric(UserHappinessMetric metric) const;
351 // Logs |state| to the dismissal states histogram.
352 virtual void LogDialogDismissalState(DialogDismissalState state) const;
354 // This should be called as soon as the user's signed-in status and Wallet
355 // item count is known. Records that a user starting out in |user_state| is
356 // interacting with a dialog.
357 virtual void LogDialogInitialUserState(
358 DialogInitialUserStateMetric user_type) const;
360 // Logs the time elapsed between the dialog being shown and when it is ready
361 // for user interaction.
362 virtual void LogDialogLatencyToShow(const base::TimeDelta& duration) const;
364 // Logs |event| to the popup events histogram.
365 virtual void LogDialogPopupEvent(DialogPopupEvent event) const;
367 // Logs |metric| to the security metrics histogram.
368 virtual void LogDialogSecurityMetric(DialogSecurityMetric metric) const;
370 // This should be called when the Autofill dialog is closed. |duration|
371 // should be the time elapsed between the dialog being shown and it being
372 // closed. |dismissal_action| should indicate whether the user dismissed
373 // the dialog by submitting the form data or by canceling.
374 virtual void LogDialogUiDuration(
375 const base::TimeDelta& duration,
376 DialogDismissalAction dismissal_action) const;
378 // Logs |event| to the UI events histogram.
379 virtual void LogDialogUiEvent(DialogUiEvent event) const;
381 // Logs |metric| to the Wallet errors histogram.
382 virtual void LogWalletErrorMetric(WalletErrorMetric metric) const;
384 // Logs the network request time of Wallet API calls.
385 virtual void LogWalletApiCallDuration(
386 WalletApiCallMetric metric,
387 const base::TimeDelta& duration) const;
389 // Logs that the Wallet API call corresponding to |metric| was malformed.
390 virtual void LogWalletMalformedResponseMetric(
391 WalletApiCallMetric metric) const;
393 // Logs |required_action| to the required actions histogram.
394 virtual void LogWalletRequiredActionMetric(
395 WalletRequiredActionMetric required_action) const;
397 // Logs HTTP response codes recieved by wallet client.
398 virtual void LogWalletResponseCode(int response_code) const;
400 // This should be called when a form that has been Autofilled is submitted.
401 // |duration| should be the time elapsed between form load and submission.
402 virtual void LogFormFillDurationFromLoadWithAutofill(
403 const base::TimeDelta& duration) const;
405 // This should be called when a fillable form that has not been Autofilled is
406 // submitted. |duration| should be the time elapsed between form load and
408 virtual void LogFormFillDurationFromLoadWithoutAutofill(
409 const base::TimeDelta& duration) const;
411 // This should be called when a form that has been Autofilled is submitted.
412 // |duration| should be the time elapsed between the initial form interaction
414 virtual void LogFormFillDurationFromInteractionWithAutofill(
415 const base::TimeDelta& duration) const;
417 // This should be called when a fillable form that has not been Autofilled is
418 // submitted. |duration| should be the time elapsed between the initial form
419 // interaction and submission.
420 virtual void LogFormFillDurationFromInteractionWithoutAutofill(
421 const base::TimeDelta& duration) const;
423 // This should be called each time a page containing forms is loaded.
424 virtual void LogIsAutofillEnabledAtPageLoad(bool enabled) const;
426 // This should be called each time a new profile is launched.
427 virtual void LogIsAutofillEnabledAtStartup(bool enabled) const;
429 // This should be called each time a new profile is launched.
430 virtual void LogStoredProfileCount(size_t num_profiles) const;
432 // Log the number of Autofill suggestions presented to the user when filling a
434 virtual void LogAddressSuggestionsCount(size_t num_suggestions) const;
436 // Logs the experiment id corresponding to a server query response.
437 virtual void LogServerExperimentIdForQuery(
438 const std::string& experiment_id) const;
440 // Logs the experiment id corresponding to an upload to the server.
441 virtual void LogServerExperimentIdForUpload(
442 const std::string& experiment_id) const;
445 DISALLOW_COPY_AND_ASSIGN(AutofillMetrics);
448 } // namespace autofill
450 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_