Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: components/feature_engagement_tracker/internal/stats.cc

Issue 2911123003: Metrics for feature engagement tracker. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 #include "components/feature_engagement_tracker/internal/stats.h"
6
7 #include <string>
8
9 #include "base/metrics/histogram_functions.h"
10 #include "base/metrics/histogram_macros.h"
11 #include "base/metrics/user_metrics.h"
12 #include "components/feature_engagement_tracker/public/feature_list.h"
13
14 namespace feature_engagement_tracker {
15 namespace stats {
16 namespace {
17
18 // Histogram suffixes for database metrics, must match the ones in
19 // histograms.xml.
20 const char kEventStoreSuffix[] = "EventStore";
21 const char kAvailabilityStoreSuffix[] = "AvailabilityStore";
22
23 // Helper function to log a TriggerHelpUIResult.
24 void LogTriggerHelpUIResult(const std::string& name,
25 TriggerHelpUIResult result) {
26 // Must not use histograms macros here because we pass in the histogram name.
27 base::UmaHistogramEnumeration(name, result, TriggerHelpUIResult::COUNT);
28 }
29
30 } // namespace
31
32 std::string ToDbHistogramSuffix(StoreType type) {
33 switch (type) {
34 case StoreType::EVENTS_STORE:
35 return std::string(kEventStoreSuffix);
36 case StoreType::AVAILABILITY_STORE:
37 return std::string(kAvailabilityStoreSuffix);
38 default:
39 NOTREACHED();
40 return std::string();
41 }
42 }
43
44 void RecordNotifyEvent(const std::string& event_name,
45 const Configuration* config,
46 bool is_model_ready) {
47 DCHECK(!event_name.empty());
48 DCHECK(config);
49
50 // Find which feature this event belongs to.
51 const Configuration::ConfigMap& features = config->GetRegisteredFeatures();
52 std::string feature_name;
53 for (const auto& element : features) {
54 const base::Feature* feature = element.first;
55 const FeatureConfig& feature_config = element.second;
56
57 // Track used event separately.
58 if (feature_config.used.name == event_name) {
59 feature_name = feature->name;
60 DCHECK(!feature_name.empty());
61 std::string used_event_action = "InProductHelp.NotifyUsedEvent.";
62 used_event_action.append(feature_name);
63 base::RecordComputedAction(used_event_action);
64 break;
65 }
66
67 // Find if the |event_name| matches any configuration.
68 for (const auto& event : feature_config.event_configs) {
69 if (event.name == event_name) {
70 feature_name = feature->name;
71 break;
72 }
73 }
74 if (feature_config.trigger.name == event_name) {
75 feature_name = feature->name;
76 break;
77 }
78 }
79
80 // Do nothing if no events in the configuration matches the |event_name|.
81 if (feature_name.empty())
82 return;
83
84 std::string event_action = "InProductHelp.NotifyEvent.";
85 event_action.append(feature_name);
86 base::RecordComputedAction(event_action);
87
88 std::string event_histogram = "InProductHelp.NotifyEventReadyState.";
89 event_histogram.append(feature_name);
90 base::UmaHistogramBoolean(event_histogram, is_model_ready);
91 }
92
93 void RecordShouldTriggerHelpUI(const base::Feature& feature,
94 const ConditionValidator::Result& result) {
95 // Records the user action.
96 std::string name = "InProductHelp.ShouldTriggerHelpUI.";
97 name.append(feature.name);
98 base::RecordComputedAction(name);
99
100 // Total count histogram, used to compute the percentage of each failure type.
101 if (result.NoErrors()) {
102 LogTriggerHelpUIResult(name, TriggerHelpUIResult::SUCCESS);
103 } else {
104 LogTriggerHelpUIResult(name, TriggerHelpUIResult::FAILURE);
105 }
106
107 // Histogram about the failure reasons.
108 if (!result.event_model_ready_ok)
109 LogTriggerHelpUIResult(name, TriggerHelpUIResult::FAILURE_MODEL_NOT_READY);
110 if (!result.currently_showing_ok) {
111 LogTriggerHelpUIResult(name,
112 TriggerHelpUIResult::FAILURE_CURRENTLY_SHOWING);
113 }
114 if (!result.feature_enabled_ok) {
115 LogTriggerHelpUIResult(name, TriggerHelpUIResult::FAILURE_FEATURE_DISABLED);
116 }
117 if (!result.config_ok) {
118 LogTriggerHelpUIResult(name, TriggerHelpUIResult::FAILURE_CONFIG_INVALID);
119 }
120 if (!result.used_ok) {
121 LogTriggerHelpUIResult(
122 name, TriggerHelpUIResult::FAILURE_USED_PRECONDITION_UNMET);
123 }
124 if (!result.trigger_ok) {
125 LogTriggerHelpUIResult(
126 name, TriggerHelpUIResult::FAILURE_TRIGGER_PRECONDITION_UNMET);
127 }
128 if (!result.preconditions_ok) {
129 LogTriggerHelpUIResult(
130 name, TriggerHelpUIResult::FAILURE_OTHER_PRECONDITION_UNMET);
131 }
132 if (!result.session_rate_ok) {
133 LogTriggerHelpUIResult(name, TriggerHelpUIResult::FAILURE_SESSION_RATE);
134 }
135 if (!result.availability_model_ready_ok) {
136 LogTriggerHelpUIResult(
137 name, TriggerHelpUIResult::FAILURE_AVAILABILITY_MODEL_NOT_READY);
138 }
139 if (!result.availability_ok) {
140 LogTriggerHelpUIResult(
141 name, TriggerHelpUIResult::FAILURE_AVAILABILITY_PRECONDITION_UNMET);
142 }
143 }
144
145 void RecordUserDismiss() {
146 base::RecordAction(base::UserMetricsAction("InProductHelp.Dismissed"));
147 }
148
149 void RecordDbUpdate(bool success, StoreType type) {
150 std::string histogram_name =
151 "InProductHelp.Db.Update." + ToDbHistogramSuffix(type);
152 base::UmaHistogramBoolean(histogram_name, success);
153 }
154
155 void RecordDbInitEvent(bool success, StoreType type) {
156 std::string histogram_name =
157 "InProductHelp.Db.Init." + ToDbHistogramSuffix(type);
158 base::UmaHistogramBoolean(histogram_name, success);
159 }
160
161 void RecordEventDbLoadEvent(bool success, const std::vector<Event>& events) {
162 std::string histogram_name =
163 "InProductHelp.Db.Load." + ToDbHistogramSuffix(StoreType::EVENTS_STORE);
164 base::UmaHistogramBoolean(histogram_name, success);
165 UMA_HISTOGRAM_BOOLEAN("InProductHelp.Db.Load", success);
166
167 if (!success)
168 return;
169
170 // Tracks total number of events records when the database is successfully
171 // loaded.
172 int event_count = 0;
173 for (const auto& event : events)
174 event_count += event.events_size();
175 UMA_HISTOGRAM_COUNTS_1000("InProductHelp.Db.TotalEvents", event_count);
176 }
177
178 void RecordAvailabilityDbLoadEvent(bool success) {
179 std::string histogram_name =
180 "InProductHelp.Db.Load." +
181 ToDbHistogramSuffix(StoreType::AVAILABILITY_STORE);
182 base::UmaHistogramBoolean(histogram_name, success);
183 UMA_HISTOGRAM_BOOLEAN("InProductHelp.Db.Load", success);
184 }
185
186 void RecordConfigParsingEvent(ConfigParsingEvent event) {
187 UMA_HISTOGRAM_ENUMERATION("InProductHelp.Config.ParsingEvent", event,
188 ConfigParsingEvent::COUNT);
189 }
190
191 } // namespace stats
192 } // namespace feature_engagement_tracker
OLDNEW
« no previous file with comments | « components/feature_engagement_tracker/internal/stats.h ('k') | tools/metrics/actions/actions.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698