tree: 54c3bbbdd0219747734660d91dc78339e408f46f [path history] [tgz]
  1. form_events/
  2. payments/
  3. address_data_cleaner_metrics.cc
  4. address_data_cleaner_metrics.h
  5. address_save_metrics.cc
  6. address_save_metrics.h
  7. autofill_in_devtools_metrics.cc
  8. autofill_in_devtools_metrics.h
  9. autofill_metrics.cc
  10. autofill_metrics.h
  11. autofill_metrics_test_base.cc
  12. autofill_metrics_test_base.h
  13. autofill_metrics_unittest.cc
  14. autofill_metrics_utils.cc
  15. autofill_metrics_utils.h
  16. autofill_metrics_utils_unittest.cc
  17. autofill_settings_metrics.cc
  18. autofill_settings_metrics.h
  19. autofill_settings_metrics_unittest.cc
  20. field_filling_stats_and_score_metrics.cc
  21. field_filling_stats_and_score_metrics.h
  22. field_filling_stats_and_score_metrics_unittest.cc
  23. form_interactions_ukm_logger.cc
  24. form_interactions_ukm_logger.h
  25. form_interactions_ukm_logger_unittest.cc
  26. log_event.cc
  27. log_event.h
  28. loyalty_cards_metrics.cc
  29. loyalty_cards_metrics.h
  30. per_fill_metrics.cc
  31. per_fill_metrics.h
  32. per_fill_metrics_unittest.cc
  33. prediction_quality_metrics.cc
  34. prediction_quality_metrics.h
  35. prediction_quality_metrics_unittest.cc
  36. profile_import_metrics.cc
  37. profile_import_metrics.h
  38. profile_import_metrics_unittest.cc
  39. profile_token_quality_metrics.cc
  40. profile_token_quality_metrics.h
  41. profile_token_quality_metrics_unittest.cc
  42. quality_metrics.cc
  43. quality_metrics.h
  44. quality_metrics_filling.cc
  45. quality_metrics_filling.h
  46. quality_metrics_filling_unittest.cc
  47. quality_metrics_unittest.cc
  48. README.md
  49. stored_profile_metrics.cc
  50. stored_profile_metrics.h
  51. stored_profile_metrics_unittest.cc
  52. suggestions_list_metrics.cc
  53. suggestions_list_metrics.h
  54. suggestions_list_metrics_unittest.cc
  55. ukm_metrics_test_utils.cc
  56. ukm_metrics_test_utils.h
components/autofill/core/browser/metrics/README.md

Adding metrics for a new feature?

Please do not add your metrics in autofill_metrics.*! Instead, help support code clarity and organization by adding a pair of files per feature.

The old way

Originally, when making metrics for a new feature, everything was thrown into the autofill_metrics.* files:

autofill_metrics.h:

class AutofillMetrics {

  enum class CoolFeatureInteractionMetric {
    // User accepted the cool feature.
    kAccepted = 0,
    // User explicitly denied the feature.
    kCancelled = 1,
    // User left the page without interacting with the feature.
    kIgnored = 2,
    kMaxValue = kIgnored,
  };

  // ...Roughly 1500 lines of other enums and functions...

  static void LogCoolFeatureInteraction(CoolFeatureInteractionMetric metric);
}

autofill_metrics.cc:

  // ...In the middle of 3000 lines of similar code...

  // static
  void AutofillMetrics::LogCoolFeatureInteraction(
      CoolFeatureInteractionMetric metric) {
    base::UmaHistogramEnumeration("Autofill.CoolFeatureInteraction", metric);
  }

The calling code of this function would be AutofillMetrics::LogCoolFeatureInteraction(~).

The biggest downside to this approach was not just how large the two files became, but also how far apart enums/metrics related to the same feature were located, as well as how hard it was to find all metrics for a given feature.

The new way

Don't use a class, but do use the autofill::autofill_metrics namespace. Then, combine all metrics that are part of a single feature together, so they‘re not intertwined with the rest of Autofill’s metrics.

cool_feature_metrics.h:

(Put this header file under components/autofill/core/browser/metrics/[optional_sub_directory])

// [Copyright notice and include guards]

namespace autofill::autofill_metrics {

enum class CoolFeatureInteractionMetric {
  // User accepted the cool feature.
  kAccepted = 0,
  // User explicitly denied the feature.
  kCancelled = 1,
  // User left the page without interacting with the feature.
  kIgnored = 2,
  kMaxValue = kIgnored,
};

void LogCoolFeatureInteraction(CoolFeatureInteractionMetric metric);

}  // namespace autofill::autofill_metrics

cool_feature_metrics.cc:

// [Copyright notice]

#include "components/autofill/core/browser/metrics/[optional_sub_directory]/cool_feature_metrics.h"

namespace autofill::autofill_metrics {

void LogCoolFeatureInteraction(CoolFeatureInteractionMetric metric) {
  base::UmaHistogramEnumeration("Autofill.CoolFeatureInteraction", metric);
}

// If there are other metrics related to this feature, they'd go here, and it
// would be very obvious they're related!

}  // namespace autofill::autofill_metrics

The calling code of this function would be autofill::autofill_metrics::LogCoolFeatureInteraction(~).