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

Side by Side Diff: components/ntp_snippets/content_suggestions_metrics.cc

Issue 2509663002: Add a histogram for recording content suggestions local usage time stats. (Closed)
Patch Set: Fix a comment Created 4 years, 1 month 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/ntp_snippets/content_suggestions_metrics.h" 5 #include "components/ntp_snippets/content_suggestions_metrics.h"
6 6
7 #include <string> 7 #include <string>
8 #include <type_traits> 8 #include <type_traits>
9 9
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 22 matching lines...) Expand all
33 "NewTabPage.ContentSuggestions.OpenDisposition"; 33 "NewTabPage.ContentSuggestions.OpenDisposition";
34 const char kHistogramMenuOpened[] = "NewTabPage.ContentSuggestions.MenuOpened"; 34 const char kHistogramMenuOpened[] = "NewTabPage.ContentSuggestions.MenuOpened";
35 const char kHistogramMenuOpenedAge[] = 35 const char kHistogramMenuOpenedAge[] =
36 "NewTabPage.ContentSuggestions.MenuOpenedAge"; 36 "NewTabPage.ContentSuggestions.MenuOpenedAge";
37 const char kHistogramMenuOpenedScore[] = 37 const char kHistogramMenuOpenedScore[] =
38 "NewTabPage.ContentSuggestions.MenuOpenedScore"; 38 "NewTabPage.ContentSuggestions.MenuOpenedScore";
39 const char kHistogramDismissedUnvisited[] = 39 const char kHistogramDismissedUnvisited[] =
40 "NewTabPage.ContentSuggestions.DismissedUnvisited"; 40 "NewTabPage.ContentSuggestions.DismissedUnvisited";
41 const char kHistogramDismissedVisited[] = 41 const char kHistogramDismissedVisited[] =
42 "NewTabPage.ContentSuggestions.DismissedVisited"; 42 "NewTabPage.ContentSuggestions.DismissedVisited";
43 const char kHistogramUsageTimeLocal[] =
44 "NewTabPage.ContentSuggestions.UsageTimeLocal";
43 const char kHistogramVisitDuration[] = 45 const char kHistogramVisitDuration[] =
44 "NewTabPage.ContentSuggestions.VisitDuration"; 46 "NewTabPage.ContentSuggestions.VisitDuration";
45 const char kHistogramMoreButtonShown[] = 47 const char kHistogramMoreButtonShown[] =
46 "NewTabPage.ContentSuggestions.MoreButtonShown"; 48 "NewTabPage.ContentSuggestions.MoreButtonShown";
47 const char kHistogramMoreButtonClicked[] = 49 const char kHistogramMoreButtonClicked[] =
48 "NewTabPage.ContentSuggestions.MoreButtonClicked"; 50 "NewTabPage.ContentSuggestions.MoreButtonClicked";
49 51
50 const char kPerCategoryHistogramFormat[] = "%s.%s"; 52 const char kPerCategoryHistogramFormat[] = "%s.%s";
51 53
52 // Each suffix here should correspond to an entry under histogram suffix 54 // Each suffix here should correspond to an entry under histogram suffix
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 154 }
153 155
154 void LogCategoryHistogramScore(const char* base_name, 156 void LogCategoryHistogramScore(const char* base_name,
155 Category category, 157 Category category,
156 float score) { 158 float score) {
157 std::string name = GetCategoryHistogramName(base_name, category); 159 std::string name = GetCategoryHistogramName(base_name, category);
158 // Since the histogram name is dynamic, we can't use the regular macro. 160 // Since the histogram name is dynamic, we can't use the regular macro.
159 UmaHistogramScore(name, score); 161 UmaHistogramScore(name, score);
160 } 162 }
161 163
164 // Records ContentSuggestions usage. Therefore the day is sliced into 20min
165 // buckets. Depending on the current local time the count of the corresponding
166 // bucket is increased.
Marc Treib 2016/11/16 14:14:29 Mention that "usage" means "impression" rather tha
markusheintz_ 2016/11/16 14:52:13 It will be more that just the impression, i'll als
Marc Treib 2016/11/16 15:10:08 Then all the more important to define what we cons
167 void RecordContentSuggestionsUsage() {
168 const int kBucketSize = 20; // min
Marc Treib 2016/11/16 14:14:29 nit: kBucketSizeMins and remove the comment?
markusheintz_ 2016/11/16 14:52:13 Done.
169 const int kNumBuckets = 24 * 60 / kBucketSize;
170
171 base::Time now(base::Time::Now());
172 base::Time::Exploded now_exploded;
173 now.LocalExplode(&now_exploded);
Marc Treib 2016/11/16 14:14:29 nit: You could just write base::Time::Now().LocalE
markusheintz_ 2016/11/16 14:52:13 Done.
174 size_t bucket = (now_exploded.hour * 60 + now_exploded.minute) / kBucketSize;
Marc Treib 2016/11/16 14:14:29 Why size_t rather than int?
markusheintz_ 2016/11/16 14:52:13 bucket size can't be negative.
Marc Treib 2016/11/16 15:10:08 Nothing here can be negative, yet everything else
175
176 UMA_HISTOGRAM_ENUMERATION(
177 kHistogramUsageTimeLocal,
178 bucket,
179 kNumBuckets);
Marc Treib 2016/11/16 14:14:29 nit: run "git cl format"
markusheintz_ 2016/11/16 14:52:13 Done.
180 }
181
162 } // namespace 182 } // namespace
163 183
164 void OnPageShown( 184 void OnPageShown(
165 const std::vector<std::pair<Category, int>>& suggestions_per_category) { 185 const std::vector<std::pair<Category, int>>& suggestions_per_category) {
166 int suggestions_total = 0; 186 int suggestions_total = 0;
167 for (const std::pair<Category, int>& item : suggestions_per_category) { 187 for (const std::pair<Category, int>& item : suggestions_per_category) {
168 LogCategoryHistogramEnumeration(kHistogramCountOnNtpOpened, item.first, 188 LogCategoryHistogramEnumeration(kHistogramCountOnNtpOpened, item.first,
169 item.second, kMaxSuggestionsPerCategory); 189 item.second, kMaxSuggestionsPerCategory);
170 suggestions_total += item.second; 190 suggestions_total += item.second;
171 } 191 }
172 192
173 UMA_HISTOGRAM_ENUMERATION(kHistogramCountOnNtpOpened, suggestions_total, 193 UMA_HISTOGRAM_ENUMERATION(kHistogramCountOnNtpOpened, suggestions_total,
174 kMaxSuggestionsTotal); 194 kMaxSuggestionsTotal);
175 } 195 }
176 196
177 void OnSuggestionShown(int global_position, 197 void OnSuggestionShown(int global_position,
178 Category category, 198 Category category,
179 int category_position, 199 int category_position,
180 base::Time publish_date, 200 base::Time publish_date,
181 float score) { 201 float score) {
182 UMA_HISTOGRAM_ENUMERATION(kHistogramShown, global_position, 202 UMA_HISTOGRAM_ENUMERATION(kHistogramShown, global_position,
183 kMaxSuggestionsTotal); 203 kMaxSuggestionsTotal);
184 LogCategoryHistogramEnumeration(kHistogramShown, category, category_position, 204 LogCategoryHistogramEnumeration(kHistogramShown, category, category_position,
185 kMaxSuggestionsPerCategory); 205 kMaxSuggestionsPerCategory);
186 206
187 base::TimeDelta age = base::Time::Now() - publish_date; 207 base::TimeDelta age = base::Time::Now() - publish_date;
188 LogCategoryHistogramAge(kHistogramShownAge, category, age); 208 LogCategoryHistogramAge(kHistogramShownAge, category, age);
189 209
190 LogCategoryHistogramScore(kHistogramShownScore, category, score); 210 LogCategoryHistogramScore(kHistogramShownScore, category, score);
211
212 // When the first suggestion of all snippets is shown, then we count this as a
Marc Treib 2016/11/16 14:14:29 "When the first of all suggestions is shown, ..."?
markusheintz_ 2016/11/16 14:52:13 Done.
213 // single usage of content suggestions.
214 // TODO(markusheintz): Use position 0 once http://crbug.com/664539 is fixed.
Marc Treib 2016/11/16 14:14:29 It'll be fixed very soon, see https://codereview.c
markusheintz_ 2016/11/16 14:52:13 Done.
215 if (global_position == 1) {
216 RecordContentSuggestionsUsage();
217 }
191 } 218 }
192 219
193 void OnSuggestionOpened(int global_position, 220 void OnSuggestionOpened(int global_position,
194 Category category, 221 Category category,
195 int category_position, 222 int category_position,
196 base::Time publish_date, 223 base::Time publish_date,
197 float score, 224 float score,
198 WindowOpenDisposition disposition) { 225 WindowOpenDisposition disposition) {
199 UMA_HISTOGRAM_ENUMERATION(kHistogramOpened, global_position, 226 UMA_HISTOGRAM_ENUMERATION(kHistogramOpened, global_position,
200 kMaxSuggestionsTotal); 227 kMaxSuggestionsTotal);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 290
264 void OnMoreButtonClicked(Category category, int position) { 291 void OnMoreButtonClicked(Category category, int position) {
265 // The "more" card can appear in addition to the actual suggestions, so add 292 // The "more" card can appear in addition to the actual suggestions, so add
266 // one extra bucket to this histogram. 293 // one extra bucket to this histogram.
267 LogCategoryHistogramEnumeration(kHistogramMoreButtonClicked, category, 294 LogCategoryHistogramEnumeration(kHistogramMoreButtonClicked, category,
268 position, kMaxSuggestionsPerCategory + 1); 295 position, kMaxSuggestionsPerCategory + 1);
269 } 296 }
270 297
271 } // namespace metrics 298 } // namespace metrics
272 } // namespace ntp_snippets 299 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | tools/metrics/histograms/histograms.xml » ('J')

Powered by Google App Engine
This is Rietveld 408576698