• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_client.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     DEPRECATED_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     // The user submitted using data already stored in Wallet.
58     DIALOG_ACCEPTED_EXISTING_WALLET_DATA,
59     // The user submitted using data already stored in Autofill.
60     DIALOG_ACCEPTED_EXISTING_AUTOFILL_DATA,
61     NUM_DIALOG_DISMISSAL_STATES
62   };
63 
64   // The initial state of user that's interacting with a freshly shown Autofill
65   // dialog.
66   enum DialogInitialUserStateMetric {
67     // Could not determine the user's state due to failure to communicate with
68     // the Wallet server.
69     DIALOG_USER_STATE_UNKNOWN = 0,
70     // Not signed in, no verified Autofill profiles.
71     DIALOG_USER_NOT_SIGNED_IN_NO_AUTOFILL,
72     // Not signed in, has verified Autofill profiles.
73     DIALOG_USER_NOT_SIGNED_IN_HAS_AUTOFILL,
74     // Signed in, no Wallet items, no verified Autofill profiles.
75     DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL,
76     // Signed in, no Wallet items, has verified Autofill profiles.
77     DIALOG_USER_SIGNED_IN_NO_WALLET_HAS_AUTOFILL,
78     // Signed in, has Wallet items, no verified Autofill profiles.
79     DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL,
80     // Signed in, has Wallet items, has verified Autofill profiles.
81     DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL,
82     NUM_DIALOG_INITIAL_USER_STATE_METRICS
83   };
84 
85   // Events related to the Autofill popup shown in a requestAutocomplete
86   // dialog.
87   enum DialogPopupEvent {
88     // An Autofill popup was shown.
89     DIALOG_POPUP_SHOWN = 0,
90     // The user chose to fill the form with a suggestion from the popup.
91     DIALOG_POPUP_FORM_FILLED,
92     NUM_DIALOG_POPUP_EVENTS
93   };
94 
95   // For measuring the frequency of security warnings or errors that can come
96   // up as part of the requestAutocomplete flow.
97   enum DialogSecurityMetric {
98     // Baseline metric: The dialog was shown.
99     SECURITY_METRIC_DIALOG_SHOWN = 0,
100     // Credit card requested over non-secure protocol.
101     SECURITY_METRIC_CREDIT_CARD_OVER_HTTP,
102     // Autocomplete data requested from a frame hosted on an origin not matching
103     // the main frame's origin.
104     SECURITY_METRIC_CROSS_ORIGIN_FRAME,
105     NUM_DIALOG_SECURITY_METRICS
106   };
107 
108   // For measuring how users are interacting with the Autofill dialog UI.
109   enum DialogUiEvent {
110     // Baseline metric: The dialog was shown.
111     DIALOG_UI_SHOWN = 0,
112 
113     // Dialog dismissal actions:
114     DIALOG_UI_ACCEPTED,
115     DIALOG_UI_CANCELED,
116 
117     // Selections within the account switcher:
118     // Switched from a Wallet account to local Autofill data.
119     DIALOG_UI_ACCOUNT_CHOOSER_SWITCHED_TO_AUTOFILL,
120     // Switched from local Autofill data to a Wallet account.
121     DIALOG_UI_ACCOUNT_CHOOSER_SWITCHED_TO_WALLET,
122     // Switched from one Wallet account to another one.
123     DIALOG_UI_ACCOUNT_CHOOSER_SWITCHED_WALLET_ACCOUNT,
124 
125     // The sign-in UI was shown.
126     DIALOG_UI_SIGNIN_SHOWN,
127 
128     // Selecting a different item from a suggestion menu dropdown:
129     DEPRECATED_DIALOG_UI_EMAIL_SELECTED_SUGGESTION_CHANGED,
130     DIALOG_UI_BILLING_SELECTED_SUGGESTION_CHANGED,
131     DIALOG_UI_CC_BILLING_SELECTED_SUGGESTION_CHANGED,
132     DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED,
133     DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED,
134 
135     // Showing the editing UI for a section of the dialog:
136     DEPRECATED_DIALOG_UI_EMAIL_EDIT_UI_SHOWN,
137     DEPRECATED_DIALOG_UI_BILLING_EDIT_UI_SHOWN,
138     DEPRECATED_DIALOG_UI_CC_BILLING_EDIT_UI_SHOWN,
139     DEPRECATED_DIALOG_UI_SHIPPING_EDIT_UI_SHOWN,
140     DEPRECATED_DIALOG_UI_CC_EDIT_UI_SHOWN,
141 
142     // Adding a new item in a section of the dialog:
143     DEPRECATED_DIALOG_UI_EMAIL_ITEM_ADDED,
144     DIALOG_UI_BILLING_ITEM_ADDED,
145     DIALOG_UI_CC_BILLING_ITEM_ADDED,
146     DIALOG_UI_SHIPPING_ITEM_ADDED,
147     DIALOG_UI_CC_ITEM_ADDED,
148 
149     // Also an account switcher menu item. The user selected the
150     // "add account" option.
151     DIALOG_UI_ACCOUNT_CHOOSER_TRIED_TO_ADD_ACCOUNT,
152 
153     NUM_DIALOG_UI_EVENTS
154   };
155 
156   enum InfoBarMetric {
157     INFOBAR_SHOWN = 0,  // We showed an infobar, e.g. prompting to save credit
158                         // card info.
159     INFOBAR_ACCEPTED,   // The user explicitly accepted the infobar.
160     INFOBAR_DENIED,     // The user explicitly denied the infobar.
161     INFOBAR_IGNORED,    // The user completely ignored the infobar (logged on
162                         // tab close).
163     NUM_INFO_BAR_METRICS,
164   };
165 
166   // Metrics measuring how well we predict field types.  Exactly three such
167   // metrics are logged for each fillable field in a submitted form: for
168   // the heuristic prediction, for the crowd-sourced prediction, and for the
169   // overall prediction.
170   enum FieldTypeQualityMetric {
171     TYPE_UNKNOWN = 0,  // Offered no prediction.
172     TYPE_MATCH,        // Predicted correctly.
173     TYPE_MISMATCH,     // Predicted incorrectly.
174     NUM_FIELD_TYPE_QUALITY_METRICS,
175   };
176 
177   // Each of these is logged at most once per query to the server, which in turn
178   // occurs at most once per page load.
179   enum ServerQueryMetric {
180     QUERY_SENT = 0,           // Sent a query to the server.
181     QUERY_RESPONSE_RECEIVED,  // Received a response.
182     QUERY_RESPONSE_PARSED,    // Successfully parsed the server response.
183 
184     // The response was parseable, but provided no improvements relative to our
185     // heuristics.
186     QUERY_RESPONSE_MATCHED_LOCAL_HEURISTICS,
187 
188     // Our heuristics detected at least one auto-fillable field, and the server
189     // response overrode the type of at least one field.
190     QUERY_RESPONSE_OVERRODE_LOCAL_HEURISTICS,
191 
192     // Our heuristics did not detect any auto-fillable fields, but the server
193     // response did detect at least one.
194     QUERY_RESPONSE_WITH_NO_LOCAL_HEURISTICS,
195     NUM_SERVER_QUERY_METRICS,
196   };
197 
198   // Each of these metrics is logged only for potentially autofillable forms,
199   // i.e. forms with at least three fields, etc.
200   // These are used to derive certain "user happiness" metrics.  For example, we
201   // can compute the ratio (USER_DID_EDIT_AUTOFILLED_FIELD / USER_DID_AUTOFILL)
202   // to see how often users have to correct autofilled data.
203   enum UserHappinessMetric {
204     // Loaded a page containing forms.
205     FORMS_LOADED,
206     // Submitted a fillable form -- i.e. one with at least three field values
207     // that match the user's stored Autofill data -- and all matching fields
208     // were autofilled.
209     SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL,
210     // Submitted a fillable form and some (but not all) matching fields were
211     // autofilled.
212     SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME,
213     // Submitted a fillable form and no fields were autofilled.
214     SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE,
215     // Submitted a non-fillable form.
216     SUBMITTED_NON_FILLABLE_FORM,
217 
218     // User manually filled one of the form fields.
219     USER_DID_TYPE,
220     // We showed a popup containing Autofill suggestions.
221     SUGGESTIONS_SHOWN,
222     // Same as above, but only logged once per page load.
223     SUGGESTIONS_SHOWN_ONCE,
224     // User autofilled at least part of the form.
225     USER_DID_AUTOFILL,
226     // Same as above, but only logged once per page load.
227     USER_DID_AUTOFILL_ONCE,
228     // User edited a previously autofilled field.
229     USER_DID_EDIT_AUTOFILLED_FIELD,
230     // Same as above, but only logged once per page load.
231     USER_DID_EDIT_AUTOFILLED_FIELD_ONCE,
232     NUM_USER_HAPPINESS_METRICS,
233   };
234 
235   // For measuring the network request time of various Wallet API calls. See
236   // WalletClient::RequestType.
237   enum WalletApiCallMetric {
238     UNKNOWN_API_CALL,  // Catch all. Should never be used.
239     ACCEPT_LEGAL_DOCUMENTS,
240     AUTHENTICATE_INSTRUMENT,
241     GET_FULL_WALLET,
242     GET_WALLET_ITEMS,
243     SAVE_TO_WALLET,
244     NUM_WALLET_API_CALLS
245   };
246 
247   // For measuring the frequency of errors while communicating with the Wallet
248   // server.
249   enum WalletErrorMetric {
250     // Baseline metric: Issued a request to the Wallet server.
251     WALLET_ERROR_BASELINE_ISSUED_REQUEST = 0,
252     // A fatal error occured while communicating with the Wallet server. This
253     // value has been deprecated.
254     WALLET_FATAL_ERROR_DEPRECATED,
255     // Received a malformed response from the Wallet server.
256     WALLET_MALFORMED_RESPONSE,
257     // A network error occured while communicating with the Wallet server.
258     WALLET_NETWORK_ERROR,
259     // The request was malformed.
260     WALLET_BAD_REQUEST,
261     // Risk deny, unsupported country, or account closed.
262     WALLET_BUYER_ACCOUNT_ERROR,
263     // Unknown server side error.
264     WALLET_INTERNAL_ERROR,
265     // API call had missing or invalid parameters.
266     WALLET_INVALID_PARAMS,
267     // Online Wallet is down.
268     WALLET_SERVICE_UNAVAILABLE,
269     // User needs make a cheaper transaction or not use Online Wallet. This
270     // value has been deprecated.
271     WALLET_SPENDING_LIMIT_EXCEEDED_DEPRECATED,
272     // The server API version of the request is no longer supported.
273     WALLET_UNSUPPORTED_API_VERSION,
274     // Catch all error type.
275     WALLET_UNKNOWN_ERROR,
276     // The merchant has been blacklisted for Online Wallet due to some manner
277     // of compliance violation.
278     WALLET_UNSUPPORTED_MERCHANT,
279     // Buyer Legal Address has a country which is unsupported by Wallet.
280     WALLET_BUYER_LEGAL_ADDRESS_NOT_SUPPORTED,
281     // Wallet's Know Your Customer(KYC) action is pending/failed for this user.
282     WALLET_UNVERIFIED_KNOW_YOUR_CUSTOMER_STATUS,
283     // Chrome version is unsupported or provided API key not allowed.
284     WALLET_UNSUPPORTED_USER_AGENT_OR_API_KEY,
285     NUM_WALLET_ERROR_METRICS
286   };
287 
288   // For measuring the frequency of "required actions" returned by the Wallet
289   // server.  This is similar to the autofill::wallet::RequiredAction enum;
290   // but unlike that enum, the values in this one must remain constant over
291   // time, so that the metrics can be consistently interpreted on the
292   // server-side.
293   enum WalletRequiredActionMetric {
294     // Baseline metric: Issued a request to the Wallet server.
295     WALLET_REQUIRED_ACTION_BASELINE_ISSUED_REQUEST = 0,
296     // Values from the autofill::wallet::RequiredAction enum:
297     UNKNOWN_REQUIRED_ACTION,  // Catch all type.
298     GAIA_AUTH,
299     PASSIVE_GAIA_AUTH,
300     SETUP_WALLET,
301     ACCEPT_TOS,
302     UPDATE_EXPIRATION_DATE,
303     UPGRADE_MIN_ADDRESS,
304     CHOOSE_ANOTHER_INSTRUMENT_OR_ADDRESS,
305     VERIFY_CVV,
306     INVALID_FORM_FIELD,
307     REQUIRE_PHONE_NUMBER,
308     NUM_WALLET_REQUIRED_ACTIONS
309   };
310 
311   AutofillMetrics();
312   virtual ~AutofillMetrics();
313 
314   virtual void LogCreditCardInfoBarMetric(InfoBarMetric metric) const;
315 
316   virtual void LogDeveloperEngagementMetric(
317       DeveloperEngagementMetric metric) const;
318 
319   virtual void LogHeuristicTypePrediction(FieldTypeQualityMetric metric,
320                                           ServerFieldType field_type) const;
321   virtual void LogOverallTypePrediction(FieldTypeQualityMetric metric,
322                                         ServerFieldType field_type) const;
323   virtual void LogServerTypePrediction(FieldTypeQualityMetric metric,
324                                        ServerFieldType field_type) const;
325 
326   virtual void LogServerQueryMetric(ServerQueryMetric metric) const;
327 
328   virtual void LogUserHappinessMetric(UserHappinessMetric metric) const;
329 
330   // Logs |state| to the dismissal states histogram.
331   virtual void LogDialogDismissalState(DialogDismissalState state) const;
332 
333   // This should be called as soon as the user's signed-in status and Wallet
334   // item count is known.  Records that a user starting out in |user_state| is
335   // interacting with a dialog.
336   virtual void LogDialogInitialUserState(
337       DialogInitialUserStateMetric user_type) const;
338 
339   // Logs the time elapsed between the dialog being shown and when it is ready
340   // for user interaction.
341   virtual void LogDialogLatencyToShow(const base::TimeDelta& duration) const;
342 
343   // Logs |event| to the popup events histogram.
344   virtual void LogDialogPopupEvent(DialogPopupEvent event) const;
345 
346   // Logs |metric| to the security metrics histogram.
347   virtual void LogDialogSecurityMetric(DialogSecurityMetric metric) const;
348 
349   // This should be called when the Autofill dialog is closed.  |duration|
350   // should be the time elapsed between the dialog being shown and it being
351   // closed.  |dismissal_action| should indicate whether the user dismissed
352   // the dialog by submitting the form data or by canceling.
353   virtual void LogDialogUiDuration(
354       const base::TimeDelta& duration,
355       DialogDismissalAction dismissal_action) const;
356 
357   // Logs |event| to the UI events histogram.
358   virtual void LogDialogUiEvent(DialogUiEvent event) const;
359 
360   // Logs |metric| to the Wallet errors histogram.
361   virtual void LogWalletErrorMetric(WalletErrorMetric metric) const;
362 
363   // Logs the network request time of Wallet API calls.
364   virtual void LogWalletApiCallDuration(
365       WalletApiCallMetric metric,
366       const base::TimeDelta& duration) const;
367 
368   // Logs that the Wallet API call corresponding to |metric| was malformed.
369   virtual void LogWalletMalformedResponseMetric(
370       WalletApiCallMetric metric) const;
371 
372   // Logs |required_action| to the required actions histogram.
373   virtual void LogWalletRequiredActionMetric(
374       WalletRequiredActionMetric required_action) const;
375 
376   // Logs HTTP response codes recieved by wallet client.
377   virtual void LogWalletResponseCode(int response_code) const;
378 
379   // This should be called when a form that has been Autofilled is submitted.
380   // |duration| should be the time elapsed between form load and submission.
381   virtual void LogFormFillDurationFromLoadWithAutofill(
382       const base::TimeDelta& duration) const;
383 
384   // This should be called when a fillable form that has not been Autofilled is
385   // submitted.  |duration| should be the time elapsed between form load and
386   // submission.
387   virtual void LogFormFillDurationFromLoadWithoutAutofill(
388       const base::TimeDelta& duration) const;
389 
390   // This should be called when a form that has been Autofilled is submitted.
391   // |duration| should be the time elapsed between the initial form interaction
392   // and submission.
393   virtual void LogFormFillDurationFromInteractionWithAutofill(
394       const base::TimeDelta& duration) const;
395 
396   // This should be called when a fillable form that has not been Autofilled is
397   // submitted.  |duration| should be the time elapsed between the initial form
398   // interaction and submission.
399   virtual void LogFormFillDurationFromInteractionWithoutAutofill(
400       const base::TimeDelta& duration) const;
401 
402   // This should be called each time a page containing forms is loaded.
403   virtual void LogIsAutofillEnabledAtPageLoad(bool enabled) const;
404 
405   // This should be called each time a new profile is launched.
406   virtual void LogIsAutofillEnabledAtStartup(bool enabled) const;
407 
408   // This should be called each time a new profile is launched.
409   virtual void LogStoredProfileCount(size_t num_profiles) const;
410 
411   // Log the number of Autofill suggestions presented to the user when filling a
412   // form.
413   virtual void LogAddressSuggestionsCount(size_t num_suggestions) const;
414 
415  private:
416   DISALLOW_COPY_AND_ASSIGN(AutofillMetrics);
417 };
418 
419 }  // namespace autofill
420 
421 #endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_
422