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_client.h"
13 #include "components/autofill/core/browser/autofill_profile.h"
14 #include "components/autofill/core/browser/credit_card.h"
15 #include "components/autofill/core/browser/field_types.h"
23 class AutofillMetrics
{
25 enum DeveloperEngagementMetric
{
26 // Parsed a form that is potentially autofillable.
27 FILLABLE_FORM_PARSED
= 0,
28 // Parsed a form that is potentially autofillable and contains at least one
29 // web developer-specified field type hint, a la
30 // http://is.gd/whatwg_autocomplete
31 FILLABLE_FORM_CONTAINS_TYPE_HINTS
,
32 NUM_DEVELOPER_ENGAGEMENT_METRICS
,
35 // The action the user took to dismiss a dialog.
36 enum DialogDismissalAction
{
37 DIALOG_ACCEPTED
= 0, // The user accepted, i.e. submitted, the dialog.
38 DIALOG_CANCELED
, // The user canceled out of the dialog.
41 // The state of the Autofill dialog when it was dismissed.
42 enum DialogDismissalState
{
43 // The user submitted with no data available to save.
44 DEPRECATED_DIALOG_ACCEPTED_EXISTING_DATA
,
45 // The saved details to Online Wallet on submit.
46 DIALOG_ACCEPTED_SAVE_TO_WALLET
,
47 // The saved details to the local Autofill database on submit.
48 DIALOG_ACCEPTED_SAVE_TO_AUTOFILL
,
49 // The user submitted without saving any edited sections.
50 DIALOG_ACCEPTED_NO_SAVE
,
51 // The user canceled with no edit UI showing.
52 DIALOG_CANCELED_NO_EDITS
,
53 // The user canceled with edit UI showing, but no invalid fields.
54 DIALOG_CANCELED_NO_INVALID_FIELDS
,
55 // The user canceled with at least one invalid field.
56 DIALOG_CANCELED_WITH_INVALID_FIELDS
,
57 // The user canceled while the sign-in form was showing.
58 DIALOG_CANCELED_DURING_SIGNIN
,
59 // The user submitted using data already stored in Wallet.
60 DIALOG_ACCEPTED_EXISTING_WALLET_DATA
,
61 // The user submitted using data already stored in Autofill.
62 DIALOG_ACCEPTED_EXISTING_AUTOFILL_DATA
,
63 NUM_DIALOG_DISMISSAL_STATES
66 // The initial state of user that's interacting with a freshly shown Autofill
68 enum DialogInitialUserStateMetric
{
69 // Could not determine the user's state due to failure to communicate with
71 DIALOG_USER_STATE_UNKNOWN
= 0,
72 // Not signed in, no verified Autofill profiles.
73 DIALOG_USER_NOT_SIGNED_IN_NO_AUTOFILL
,
74 // Not signed in, has verified Autofill profiles.
75 DIALOG_USER_NOT_SIGNED_IN_HAS_AUTOFILL
,
76 // Signed in, no Wallet items, no verified Autofill profiles.
77 DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL
,
78 // Signed in, no Wallet items, has verified Autofill profiles.
79 DIALOG_USER_SIGNED_IN_NO_WALLET_HAS_AUTOFILL
,
80 // Signed in, has Wallet items, no verified Autofill profiles.
81 DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL
,
82 // Signed in, has Wallet items, has verified Autofill profiles.
83 DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL
,
84 NUM_DIALOG_INITIAL_USER_STATE_METRICS
87 // Events related to the Autofill popup shown in a requestAutocomplete
89 enum DialogPopupEvent
{
90 // An Autofill popup was shown.
91 DIALOG_POPUP_SHOWN
= 0,
92 // The user chose to fill the form with a suggestion from the popup.
93 DIALOG_POPUP_FORM_FILLED
,
94 NUM_DIALOG_POPUP_EVENTS
97 // For measuring the frequency of security warnings or errors that can come
98 // up as part of the requestAutocomplete flow.
99 enum DialogSecurityMetric
{
100 // Baseline metric: The dialog was shown.
101 SECURITY_METRIC_DIALOG_SHOWN
= 0,
102 // Credit card requested over non-secure protocol.
103 SECURITY_METRIC_CREDIT_CARD_OVER_HTTP
,
104 // Autocomplete data requested from a frame hosted on an origin not matching
105 // the main frame's origin.
106 SECURITY_METRIC_CROSS_ORIGIN_FRAME
,
107 NUM_DIALOG_SECURITY_METRICS
110 // For measuring how users are interacting with the Autofill dialog UI.
112 // Baseline metric: The dialog was shown.
115 // Dialog dismissal actions:
119 // Selections within the account switcher:
120 // Switched from a Wallet account to local Autofill data.
121 DIALOG_UI_ACCOUNT_CHOOSER_SWITCHED_TO_AUTOFILL
,
122 // Switched from local Autofill data to a Wallet account.
123 DIALOG_UI_ACCOUNT_CHOOSER_SWITCHED_TO_WALLET
,
124 // Switched from one Wallet account to another one.
125 DIALOG_UI_ACCOUNT_CHOOSER_SWITCHED_WALLET_ACCOUNT
,
127 // The sign-in UI was shown.
128 DIALOG_UI_SIGNIN_SHOWN
,
130 // Selecting a different item from a suggestion menu dropdown:
131 DEPRECATED_DIALOG_UI_EMAIL_SELECTED_SUGGESTION_CHANGED
,
132 DIALOG_UI_BILLING_SELECTED_SUGGESTION_CHANGED
,
133 DIALOG_UI_CC_BILLING_SELECTED_SUGGESTION_CHANGED
,
134 DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED
,
135 DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED
,
137 // Showing the editing UI for a section of the dialog:
138 DEPRECATED_DIALOG_UI_EMAIL_EDIT_UI_SHOWN
,
139 DEPRECATED_DIALOG_UI_BILLING_EDIT_UI_SHOWN
,
140 DEPRECATED_DIALOG_UI_CC_BILLING_EDIT_UI_SHOWN
,
141 DEPRECATED_DIALOG_UI_SHIPPING_EDIT_UI_SHOWN
,
142 DEPRECATED_DIALOG_UI_CC_EDIT_UI_SHOWN
,
144 // Adding a new item in a section of the dialog:
145 DEPRECATED_DIALOG_UI_EMAIL_ITEM_ADDED
,
146 DIALOG_UI_BILLING_ITEM_ADDED
,
147 DIALOG_UI_CC_BILLING_ITEM_ADDED
,
148 DIALOG_UI_SHIPPING_ITEM_ADDED
,
149 DIALOG_UI_CC_ITEM_ADDED
,
151 // Also an account switcher menu item. The user selected the
152 // "add account" option.
153 DIALOG_UI_ACCOUNT_CHOOSER_TRIED_TO_ADD_ACCOUNT
,
159 INFOBAR_SHOWN
= 0, // We showed an infobar, e.g. prompting to save credit
161 INFOBAR_ACCEPTED
, // The user explicitly accepted the infobar.
162 INFOBAR_DENIED
, // The user explicitly denied the infobar.
163 INFOBAR_IGNORED
, // The user completely ignored the infobar (logged on
165 NUM_INFO_BAR_METRICS
,
168 // Metrics measuring how well we predict field types. Exactly three such
169 // metrics are logged for each fillable field in a submitted form: for
170 // the heuristic prediction, for the crowd-sourced prediction, and for the
171 // overall prediction.
172 enum FieldTypeQualityMetric
{
173 TYPE_UNKNOWN
= 0, // Offered no prediction.
174 TYPE_MATCH
, // Predicted correctly.
175 TYPE_MISMATCH
, // Predicted incorrectly.
176 NUM_FIELD_TYPE_QUALITY_METRICS
,
179 // Each of these is logged at most once per query to the server, which in turn
180 // occurs at most once per page load.
181 enum ServerQueryMetric
{
182 QUERY_SENT
= 0, // Sent a query to the server.
183 QUERY_RESPONSE_RECEIVED
, // Received a response.
184 QUERY_RESPONSE_PARSED
, // Successfully parsed the server response.
186 // The response was parseable, but provided no improvements relative to our
188 QUERY_RESPONSE_MATCHED_LOCAL_HEURISTICS
,
190 // Our heuristics detected at least one auto-fillable field, and the server
191 // response overrode the type of at least one field.
192 QUERY_RESPONSE_OVERRODE_LOCAL_HEURISTICS
,
194 // Our heuristics did not detect any auto-fillable fields, but the server
195 // response did detect at least one.
196 QUERY_RESPONSE_WITH_NO_LOCAL_HEURISTICS
,
197 NUM_SERVER_QUERY_METRICS
,
200 // Logs usage of "Scan card" control item.
201 enum ScanCreditCardPromptMetric
{
202 // "Scan card" was presented to the user.
203 SCAN_CARD_ITEM_SHOWN
,
204 // "Scan card" was selected by the user.
205 SCAN_CARD_ITEM_SELECTED
,
206 // The user selected something in the dropdown besides "scan card".
207 SCAN_CARD_OTHER_ITEM_SELECTED
,
208 NUM_SCAN_CREDIT_CARD_PROMPT_METRICS
,
211 // Each of these metrics is logged only for potentially autofillable forms,
212 // i.e. forms with at least three fields, etc.
213 // These are used to derive certain "user happiness" metrics. For example, we
214 // can compute the ratio (USER_DID_EDIT_AUTOFILLED_FIELD / USER_DID_AUTOFILL)
215 // to see how often users have to correct autofilled data.
216 enum UserHappinessMetric
{
217 // Loaded a page containing forms.
219 // Submitted a fillable form -- i.e. one with at least three field values
220 // that match the user's stored Autofill data -- and all matching fields
222 SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL
,
223 // Submitted a fillable form and some (but not all) matching fields were
225 SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME
,
226 // Submitted a fillable form and no fields were autofilled.
227 SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE
,
228 // Submitted a non-fillable form.
229 SUBMITTED_NON_FILLABLE_FORM
,
231 // User manually filled one of the form fields.
233 // We showed a popup containing Autofill suggestions.
235 // Same as above, but only logged once per page load.
236 SUGGESTIONS_SHOWN_ONCE
,
237 // User autofilled at least part of the form.
239 // Same as above, but only logged once per page load.
240 USER_DID_AUTOFILL_ONCE
,
241 // User edited a previously autofilled field.
242 USER_DID_EDIT_AUTOFILLED_FIELD
,
243 // Same as above, but only logged once per page load.
244 USER_DID_EDIT_AUTOFILLED_FIELD_ONCE
,
245 NUM_USER_HAPPINESS_METRICS
,
248 // Form Events for autofill.
249 // These events are triggered separetly for address and credit card forms.
251 // User interacted with a field of this kind of form. Logged only once per
253 FORM_EVENT_INTERACTED_ONCE
= 0,
254 // A dropdown with suggestions was shown.
255 FORM_EVENT_SUGGESTIONS_SHOWN
,
256 // Same as above, but recoreded only once per page load.
257 FORM_EVENT_SUGGESTIONS_SHOWN_ONCE
,
258 // A local suggestion was used to fill the form.
259 FORM_EVENT_LOCAL_SUGGESTION_FILLED
,
260 // A server suggestion was used to fill the form.
261 // When dealing with credit cards, this means a full server card was used
263 FORM_EVENT_SERVER_SUGGESTION_FILLED
,
264 // A masked server card suggestion was used to fill the form.
265 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED
,
266 // A suggestion was used to fill the form. The origin type (local or server
267 // or masked server card) of the first selected within a page load will
268 // determine which of the following two will be fired.
269 FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE
,
270 FORM_EVENT_SERVER_SUGGESTION_FILLED_ONCE
,
271 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE
,
272 // A form was submitted. Depending on the user filling a local, server,
273 // masked server card or no suggestion one of the following will be
274 // triggered. Only one of the following four will be triggered per page
276 FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE
,
277 FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE
,
278 FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE
,
279 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE
,
280 // A masked server card suggestion was selected to fill the form.
281 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED
,
282 // Same as above but only triggered once per page load.
283 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED_ONCE
,
287 // For measuring the network request time of various Wallet API calls. See
288 // WalletClient::RequestType.
289 enum WalletApiCallMetric
{
290 UNKNOWN_API_CALL
, // Catch all. Should never be used.
291 ACCEPT_LEGAL_DOCUMENTS
,
292 AUTHENTICATE_INSTRUMENT
,
299 // For measuring the frequency of errors while communicating with the Wallet
301 enum WalletErrorMetric
{
302 // Baseline metric: Issued a request to the Wallet server.
303 WALLET_ERROR_BASELINE_ISSUED_REQUEST
= 0,
304 // A fatal error occured while communicating with the Wallet server. This
305 // value has been deprecated.
306 WALLET_FATAL_ERROR_DEPRECATED
,
307 // Received a malformed response from the Wallet server.
308 WALLET_MALFORMED_RESPONSE
,
309 // A network error occured while communicating with the Wallet server.
310 WALLET_NETWORK_ERROR
,
311 // The request was malformed.
313 // Risk deny, unsupported country, or account closed.
314 WALLET_BUYER_ACCOUNT_ERROR
,
315 // Unknown server side error.
316 WALLET_INTERNAL_ERROR
,
317 // API call had missing or invalid parameters.
318 WALLET_INVALID_PARAMS
,
319 // Online Wallet is down.
320 WALLET_SERVICE_UNAVAILABLE
,
321 // User needs make a cheaper transaction or not use Online Wallet.
322 WALLET_SPENDING_LIMIT_EXCEEDED
,
323 // The server API version of the request is no longer supported.
324 WALLET_UNSUPPORTED_API_VERSION
,
325 // Catch all error type.
326 WALLET_UNKNOWN_ERROR
,
327 // The merchant has been blacklisted for Online Wallet due to some manner
328 // of compliance violation.
329 WALLET_UNSUPPORTED_MERCHANT
,
330 // Buyer Legal Address has a country which is unsupported by Wallet.
331 WALLET_BUYER_LEGAL_ADDRESS_NOT_SUPPORTED
,
332 // Wallet's Know Your Customer(KYC) action is pending/failed for this user.
333 WALLET_UNVERIFIED_KNOW_YOUR_CUSTOMER_STATUS
,
334 // Chrome version is unsupported or provided API key not allowed.
335 WALLET_UNSUPPORTED_USER_AGENT_OR_API_KEY
,
336 NUM_WALLET_ERROR_METRICS
339 // For measuring the frequency of "required actions" returned by the Wallet
340 // server. This is similar to the autofill::wallet::RequiredAction enum;
341 // but unlike that enum, the values in this one must remain constant over
342 // time, so that the metrics can be consistently interpreted on the
344 enum WalletRequiredActionMetric
{
345 // Baseline metric: Issued a request to the Wallet server.
346 WALLET_REQUIRED_ACTION_BASELINE_ISSUED_REQUEST
= 0,
347 // Values from the autofill::wallet::RequiredAction enum:
348 UNKNOWN_REQUIRED_ACTION
, // Catch all type.
353 UPDATE_EXPIRATION_DATE
,
355 CHOOSE_ANOTHER_INSTRUMENT_OR_ADDRESS
,
358 REQUIRE_PHONE_NUMBER
,
359 NUM_WALLET_REQUIRED_ACTIONS
362 static void LogCreditCardInfoBarMetric(InfoBarMetric metric
);
363 static void LogScanCreditCardPromptMetric(ScanCreditCardPromptMetric metric
);
365 // Should be called when credit card scan is finished. |duration| should be
366 // the time elapsed between launching the credit card scanner and getting back
367 // the result. |completed| should be true if a credit card was scanned, false
368 // if the scan was cancelled.
369 static void LogScanCreditCardCompleted(const base::TimeDelta
& duration
,
372 static void LogDeveloperEngagementMetric(DeveloperEngagementMetric metric
);
374 static void LogHeuristicTypePrediction(FieldTypeQualityMetric metric
,
375 ServerFieldType field_type
);
376 static void LogOverallTypePrediction(FieldTypeQualityMetric metric
,
377 ServerFieldType field_type
);
378 static void LogServerTypePrediction(FieldTypeQualityMetric metric
,
379 ServerFieldType field_type
);
381 static void LogServerQueryMetric(ServerQueryMetric metric
);
383 static void LogUserHappinessMetric(UserHappinessMetric metric
);
385 // Logs |state| to the dismissal states histogram.
386 static void LogDialogDismissalState(DialogDismissalState state
);
388 // This should be called as soon as the user's signed-in status and Wallet
389 // item count is known. Records that a user starting out in |user_state| is
390 // interacting with a dialog.
391 static void LogDialogInitialUserState(DialogInitialUserStateMetric user_type
);
393 // Logs the time elapsed between the dialog being shown and when it is ready
394 // for user interaction.
395 static void LogDialogLatencyToShow(const base::TimeDelta
& duration
);
397 // Logs |event| to the popup events histogram.
398 static void LogDialogPopupEvent(DialogPopupEvent event
);
400 // Logs |metric| to the security metrics histogram.
401 static void LogDialogSecurityMetric(DialogSecurityMetric metric
);
403 // This should be called when the Autofill dialog is closed. |duration|
404 // should be the time elapsed between the dialog being shown and it being
405 // closed. |dismissal_action| should indicate whether the user dismissed
406 // the dialog by submitting the form data or by canceling.
407 static void LogDialogUiDuration(const base::TimeDelta
& duration
,
408 DialogDismissalAction dismissal_action
);
410 // Logs |event| to the UI events histogram.
411 static void LogDialogUiEvent(DialogUiEvent event
);
413 // Logs |metric| to the Wallet errors histogram.
414 static void LogWalletErrorMetric(WalletErrorMetric metric
);
416 // Logs the network request time of Wallet API calls.
417 static void LogWalletApiCallDuration(WalletApiCallMetric metric
,
418 const base::TimeDelta
& duration
);
420 // Logs that the Wallet API call corresponding to |metric| was malformed.
421 static void LogWalletMalformedResponseMetric(WalletApiCallMetric metric
);
423 // Logs |required_action| to the required actions histogram.
424 static void LogWalletRequiredActionMetric(
425 WalletRequiredActionMetric required_action
);
427 // Logs HTTP response codes recieved by wallet client.
428 static void LogWalletResponseCode(int response_code
);
430 // This should be called when a form that has been Autofilled is submitted.
431 // |duration| should be the time elapsed between form load and submission.
432 static void LogFormFillDurationFromLoadWithAutofill(
433 const base::TimeDelta
& duration
);
435 // This should be called when a fillable form that has not been Autofilled is
436 // submitted. |duration| should be the time elapsed between form load and
438 static void LogFormFillDurationFromLoadWithoutAutofill(
439 const base::TimeDelta
& duration
);
441 // This should be called when a form that has been Autofilled is submitted.
442 // |duration| should be the time elapsed between the initial form interaction
444 static void LogFormFillDurationFromInteractionWithAutofill(
445 const base::TimeDelta
& duration
);
447 // This should be called when a fillable form that has not been Autofilled is
448 // submitted. |duration| should be the time elapsed between the initial form
449 // interaction and submission.
450 static void LogFormFillDurationFromInteractionWithoutAutofill(
451 const base::TimeDelta
& duration
);
453 // This should be called each time a page containing forms is loaded.
454 static void LogIsAutofillEnabledAtPageLoad(bool enabled
);
456 // This should be called each time a new profile is launched.
457 static void LogIsAutofillEnabledAtStartup(bool enabled
);
459 // This should be called each time a new profile is launched.
460 static void LogStoredProfileCount(size_t num_profiles
);
462 // Log the number of profiles available when an autofillable form is
464 static void LogNumberOfProfilesAtAutofillableFormSubmission(
465 size_t num_profiles
);
467 // Log the number of Autofill suggestions presented to the user when filling a
469 static void LogAddressSuggestionsCount(size_t num_suggestions
);
471 // Utility to autofill form events in the relevant histograms depending on
472 // the presence of server and/or local data.
473 class FormEventLogger
{
475 FormEventLogger(bool is_for_credit_card
);
477 inline void set_is_server_data_available(bool is_server_data_available
) {
478 is_server_data_available_
= is_server_data_available
;
481 inline void set_is_local_data_available(bool is_local_data_available
) {
482 is_local_data_available_
= is_local_data_available
;
485 void OnDidInteractWithAutofillableForm();
487 void OnDidShowSuggestions();
489 void OnDidSelectMaskedServerCardSuggestion();
491 // In case of masked cards, caller must make sure this gets called before
492 // the card is upgraded to a full card.
493 void OnDidFillSuggestion(const CreditCard
& credit_card
);
495 void OnDidFillSuggestion(const AutofillProfile
& profile
);
497 void OnDidSubmitForm();
500 void Log(FormEvent event
) const;
502 bool is_for_credit_card_
;
503 bool is_server_data_available_
;
504 bool is_local_data_available_
;
505 bool has_logged_interacted_
;
506 bool has_logged_suggestions_shown_
;
507 bool has_logged_masked_server_card_suggestion_selected_
;
508 bool has_logged_suggestion_filled_
;
509 bool has_logged_submitted_
;
510 bool logged_suggestion_filled_was_server_data_
;
511 bool logged_suggestion_filled_was_masked_server_card_
;
515 DISALLOW_IMPLICIT_CONSTRUCTORS(AutofillMetrics
);
518 } // namespace autofill
520 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_