pwa_install_path_tracker.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright 2021 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. #ifndef COMPONENTS_WEBAPPS_BROWSER_PWA_INSTALL_PATH_TRACKER_H_
  5. #define COMPONENTS_WEBAPPS_BROWSER_PWA_INSTALL_PATH_TRACKER_H_
  6. #include "components/webapps/browser/installable/installable_metrics.h"
  7. namespace webapps {
  8. class PwaInstallPathTracker {
  9. public:
  10. PwaInstallPathTracker();
  11. PwaInstallPathTracker& operator=(const PwaInstallPathTracker&) = delete;
  12. PwaInstallPathTracker(const PwaInstallPathTracker&) = delete;
  13. virtual ~PwaInstallPathTracker();
  14. // Keeps track of what install path was used to install a PWA. Note that these
  15. // values are persisted to logs. Entries should not be renumbered and numeric
  16. // values should never be reused.
  17. enum class InstallPathMetric {
  18. // Unabled to determine install path.
  19. kUnknownMetric = 0,
  20. // The Ambient Badge was shown and used to trigger install via the install
  21. // dialog.
  22. kAmbientInfobar = 1,
  23. // 'Install app' was selected in the App menu and used to trigger install
  24. // via the Install dialog.
  25. kAppMenuInstall = 2,
  26. // The Install dialog was shown at the request of a website and was used to
  27. // trigger install.
  28. kApiInitiatedInstall = 3,
  29. // The BottomSheet was shown ambiently (peeking) and used to trigger
  30. // install. It may or may not have been expanded before installation
  31. // started.
  32. kAmbientBottomSheet = 4,
  33. // The BottomSheet was shown expanded as a result of an App menu click and
  34. // was used to trigger install.
  35. kAppMenuBottomSheet = 5,
  36. // The BottomSheet was shown expanded at the request of a website and was
  37. // used to trigger install.
  38. kApiInitiatedBottomSheet = 6,
  39. // Same as kAmbientInfobar, except the InProduct Help was shown also.
  40. kAmbientInfobarWithIph = 7,
  41. // Same as kAppMenuInstall, except the InProduct Help was shown also.
  42. kAppMenuInstallWithIph = 8,
  43. // Same as kApiInstallInfobar, except the InProduct Help was shown also.
  44. // Note that this is is added for completeness and is not expected to
  45. // happen, because the IPH does not show when the ambient badge is deferred
  46. // by the website.
  47. kApiInitiatedInstallWithIph = 9,
  48. // Same as kAmbientBottomSheet, except the InProduct Help was shown also.
  49. kAmbientBottomSheetWithIph = 10,
  50. // Same as kAppMenuBottomSheet, except the InProduct Help was shown also.
  51. kAppMenuBottomSheetWithIph = 11,
  52. // Same as kApiInitiatedBottomSheet, except the InProduct Help was shown
  53. // also. Note that this is is added for completeness and is not expected to
  54. // happen, because the IPH does not show when the bottom sheet is deferred
  55. // by the website.
  56. kApiInitiatedBottomSheetWithIph = 12,
  57. // Keeps track of the last entry.
  58. kMaxValue = kApiInitiatedBottomSheetWithIph,
  59. };
  60. // Tracks the route taken to an install of a PWA (whether the bottom sheet
  61. // was shown or the infobar/install) and what triggered it (install source).
  62. void TrackInstallPath(bool bottom_sheet, WebappInstallSource install_source);
  63. // Tracks that the IPH has been shown.
  64. void TrackIphWasShown();
  65. // Resets the tracker (forgets previously recorder events).
  66. void Reset();
  67. // Gets the metric for the current install path, if available, or
  68. // kUnknownMetric otherwise.
  69. InstallPathMetric GetInstallPathMetric();
  70. private:
  71. // The source that initiated the install, for example: App menu, API or
  72. // ambient badge.
  73. WebappInstallSource install_source_ = WebappInstallSource::COUNT;
  74. // Whether the bottom sheet install UI was shown or the infobar/install modal.
  75. bool bottom_sheet_ = false;
  76. // Whether the IPH has been shown to the user.
  77. bool iph_was_shown_ = false;
  78. };
  79. } // namespace webapps
  80. #endif // COMPONENTS_WEBAPPS_BROWSER_PWA_INSTALL_PATH_TRACKER_H_