Home | History | Annotate | Download | only in browser
      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 
     15 namespace base {
     16 class TimeDelta;
     17 }
     18 
     19 namespace autofill {
     20 
     21 class AutofillMetrics {
     22  public:
     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,
     31   };
     32 
     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.
     37   };
     38 
     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
     58   };
     59 
     60   // The initial state of user that's interacting with a freshly shown Autofill
     61   // dialog.
     62   enum DialogInitialUserStateMetric {
     63     // Could not determine the user's state due to failure to communicate with
     64     // the Wallet server.
     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
     79   };
     80 
     81   // Events related to the Autofill popup shown in a requestAutocomplete
     82   // dialog.
     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
     89   };
     90 
     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
    102   };
    103 
    104   // For measuring how users are interacting with the Autofill dialog UI.
    105   enum DialogUiEvent {
    106     // Baseline metric: The dialog was shown.
    107     DIALOG_UI_SHOWN = 0,
    108 
    109     // Dialog dismissal actions:
    110     DIALOG_UI_ACCEPTED,
    111     DIALOG_UI_CANCELED,
    112 
    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,
    120 
    121     // The sign-in UI was shown.
    122     DIALOG_UI_SIGNIN_SHOWN,
    123 
    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,
    130 
    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,
    137 
    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,
    144 
    145     // Also an account switcher menu item. The user selected the
    146     // "add account" option.
    147     DIALOG_UI_ACCOUNT_CHOOSER_TRIED_TO_ADD_ACCOUNT,
    148 
    149     NUM_DIALOG_UI_EVENTS
    150   };
    151 
    152   enum InfoBarMetric {
    153     INFOBAR_SHOWN = 0,  // We showed an infobar, e.g. prompting to save credit
    154                         // card info.
    155     INFOBAR_ACCEPTED,   // The user explicitly accepted the infobar.
    156     INFOBAR_DENIED,     // The user explicitly denied the infobar.
    157     INFOBAR_IGNORED,    // The user completely ignored the infobar (logged on
    158                         // tab close).
    159     NUM_INFO_BAR_METRICS,
    160   };
    161 
    162   // Metrics measuring how well we predict field types.  Exactly three such
    163   // metrics are logged for each fillable field in a submitted form: for
    164   // the heuristic prediction, for the crowd-sourced prediction, and for the
    165   // overall prediction.
    166   enum FieldTypeQualityMetric {
    167     TYPE_UNKNOWN = 0,  // Offered no prediction.
    168     TYPE_MATCH,        // Predicted correctly.
    169     TYPE_MISMATCH,     // Predicted incorrectly.
    170     NUM_FIELD_TYPE_QUALITY_METRICS,
    171   };
    172 
    173   enum QualityMetric {
    174     // Logged for each potentially fillable field in a submitted form.
    175     FIELD_SUBMITTED = 0,
    176 
    177     // A simple successs metric, logged for each field that returns true for
    178     // |is_autofilled()|.
    179     FIELD_AUTOFILLED,
    180 
    181     // A simple failure metric, logged for each field that returns false for
    182     // |is_autofilled()| but has a value that is present in the personal data
    183     // manager.
    184     FIELD_NOT_AUTOFILLED,
    185 
    186     // The below are only logged when |FIELD_AUTOFILL_FAILED| is also logged.
    187     NOT_AUTOFILLED_HEURISTIC_TYPE_UNKNOWN,
    188     NOT_AUTOFILLED_HEURISTIC_TYPE_MATCH,
    189     NOT_AUTOFILLED_HEURISTIC_TYPE_MISMATCH,
    190     NOT_AUTOFILLED_SERVER_TYPE_UNKNOWN,
    191     NOT_AUTOFILLED_SERVER_TYPE_MATCH,
    192     NOT_AUTOFILLED_SERVER_TYPE_MISMATCH,
    193     NUM_QUALITY_METRICS,
    194   };
    195 
    196   // Each of these is logged at most once per query to the server, which in turn
    197   // occurs at most once per page load.
    198   enum ServerQueryMetric {
    199     QUERY_SENT = 0,           // Sent a query to the server.
    200     QUERY_RESPONSE_RECEIVED,  // Received a response.
    201     QUERY_RESPONSE_PARSED,    // Successfully parsed the server response.
    202 
    203     // The response was parseable, but provided no improvements relative to our
    204     // heuristics.
    205     QUERY_RESPONSE_MATCHED_LOCAL_HEURISTICS,
    206 
    207     // Our heuristics detected at least one auto-fillable field, and the server
    208     // response overrode the type of at least one field.
    209     QUERY_RESPONSE_OVERRODE_LOCAL_HEURISTICS,
    210 
    211     // Our heuristics did not detect any auto-fillable fields, but the server
    212     // response did detect at least one.
    213     QUERY_RESPONSE_WITH_NO_LOCAL_HEURISTICS,
    214     NUM_SERVER_QUERY_METRICS,
    215   };
    216 
    217   // Each of these metrics is logged only for potentially autofillable forms,
    218   // i.e. forms with at least three fields, etc.
    219   // These are used to derive certain "user happiness" metrics.  For example, we
    220   // can compute the ratio (USER_DID_EDIT_AUTOFILLED_FIELD / USER_DID_AUTOFILL)
    221   // to see how often users have to correct autofilled data.
    222   enum UserHappinessMetric {
    223     // Loaded a page containing forms.
    224     FORMS_LOADED,
    225     // Submitted a fillable form -- i.e. one with at least three field values
    226     // that match the user's stored Autofill data -- and all matching fields
    227     // were autofilled.
    228     SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL,
    229     // Submitted a fillable form and some (but not all) matching fields were
    230     // autofilled.
    231     SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME,
    232     // Submitted a fillable form and no fields were autofilled.
    233     SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE,
    234     // Submitted a non-fillable form.
    235     SUBMITTED_NON_FILLABLE_FORM,
    236 
    237     // User manually filled one of the form fields.
    238     USER_DID_TYPE,
    239     // We showed a popup containing Autofill suggestions.
    240     SUGGESTIONS_SHOWN,
    241     // Same as above, but only logged once per page load.
    242     SUGGESTIONS_SHOWN_ONCE,
    243     // User autofilled at least part of the form.
    244     USER_DID_AUTOFILL,
    245     // Same as above, but only logged once per page load.
    246     USER_DID_AUTOFILL_ONCE,
    247     // User edited a previously autofilled field.
    248     USER_DID_EDIT_AUTOFILLED_FIELD,
    249     // Same as above, but only logged once per page load.
    250     USER_DID_EDIT_AUTOFILLED_FIELD_ONCE,
    251     NUM_USER_HAPPINESS_METRICS,
    252   };
    253 
    254   // For measuring the network request time of various Wallet API calls. See
    255   // WalletClient::RequestType.
    256   enum WalletApiCallMetric {
    257     UNKNOWN_API_CALL,  // Catch all. Should never be used.
    258     ACCEPT_LEGAL_DOCUMENTS,
    259     AUTHENTICATE_INSTRUMENT,
    260     GET_FULL_WALLET,
    261     GET_WALLET_ITEMS,
    262     SAVE_TO_WALLET,
    263     NUM_WALLET_API_CALLS
    264   };
    265 
    266   // For measuring the frequency of errors while communicating with the Wallet
    267   // server.
    268   enum WalletErrorMetric {
    269     // Baseline metric: Issued a request to the Wallet server.
    270     WALLET_ERROR_BASELINE_ISSUED_REQUEST = 0,
    271     // A fatal error occured while communicating with the Wallet server. This
    272     // value has been deprecated.
    273     WALLET_FATAL_ERROR_DEPRECATED,
    274     // Received a malformed response from the Wallet server.
    275     WALLET_MALFORMED_RESPONSE,
    276     // A network error occured while communicating with the Wallet server.
    277     WALLET_NETWORK_ERROR,
    278     // The request was malformed.
    279     WALLET_BAD_REQUEST,
    280     // Risk deny, unsupported country, or account closed.
    281     WALLET_BUYER_ACCOUNT_ERROR,
    282     // Unknown server side error.
    283     WALLET_INTERNAL_ERROR,
    284     // API call had missing or invalid parameters.
    285     WALLET_INVALID_PARAMS,
    286     // Online Wallet is down.
    287     WALLET_SERVICE_UNAVAILABLE,
    288     // User needs make a cheaper transaction or not use Online Wallet. This
    289     // value has been deprecated.
    290     WALLET_SPENDING_LIMIT_EXCEEDED_DEPRECATED,
    291     // The server API version of the request is no longer supported.
    292     WALLET_UNSUPPORTED_API_VERSION,
    293     // Catch all error type.
    294     WALLET_UNKNOWN_ERROR,
    295     // The merchant has been blacklisted for Online Wallet due to some manner
    296     // of compliance violation.
    297     WALLET_UNSUPPORTED_MERCHANT,
    298     // Buyer Legal Address has a country which is unsupported by Wallet.
    299     WALLET_BUYER_LEGAL_ADDRESS_NOT_SUPPORTED,
    300     // Wallet's Know Your Customer(KYC) action is pending/failed for this user.
    301     WALLET_UNVERIFIED_KNOW_YOUR_CUSTOMER_STATUS,
    302     NUM_WALLET_ERROR_METRICS
    303   };
    304 
    305   // For measuring the frequency of "required actions" returned by the Wallet
    306   // server.  This is similar to the autofill::wallet::RequiredAction enum;
    307   // but unlike that enum, the values in this one must remain constant over
    308   // time, so that the metrics can be consistently interpreted on the
    309   // server-side.
    310   enum WalletRequiredActionMetric {
    311     // Baseline metric: Issued a request to the Wallet server.
    312     WALLET_REQUIRED_ACTION_BASELINE_ISSUED_REQUEST = 0,
    313     // Values from the autofill::wallet::RequiredAction enum:
    314     UNKNOWN_REQUIRED_ACTION,  // Catch all type.
    315     GAIA_AUTH,
    316     PASSIVE_GAIA_AUTH,
    317     SETUP_WALLET,
    318     ACCEPT_TOS,
    319     UPDATE_EXPIRATION_DATE,
    320     UPGRADE_MIN_ADDRESS,
    321     CHOOSE_ANOTHER_INSTRUMENT_OR_ADDRESS,
    322     VERIFY_CVV,
    323     INVALID_FORM_FIELD,
    324     REQUIRE_PHONE_NUMBER,
    325     NUM_WALLET_REQUIRED_ACTIONS
    326   };
    327 
    328   AutofillMetrics();
    329   virtual ~AutofillMetrics();
    330 
    331   virtual void LogCreditCardInfoBarMetric(InfoBarMetric metric) const;
    332 
    333   virtual void LogDeveloperEngagementMetric(
    334       DeveloperEngagementMetric metric) const;
    335 
    336   virtual void LogHeuristicTypePrediction(
    337       FieldTypeQualityMetric metric,
    338       ServerFieldType field_type,
    339       const std::string& experiment_id) const;
    340   virtual void LogOverallTypePrediction(
    341       FieldTypeQualityMetric metric,
    342       ServerFieldType field_type,
    343       const std::string& experiment_id) const;
    344   virtual void LogServerTypePrediction(FieldTypeQualityMetric metric,
    345                                        ServerFieldType field_type,
    346                                        const std::string& experiment_id) const;
    347 
    348   virtual void LogQualityMetric(QualityMetric metric,
    349                                 const std::string& experiment_id) const;
    350 
    351   virtual void LogServerQueryMetric(ServerQueryMetric metric) const;
    352 
    353   virtual void LogUserHappinessMetric(UserHappinessMetric metric) const;
    354 
    355   // Logs |state| to the dismissal states histogram.
    356   virtual void LogDialogDismissalState(DialogDismissalState state) const;
    357 
    358   // This should be called as soon as the user's signed-in status and Wallet
    359   // item count is known.  Records that a user starting out in |user_state| is
    360   // interacting with a dialog.
    361   virtual void LogDialogInitialUserState(
    362       DialogInitialUserStateMetric user_type) const;
    363 
    364   // Logs the time elapsed between the dialog being shown and when it is ready
    365   // for user interaction.
    366   virtual void LogDialogLatencyToShow(const base::TimeDelta& duration) const;
    367 
    368   // Logs |event| to the popup events histogram.
    369   virtual void LogDialogPopupEvent(DialogPopupEvent event) const;
    370 
    371   // Logs |metric| to the security metrics histogram.
    372   virtual void LogDialogSecurityMetric(DialogSecurityMetric metric) const;
    373 
    374   // This should be called when the Autofill dialog is closed.  |duration|
    375   // should be the time elapsed between the dialog being shown and it being
    376   // closed.  |dismissal_action| should indicate whether the user dismissed
    377   // the dialog by submitting the form data or by canceling.
    378   virtual void LogDialogUiDuration(
    379       const base::TimeDelta& duration,
    380       DialogDismissalAction dismissal_action) const;
    381 
    382   // Logs |event| to the UI events histogram.
    383   virtual void LogDialogUiEvent(DialogUiEvent event) const;
    384 
    385   // Logs |metric| to the Wallet errors histogram.
    386   virtual void LogWalletErrorMetric(WalletErrorMetric metric) const;
    387 
    388   // Logs the network request time of Wallet API calls.
    389   virtual void LogWalletApiCallDuration(
    390       WalletApiCallMetric metric,
    391       const base::TimeDelta& duration) const;
    392 
    393   // Logs that the Wallet API call corresponding to |metric| was malformed.
    394   virtual void LogWalletMalformedResponseMetric(
    395       WalletApiCallMetric metric) const;
    396 
    397   // Logs |required_action| to the required actions histogram.
    398   virtual void LogWalletRequiredActionMetric(
    399       WalletRequiredActionMetric required_action) const;
    400 
    401   // Logs HTTP response codes recieved by wallet client.
    402   virtual void LogWalletResponseCode(int response_code) const;
    403 
    404   // This should be called when a form that has been Autofilled is submitted.
    405   // |duration| should be the time elapsed between form load and submission.
    406   virtual void LogFormFillDurationFromLoadWithAutofill(
    407       const base::TimeDelta& duration) const;
    408 
    409   // This should be called when a fillable form that has not been Autofilled is
    410   // submitted.  |duration| should be the time elapsed between form load and
    411   // submission.
    412   virtual void LogFormFillDurationFromLoadWithoutAutofill(
    413       const base::TimeDelta& duration) const;
    414 
    415   // This should be called when a form that has been Autofilled is submitted.
    416   // |duration| should be the time elapsed between the initial form interaction
    417   // and submission.
    418   virtual void LogFormFillDurationFromInteractionWithAutofill(
    419       const base::TimeDelta& duration) const;
    420 
    421   // This should be called when a fillable form that has not been Autofilled is
    422   // submitted.  |duration| should be the time elapsed between the initial form
    423   // interaction and submission.
    424   virtual void LogFormFillDurationFromInteractionWithoutAutofill(
    425       const base::TimeDelta& duration) const;
    426 
    427   // This should be called each time a page containing forms is loaded.
    428   virtual void LogIsAutofillEnabledAtPageLoad(bool enabled) const;
    429 
    430   // This should be called each time a new profile is launched.
    431   virtual void LogIsAutofillEnabledAtStartup(bool enabled) const;
    432 
    433   // This should be called each time a new profile is launched.
    434   virtual void LogStoredProfileCount(size_t num_profiles) const;
    435 
    436   // Log the number of Autofill suggestions presented to the user when filling a
    437   // form.
    438   virtual void LogAddressSuggestionsCount(size_t num_suggestions) const;
    439 
    440   // Logs the experiment id corresponding to a server query response.
    441   virtual void LogServerExperimentIdForQuery(
    442       const std::string& experiment_id) const;
    443 
    444   // Logs the experiment id corresponding to an upload to the server.
    445   virtual void LogServerExperimentIdForUpload(
    446       const std::string& experiment_id) const;
    447 
    448  private:
    449   DISALLOW_COPY_AND_ASSIGN(AutofillMetrics);
    450 };
    451 
    452 }  // namespace autofill
    453 
    454 #endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_
    455