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