autofill_metrics.h revision ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16
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.
4
5#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_
6#define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_
7
8#include <stddef.h>
9#include <string>
10
11#include "base/basictypes.h"
12#include "components/autofill/core/browser/autofill_manager_delegate.h"
13#include "components/autofill/core/browser/field_types.h"
14
15namespace base {
16class TimeDelta;
17}
18
19namespace autofill {
20
21class AutofillMetrics {
22 public:
23  // The possible results of an Autocheckout flow.
24  enum AutocheckoutBuyFlowMetric {
25    // The user has initated Autocheckout. The baseline metric.
26    AUTOCHECKOUT_BUY_FLOW_STARTED,
27    // Autocheckout completed successfully.
28    AUTOCHECKOUT_BUY_FLOW_SUCCESS,
29    // Autocheckout failed due to missing server side data.
30    AUTOCHECKOUT_BUY_FLOW_MISSING_FIELDMAPPING,
31    // Autocheckout failed due to a missing proceed element.
32    AUTOCHECKOUT_BUY_FLOW_MISSING_ADVANCE_ELEMENT,
33    // Autocheckout failed for any number of other reasons, e.g, the proceed
34    // element click failed, the page numbers were not increasing, etc.
35    AUTOCHECKOUT_BUY_FLOW_CANNOT_PROCEED,
36    // Autocheckout failed due to a missing click element before form filling.
37    AUTOCHECKOUT_BUY_FLOW_MISSING_CLICK_ELEMENT_BEFORE_FORM_FILLING,
38    // Autocheckout failed due to a missing click element after form filling.
39    AUTOCHECKOUT_BUY_FLOW_MISSING_CLICK_ELEMENT_AFTER_FORM_FILLING,
40    NUM_AUTOCHECKOUT_BUY_FLOW_METRICS
41  };
42
43  // The success or failure of Autocheckout.
44  enum AutocheckoutCompletionStatus {
45    AUTOCHECKOUT_CANCELLED,  // The user canceled Autocheckout while it was in
46                             // progress.
47    AUTOCHECKOUT_FAILED,     // The user canceled out of the dialog after
48                             // an Autocheckout failure.
49    AUTOCHECKOUT_SUCCEEDED,  // The dialog was closed after Autocheckout
50                             // succeeded.
51  };
52
53  // The action a user took to dismiss a bubble.
54  enum BubbleMetric {
55    BUBBLE_CREATED = 0,         // The bubble was created.
56    BUBBLE_ACCEPTED,            // The user accepted, i.e. confirmed, the
57                                // bubble.
58    BUBBLE_DISMISSED,           // The user dismissed the bubble.
59    BUBBLE_IGNORED,             // The user did not interact with the bubble.
60    BUBBLE_COULD_BE_DISPLAYED,  // The bubble could be displayed.
61    NUM_BUBBLE_METRICS,
62  };
63
64  enum DeveloperEngagementMetric {
65    // Parsed a form that is potentially autofillable.
66    FILLABLE_FORM_PARSED = 0,
67    // Parsed a form that is potentially autofillable and contains at least one
68    // web developer-specified field type hint, a la
69    // http://is.gd/whatwg_autocomplete
70    FILLABLE_FORM_CONTAINS_TYPE_HINTS,
71    NUM_DEVELOPER_ENGAGEMENT_METRICS,
72  };
73
74  // The action the user took to dismiss a dialog.
75  enum DialogDismissalAction {
76    DIALOG_ACCEPTED = 0,  // The user accepted, i.e. submitted, the dialog.
77    DIALOG_CANCELED,      // The user canceled out of the dialog.
78  };
79
80  // The state of the Autofill dialog when it was dismissed.
81  enum DialogDismissalState {
82    // The user submitted with no data available to save.
83    DIALOG_ACCEPTED_EXISTING_DATA,
84    // The saved details to Online Wallet on submit.
85    DIALOG_ACCEPTED_SAVE_TO_WALLET,
86    // The saved details to the local Autofill database on submit.
87    DIALOG_ACCEPTED_SAVE_TO_AUTOFILL,
88    // The user submitted without saving any edited sections.
89    DIALOG_ACCEPTED_NO_SAVE,
90    // The user canceled with no edit UI showing.
91    DIALOG_CANCELED_NO_EDITS,
92    // The user canceled with edit UI showing, but no invalid fields.
93    DIALOG_CANCELED_NO_INVALID_FIELDS,
94    // The user canceled with at least one invalid field.
95    DIALOG_CANCELED_WITH_INVALID_FIELDS,
96    // The user canceled while the sign-in form was showing.
97    DIALOG_CANCELED_DURING_SIGNIN,
98    NUM_DIALOG_DISMISSAL_STATES
99  };
100
101  // The initial state of user that's interacting with a freshly shown Autofill
102  // dialog.
103  enum DialogInitialUserStateMetric {
104    // Could not determine the user's state due to failure to communicate with
105    // the Wallet server.
106    DIALOG_USER_STATE_UNKNOWN = 0,
107    // Not signed in, no verified Autofill profiles.
108    DIALOG_USER_NOT_SIGNED_IN_NO_AUTOFILL,
109    // Not signed in, has verified Autofill profiles.
110    DIALOG_USER_NOT_SIGNED_IN_HAS_AUTOFILL,
111    // Signed in, no Wallet items, no verified Autofill profiles.
112    DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL,
113    // Signed in, no Wallet items, has verified Autofill profiles.
114    DIALOG_USER_SIGNED_IN_NO_WALLET_HAS_AUTOFILL,
115    // Signed in, has Wallet items, no verified Autofill profiles.
116    DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL,
117    // Signed in, has Wallet items, has verified Autofill profiles.
118    DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL,
119    NUM_DIALOG_INITIAL_USER_STATE_METRICS
120  };
121
122  // Events related to the Autofill popup shown in a requestAutocomplete or
123  // Autocheckout dialog.
124  enum DialogPopupEvent {
125    // An Autofill popup was shown.
126    DIALOG_POPUP_SHOWN = 0,
127    // The user chose to fill the form with a suggestion from the popup.
128    DIALOG_POPUP_FORM_FILLED,
129    NUM_DIALOG_POPUP_EVENTS
130  };
131
132  // For measuring the frequency of security warnings or errors that can come
133  // up as part of the requestAutocomplete flow.
134  enum DialogSecurityMetric {
135    // Baseline metric: The dialog was shown.
136    SECURITY_METRIC_DIALOG_SHOWN = 0,
137    // Credit card requested over non-secure protocol.
138    SECURITY_METRIC_CREDIT_CARD_OVER_HTTP,
139    // Autocomplete data requested from a frame hosted on an origin not matching
140    // the main frame's origin.
141    SECURITY_METRIC_CROSS_ORIGIN_FRAME,
142    NUM_DIALOG_SECURITY_METRICS
143  };
144
145  // For measuring how users are interacting with the Autofill dialog UI.
146  enum DialogUiEvent {
147    // Baseline metric: The dialog was shown.
148    DIALOG_UI_SHOWN = 0,
149
150    // Dialog dismissal actions:
151    DIALOG_UI_ACCEPTED,
152    DIALOG_UI_CANCELED,
153
154    // Selections within the account switcher:
155    // Switched from a Wallet account to local Autofill data.
156    DIALOG_UI_ACCOUNT_CHOOSER_SWITCHED_TO_AUTOFILL,
157    // Switched from local Autofill data to a Wallet account.
158    DIALOG_UI_ACCOUNT_CHOOSER_SWITCHED_TO_WALLET,
159    // Switched from one Wallet account to another one.
160    DIALOG_UI_ACCOUNT_CHOOSER_SWITCHED_WALLET_ACCOUNT,
161
162    // The sign-in UI was shown.
163    DIALOG_UI_SIGNIN_SHOWN,
164
165    // Selecting a different item from a suggestion menu dropdown:
166    DIALOG_UI_EMAIL_SELECTED_SUGGESTION_CHANGED,
167    DIALOG_UI_BILLING_SELECTED_SUGGESTION_CHANGED,
168    DIALOG_UI_CC_BILLING_SELECTED_SUGGESTION_CHANGED,
169    DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED,
170    DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED,
171
172    // Showing the editing UI for a section of the dialog:
173    DIALOG_UI_EMAIL_EDIT_UI_SHOWN,
174    DIALOG_UI_BILLING_EDIT_UI_SHOWN,
175    DIALOG_UI_CC_BILLING_EDIT_UI_SHOWN,
176    DIALOG_UI_SHIPPING_EDIT_UI_SHOWN,
177    DIALOG_UI_CC_EDIT_UI_SHOWN,
178
179    // Adding a new item in a section of the dialog:
180    DIALOG_UI_EMAIL_ITEM_ADDED,
181    DIALOG_UI_BILLING_ITEM_ADDED,
182    DIALOG_UI_CC_BILLING_ITEM_ADDED,
183    DIALOG_UI_SHIPPING_ITEM_ADDED,
184    DIALOG_UI_CC_ITEM_ADDED,
185
186    NUM_DIALOG_UI_EVENTS
187  };
188
189  enum InfoBarMetric {
190    INFOBAR_SHOWN = 0,  // We showed an infobar, e.g. prompting to save credit
191                        // card info.
192    INFOBAR_ACCEPTED,   // The user explicitly accepted the infobar.
193    INFOBAR_DENIED,     // The user explicitly denied the infobar.
194    INFOBAR_IGNORED,    // The user completely ignored the infobar (logged on
195                        // tab close).
196    NUM_INFO_BAR_METRICS,
197  };
198
199  // Metrics measuring how well we predict field types.  Exactly three such
200  // metrics are logged for each fillable field in a submitted form: for
201  // the heuristic prediction, for the crowd-sourced prediction, and for the
202  // overall prediction.
203  enum FieldTypeQualityMetric {
204    TYPE_UNKNOWN = 0,  // Offered no prediction.
205    TYPE_MATCH,        // Predicted correctly.
206    TYPE_MISMATCH,     // Predicted incorrectly.
207    NUM_FIELD_TYPE_QUALITY_METRICS,
208  };
209
210  enum QualityMetric {
211    // Logged for each potentially fillable field in a submitted form.
212    FIELD_SUBMITTED = 0,
213
214    // A simple successs metric, logged for each field that returns true for
215    // |is_autofilled()|.
216    FIELD_AUTOFILLED,
217
218    // A simple failure metric, logged for each field that returns false for
219    // |is_autofilled()| but has a value that is present in the personal data
220    // manager.
221    FIELD_NOT_AUTOFILLED,
222
223    // The below are only logged when |FIELD_AUTOFILL_FAILED| is also logged.
224    NOT_AUTOFILLED_HEURISTIC_TYPE_UNKNOWN,
225    NOT_AUTOFILLED_HEURISTIC_TYPE_MATCH,
226    NOT_AUTOFILLED_HEURISTIC_TYPE_MISMATCH,
227    NOT_AUTOFILLED_SERVER_TYPE_UNKNOWN,
228    NOT_AUTOFILLED_SERVER_TYPE_MATCH,
229    NOT_AUTOFILLED_SERVER_TYPE_MISMATCH,
230    NUM_QUALITY_METRICS,
231  };
232
233  // Each of these is logged at most once per query to the server, which in turn
234  // occurs at most once per page load.
235  enum ServerQueryMetric {
236    QUERY_SENT = 0,           // Sent a query to the server.
237    QUERY_RESPONSE_RECEIVED,  // Received a response.
238    QUERY_RESPONSE_PARSED,    // Successfully parsed the server response.
239
240    // The response was parseable, but provided no improvements relative to our
241    // heuristics.
242    QUERY_RESPONSE_MATCHED_LOCAL_HEURISTICS,
243
244    // Our heuristics detected at least one auto-fillable field, and the server
245    // response overrode the type of at least one field.
246    QUERY_RESPONSE_OVERRODE_LOCAL_HEURISTICS,
247
248    // Our heuristics did not detect any auto-fillable fields, but the server
249    // response did detect at least one.
250    QUERY_RESPONSE_WITH_NO_LOCAL_HEURISTICS,
251    NUM_SERVER_QUERY_METRICS,
252  };
253
254  // Each of these metrics is logged only for potentially autofillable forms,
255  // i.e. forms with at least three fields, etc.
256  // These are used to derive certain "user happiness" metrics.  For example, we
257  // can compute the ratio (USER_DID_EDIT_AUTOFILLED_FIELD / USER_DID_AUTOFILL)
258  // to see how often users have to correct autofilled data.
259  enum UserHappinessMetric {
260    // Loaded a page containing forms.
261    FORMS_LOADED,
262    // Submitted a fillable form -- i.e. one with at least three field values
263    // that match the user's stored Autofill data -- and all matching fields
264    // were autofilled.
265    SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL,
266    // Submitted a fillable form and some (but not all) matching fields were
267    // autofilled.
268    SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME,
269    // Submitted a fillable form and no fields were autofilled.
270    SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE,
271    // Submitted a non-fillable form.
272    SUBMITTED_NON_FILLABLE_FORM,
273
274    // User manually filled one of the form fields.
275    USER_DID_TYPE,
276    // We showed a popup containing Autofill suggestions.
277    SUGGESTIONS_SHOWN,
278    // Same as above, but only logged once per page load.
279    SUGGESTIONS_SHOWN_ONCE,
280    // User autofilled at least part of the form.
281    USER_DID_AUTOFILL,
282    // Same as above, but only logged once per page load.
283    USER_DID_AUTOFILL_ONCE,
284    // User edited a previously autofilled field.
285    USER_DID_EDIT_AUTOFILLED_FIELD,
286    // Same as above, but only logged once per page load.
287    USER_DID_EDIT_AUTOFILLED_FIELD_ONCE,
288    NUM_USER_HAPPINESS_METRICS,
289  };
290
291  // For measuring the network request time of various Wallet API calls. See
292  // WalletClient::RequestType.
293  enum WalletApiCallMetric {
294    UNKNOWN_API_CALL,  // Catch all. Should never be used.
295    ACCEPT_LEGAL_DOCUMENTS,
296    AUTHENTICATE_INSTRUMENT,
297    GET_FULL_WALLET,
298    GET_WALLET_ITEMS,
299    SEND_STATUS,
300    SAVE_TO_WALLET,
301  };
302
303  // For measuring the frequency of errors while communicating with the Wallet
304  // server.
305  enum WalletErrorMetric {
306    // Baseline metric: Issued a request to the Wallet server.
307    WALLET_ERROR_BASELINE_ISSUED_REQUEST = 0,
308    // A fatal error occured while communicating with the Wallet server. This
309    // value has been deprecated.
310    WALLET_FATAL_ERROR_DEPRECATED,
311    // Received a malformed response from the Wallet server.
312    WALLET_MALFORMED_RESPONSE,
313    // A network error occured while communicating with the Wallet server.
314    WALLET_NETWORK_ERROR,
315    // The request was malformed.
316    WALLET_BAD_REQUEST,
317    // Risk deny, unsupported country, or account closed.
318    WALLET_BUYER_ACCOUNT_ERROR,
319    // Unknown server side error.
320    WALLET_INTERNAL_ERROR,
321    // API call had missing or invalid parameters.
322    WALLET_INVALID_PARAMS,
323    // Online Wallet is down.
324    WALLET_SERVICE_UNAVAILABLE,
325    // User needs make a cheaper transaction or not use Online Wallet. This
326    // value has been deprecated.
327    WALLET_SPENDING_LIMIT_EXCEEDED_DEPRECATED,
328    // The server API version of the request is no longer supported.
329    WALLET_UNSUPPORTED_API_VERSION,
330    // Catch all error type.
331    WALLET_UNKNOWN_ERROR,
332    // The merchant has been blacklisted for Online Wallet due to some manner
333    // of compliance violation.
334    WALLET_UNSUPPORTED_MERCHANT,
335    // Buyer Legal Address has a country which is unsupported by Wallet.
336    WALLET_BUYER_LEGAL_ADDRESS_NOT_SUPPORTED,
337    // Wallet's Know Your Customer(KYC) action is pending/failed for this user.
338    WALLET_UNVERIFIED_KNOW_YOUR_CUSTOMER_STATUS,
339    NUM_WALLET_ERROR_METRICS
340  };
341
342  // For measuring the frequency of "required actions" returned by the Wallet
343  // server.  This is similar to the autofill::wallet::RequiredAction enum;
344  // but unlike that enum, the values in this one must remain constant over
345  // time, so that the metrics can be consistently interpreted on the
346  // server-side.
347  enum WalletRequiredActionMetric {
348    // Baseline metric: Issued a request to the Wallet server.
349    WALLET_REQUIRED_ACTION_BASELINE_ISSUED_REQUEST = 0,
350    // Values from the autofill::wallet::RequiredAction enum:
351    UNKNOWN_REQUIRED_ACTION,  // Catch all type.
352    GAIA_AUTH,
353    PASSIVE_GAIA_AUTH,
354    SETUP_WALLET,
355    ACCEPT_TOS,
356    UPDATE_EXPIRATION_DATE,
357    UPGRADE_MIN_ADDRESS,
358    CHOOSE_ANOTHER_INSTRUMENT_OR_ADDRESS,
359    VERIFY_CVV,
360    INVALID_FORM_FIELD,
361    REQUIRE_PHONE_NUMBER,
362    NUM_WALLET_REQUIRED_ACTIONS
363  };
364
365  // The success or failure of downloading Autocheckout whitelist file.
366  enum AutocheckoutWhitelistDownloadStatus {
367    AUTOCHECKOUT_WHITELIST_DOWNLOAD_FAILED,
368    AUTOCHECKOUT_WHITELIST_DOWNLOAD_SUCCEEDED,
369  };
370
371  AutofillMetrics();
372  virtual ~AutofillMetrics();
373
374  // Logs how the user interacted with the Autocheckout bubble.
375  virtual void LogAutocheckoutBubbleMetric(BubbleMetric metric) const;
376
377  // Logs the result of an Autocheckout buy flow.
378  virtual void LogAutocheckoutBuyFlowMetric(
379      AutocheckoutBuyFlowMetric metric) const;
380
381  virtual void LogCreditCardInfoBarMetric(InfoBarMetric metric) const;
382
383  virtual void LogDeveloperEngagementMetric(
384      DeveloperEngagementMetric metric) const;
385
386  virtual void LogHeuristicTypePrediction(
387      FieldTypeQualityMetric metric,
388      ServerFieldType field_type,
389      const std::string& experiment_id) const;
390  virtual void LogOverallTypePrediction(
391      FieldTypeQualityMetric metric,
392      ServerFieldType field_type,
393      const std::string& experiment_id) const;
394  virtual void LogServerTypePrediction(FieldTypeQualityMetric metric,
395                                       ServerFieldType field_type,
396                                       const std::string& experiment_id) const;
397
398  virtual void LogQualityMetric(QualityMetric metric,
399                                const std::string& experiment_id) const;
400
401  virtual void LogServerQueryMetric(ServerQueryMetric metric) const;
402
403  virtual void LogUserHappinessMetric(UserHappinessMetric metric) const;
404
405  // Logs |state| to the dismissal states histogram for |dialog_type|.
406  virtual void LogDialogDismissalState(autofill::DialogType dialog_type,
407                                       DialogDismissalState state) const;
408
409  // This should be called as soon as the user's signed-in status and Wallet
410  // item count is known.  Records that a user starting out in |user_state| is
411  // interacting with a dialog of |dialog_type|.
412  virtual void LogDialogInitialUserState(
413      autofill::DialogType dialog_type,
414      DialogInitialUserStateMetric user_type) const;
415
416  // Logs the time elapsed between the dialog being shown for |dialog_type| and
417  // when it is ready for user interaction.
418  virtual void LogDialogLatencyToShow(autofill::DialogType dialog_type,
419                                         const base::TimeDelta& duration) const;
420
421  // Logs |event| to the popup events histogram for |dialog_type|.
422  virtual void LogDialogPopupEvent(autofill::DialogType dialog_type,
423                                   DialogPopupEvent event) const;
424
425  // Logs |metric| to the security metrics histogram for |dialog_type|.
426  virtual void LogDialogSecurityMetric(autofill::DialogType dialog_type,
427                                       DialogSecurityMetric metric) const;
428
429  // This should be called when the Autofill dialog, invoked by a dialog of type
430  // |dialog_type|, is closed.  |duration| should be the time elapsed between
431  // the dialog being shown and it being closed.  |dismissal_action| should
432  // indicate whether the user dismissed the dialog by submitting the form data
433  // or by canceling.
434  virtual void LogDialogUiDuration(
435      const base::TimeDelta& duration,
436      autofill::DialogType dialog_type,
437      DialogDismissalAction dismissal_action) const;
438
439  // Logs |event| to the UI events histogram for |dialog_type|.
440  virtual void LogDialogUiEvent(autofill::DialogType dialog_type,
441                                DialogUiEvent event) const;
442
443  // Logs |metric| to the Wallet errors histogram for |dialog_type|.
444  virtual void LogWalletErrorMetric(autofill::DialogType dialog_type,
445                                    WalletErrorMetric metric) const;
446
447  // Logs the network request time of Wallet API calls.
448  virtual void LogWalletApiCallDuration(
449      WalletApiCallMetric metric,
450      const base::TimeDelta& duration) const;
451
452  // Logs |required_action| to the required actions histogram for |dialog_type|.
453  virtual void LogWalletRequiredActionMetric(
454      autofill::DialogType dialog_type,
455      WalletRequiredActionMetric required_action) const;
456
457  virtual void LogAutocheckoutDuration(
458      const base::TimeDelta& duration,
459      AutocheckoutCompletionStatus status) const;
460
461  // Logs the time taken to download Autocheckout whitelist file.
462  virtual void LogAutocheckoutWhitelistDownloadDuration(
463      const base::TimeDelta& duration,
464      AutocheckoutWhitelistDownloadStatus status) const;
465
466  // This should be called when a form that has been Autofilled is submitted.
467  // |duration| should be the time elapsed between form load and submission.
468  virtual void LogFormFillDurationFromLoadWithAutofill(
469      const base::TimeDelta& duration) const;
470
471  // This should be called when a fillable form that has not been Autofilled is
472  // submitted.  |duration| should be the time elapsed between form load and
473  // submission.
474  virtual void LogFormFillDurationFromLoadWithoutAutofill(
475      const base::TimeDelta& duration) const;
476
477  // This should be called when a form that has been Autofilled is submitted.
478  // |duration| should be the time elapsed between the initial form interaction
479  // and submission.
480  virtual void LogFormFillDurationFromInteractionWithAutofill(
481      const base::TimeDelta& duration) const;
482
483  // This should be called when a fillable form that has not been Autofilled is
484  // submitted.  |duration| should be the time elapsed between the initial form
485  // interaction and submission.
486  virtual void LogFormFillDurationFromInteractionWithoutAutofill(
487      const base::TimeDelta& duration) const;
488
489  // This should be called each time a page containing forms is loaded.
490  virtual void LogIsAutofillEnabledAtPageLoad(bool enabled) const;
491
492  // This should be called each time a new profile is launched.
493  virtual void LogIsAutofillEnabledAtStartup(bool enabled) const;
494
495  // This should be called each time a new profile is launched.
496  virtual void LogStoredProfileCount(size_t num_profiles) const;
497
498  // Log the number of Autofill suggestions presented to the user when filling a
499  // form.
500  virtual void LogAddressSuggestionsCount(size_t num_suggestions) const;
501
502  // Logs the experiment id corresponding to a server query response.
503  virtual void LogServerExperimentIdForQuery(
504      const std::string& experiment_id) const;
505
506  // Logs the experiment id corresponding to an upload to the server.
507  virtual void LogServerExperimentIdForUpload(
508      const std::string& experiment_id) const;
509
510 private:
511  DISALLOW_COPY_AND_ASSIGN(AutofillMetrics);
512};
513
514}  // namespace autofill
515
516#endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_
517