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

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

Issue 2609413005: [NTP::SectionOrder] Add category position metric for opened suggestions. (Closed)
Patch Set: added TODO. Created 3 years, 11 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
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"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/metrics/user_metrics.h" 12 #include "base/metrics/user_metrics.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/template_util.h" 14 #include "base/template_util.h"
15 15
16 namespace ntp_snippets { 16 namespace ntp_snippets {
17 namespace metrics { 17 namespace metrics {
18 18
19 namespace { 19 namespace {
20 20
21 const int kMaxSuggestionsPerCategory = 10; 21 const int kMaxSuggestionsPerCategory = 10;
finkm 2017/01/05 16:31:29 Hmmm ... since we have the more button, a section
vitaliii 2017/01/05 17:02:46 I created a bug and added a TODO (as per our offli
22 const int kMaxSuggestionsTotal = 50; 22 const int kMaxSuggestionsTotal = 50;
finkm 2017/01/05 16:31:29 same as above
vitaliii 2017/01/05 17:02:46 same as above.
23 const int kMaxCategories = 10;
23 24
24 const char kHistogramCountOnNtpOpened[] = 25 const char kHistogramCountOnNtpOpened[] =
25 "NewTabPage.ContentSuggestions.CountOnNtpOpened"; 26 "NewTabPage.ContentSuggestions.CountOnNtpOpened";
26 const char kHistogramShown[] = "NewTabPage.ContentSuggestions.Shown"; 27 const char kHistogramShown[] = "NewTabPage.ContentSuggestions.Shown";
27 const char kHistogramShownAge[] = "NewTabPage.ContentSuggestions.ShownAge"; 28 const char kHistogramShownAge[] = "NewTabPage.ContentSuggestions.ShownAge";
28 const char kHistogramShownScore[] = "NewTabPage.ContentSuggestions.ShownScore"; 29 const char kHistogramShownScore[] = "NewTabPage.ContentSuggestions.ShownScore";
29 const char kHistogramOpened[] = "NewTabPage.ContentSuggestions.Opened"; 30 const char kHistogramOpened[] = "NewTabPage.ContentSuggestions.Opened";
30 const char kHistogramOpenedAge[] = "NewTabPage.ContentSuggestions.OpenedAge"; 31 const char kHistogramOpenedAge[] = "NewTabPage.ContentSuggestions.OpenedAge";
32 const char kHistogramOpenedCategoryPosition[] =
33 "NewTabPage.ContentSuggestions.OpenedCategoryPosition";
31 const char kHistogramOpenedScore[] = 34 const char kHistogramOpenedScore[] =
32 "NewTabPage.ContentSuggestions.OpenedScore"; 35 "NewTabPage.ContentSuggestions.OpenedScore";
33 const char kHistogramOpenDisposition[] = 36 const char kHistogramOpenDisposition[] =
34 "NewTabPage.ContentSuggestions.OpenDisposition"; 37 "NewTabPage.ContentSuggestions.OpenDisposition";
35 const char kHistogramMenuOpened[] = "NewTabPage.ContentSuggestions.MenuOpened"; 38 const char kHistogramMenuOpened[] = "NewTabPage.ContentSuggestions.MenuOpened";
36 const char kHistogramMenuOpenedAge[] = 39 const char kHistogramMenuOpenedAge[] =
37 "NewTabPage.ContentSuggestions.MenuOpenedAge"; 40 "NewTabPage.ContentSuggestions.MenuOpenedAge";
38 const char kHistogramMenuOpenedScore[] = 41 const char kHistogramMenuOpenedScore[] =
39 "NewTabPage.ContentSuggestions.MenuOpenedScore"; 42 "NewTabPage.ContentSuggestions.MenuOpenedScore";
40 const char kHistogramDismissedUnvisited[] = 43 const char kHistogramDismissedUnvisited[] =
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 kWeekdayNames[now_exploded.day_of_week])); 227 kWeekdayNames[now_exploded.day_of_week]));
225 UmaHistogramEnumeration(histogram_name, bucket, kNumBuckets); 228 UmaHistogramEnumeration(histogram_name, bucket, kNumBuckets);
226 229
227 UMA_HISTOGRAM_ENUMERATION(kHistogramArticlesUsageTimeLocal, bucket, 230 UMA_HISTOGRAM_ENUMERATION(kHistogramArticlesUsageTimeLocal, bucket,
228 kNumBuckets); 231 kNumBuckets);
229 232
230 base::RecordAction( 233 base::RecordAction(
231 base::UserMetricsAction("NewTabPage_ContentSuggestions_ArticlesUsage")); 234 base::UserMetricsAction("NewTabPage_ContentSuggestions_ArticlesUsage"));
232 } 235 }
233 236
237 int GetCategoryPosition(
238 Category category,
239 const ntp_snippets::ContentSuggestionsService* service) {
240 std::vector<Category> ordered_categories = service->GetCategories();
241 DCHECK(base::ContainsValue(ordered_categories, category));
242 auto it =
243 std::find(ordered_categories.begin(), ordered_categories.end(), category);
244 return it - ordered_categories.begin();
245 }
246
234 } // namespace 247 } // namespace
235 248
236 void OnPageShown( 249 void OnPageShown(
237 const std::vector<std::pair<Category, int>>& suggestions_per_category) { 250 const std::vector<std::pair<Category, int>>& suggestions_per_category) {
238 int suggestions_total = 0; 251 int suggestions_total = 0;
239 for (const std::pair<Category, int>& item : suggestions_per_category) { 252 for (const std::pair<Category, int>& item : suggestions_per_category) {
240 LogCategoryHistogramEnumeration(kHistogramCountOnNtpOpened, item.first, 253 LogCategoryHistogramEnumeration(kHistogramCountOnNtpOpened, item.first,
241 item.second, kMaxSuggestionsPerCategory); 254 item.second, kMaxSuggestionsPerCategory);
242 suggestions_total += item.second; 255 suggestions_total += item.second;
243 } 256 }
244 257
245 UMA_HISTOGRAM_ENUMERATION(kHistogramCountOnNtpOpened, suggestions_total, 258 UMA_HISTOGRAM_ENUMERATION(kHistogramCountOnNtpOpened, suggestions_total,
246 kMaxSuggestionsTotal); 259 kMaxSuggestionsTotal);
247 } 260 }
248 261
249 void OnSuggestionShown(int global_position, 262 void OnSuggestionShown(int global_position,
250 Category category, 263 Category category,
251 int category_position, 264 int position_in_category,
252 base::Time publish_date, 265 base::Time publish_date,
253 base::Time last_background_fetch_time, 266 base::Time last_background_fetch_time,
254 float score) { 267 float score) {
255 UMA_HISTOGRAM_ENUMERATION(kHistogramShown, global_position, 268 UMA_HISTOGRAM_ENUMERATION(kHistogramShown, global_position,
256 kMaxSuggestionsTotal); 269 kMaxSuggestionsTotal);
257 LogCategoryHistogramEnumeration(kHistogramShown, category, category_position, 270 LogCategoryHistogramEnumeration(kHistogramShown, category,
271 position_in_category,
258 kMaxSuggestionsPerCategory); 272 kMaxSuggestionsPerCategory);
259 273
260 base::TimeDelta age = base::Time::Now() - publish_date; 274 base::TimeDelta age = base::Time::Now() - publish_date;
261 LogCategoryHistogramAge(kHistogramShownAge, category, age); 275 LogCategoryHistogramAge(kHistogramShownAge, category, age);
262 276
263 LogCategoryHistogramScore(kHistogramShownScore, category, score); 277 LogCategoryHistogramScore(kHistogramShownScore, category, score);
264 278
265 // TODO(markusheintz): Discuss whether the code below should be move into a 279 // TODO(markusheintz): Discuss whether the code below should be move into a
266 // separate method called OnSuggestionsListShown. 280 // separate method called OnSuggestionsListShown.
267 // When the first of the articles suggestions is shown, then we count this as 281 // When the first of the articles suggestions is shown, then we count this as
268 // a single usage of content suggestions. 282 // a single usage of content suggestions.
269 if (category.IsKnownCategory(KnownCategories::ARTICLES) && 283 if (category.IsKnownCategory(KnownCategories::ARTICLES) &&
270 category_position == 0) { 284 position_in_category == 0) {
271 RecordContentSuggestionsUsage(); 285 RecordContentSuggestionsUsage();
272 286
273 // Records the time since the last background fetch of the remote content 287 // Records the time since the last background fetch of the remote content
274 // suggestions. 288 // suggestions.
275 UMA_HISTOGRAM_CUSTOM_TIMES( 289 UMA_HISTOGRAM_CUSTOM_TIMES(
276 kHistogramContentSuggestionsTimeSinceLastBackgroundFetch, 290 kHistogramContentSuggestionsTimeSinceLastBackgroundFetch,
277 base::Time::Now() - last_background_fetch_time, 291 base::Time::Now() - last_background_fetch_time,
278 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(7), 292 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(7),
279 /*bucket_count=*/100); 293 /*bucket_count=*/100);
280 } 294 }
281 } 295 }
282 296
283 void OnSuggestionOpened(int global_position, 297 void OnSuggestionOpened(const ContentSuggestionsService* service,
298 int global_position,
284 Category category, 299 Category category,
285 int category_position, 300 int position_in_category,
286 base::Time publish_date, 301 base::Time publish_date,
287 float score, 302 float score,
288 WindowOpenDisposition disposition) { 303 WindowOpenDisposition disposition) {
304 const int category_position = GetCategoryPosition(category, service);
305 UMA_HISTOGRAM_ENUMERATION(kHistogramOpenedCategoryPosition, category_position,
306 kMaxCategories);
307 LogCategoryHistogramEnumeration(kHistogramOpenedCategoryPosition, category,
308 category_position, kMaxCategories);
309
289 UMA_HISTOGRAM_ENUMERATION(kHistogramOpened, global_position, 310 UMA_HISTOGRAM_ENUMERATION(kHistogramOpened, global_position,
290 kMaxSuggestionsTotal); 311 kMaxSuggestionsTotal);
291 LogCategoryHistogramEnumeration(kHistogramOpened, category, category_position, 312 LogCategoryHistogramEnumeration(kHistogramOpened, category,
313 position_in_category,
292 kMaxSuggestionsPerCategory); 314 kMaxSuggestionsPerCategory);
293 315
294 base::TimeDelta age = base::Time::Now() - publish_date; 316 base::TimeDelta age = base::Time::Now() - publish_date;
295 LogCategoryHistogramAge(kHistogramOpenedAge, category, age); 317 LogCategoryHistogramAge(kHistogramOpenedAge, category, age);
296 318
297 LogCategoryHistogramScore(kHistogramOpenedScore, category, score); 319 LogCategoryHistogramScore(kHistogramOpenedScore, category, score);
298 320
299 UMA_HISTOGRAM_ENUMERATION( 321 UMA_HISTOGRAM_ENUMERATION(
300 kHistogramOpenDisposition, static_cast<int>(disposition), 322 kHistogramOpenDisposition, static_cast<int>(disposition),
301 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); 323 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1);
302 LogCategoryHistogramEnumeration( 324 LogCategoryHistogramEnumeration(
303 kHistogramOpenDisposition, category, static_cast<int>(disposition), 325 kHistogramOpenDisposition, category, static_cast<int>(disposition),
304 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); 326 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1);
305 327
306 if (category.IsKnownCategory(KnownCategories::ARTICLES)) { 328 if (category.IsKnownCategory(KnownCategories::ARTICLES)) {
307 RecordContentSuggestionsUsage(); 329 RecordContentSuggestionsUsage();
308 } 330 }
309 } 331 }
310 332
311 void OnSuggestionMenuOpened(int global_position, 333 void OnSuggestionMenuOpened(int global_position,
312 Category category, 334 Category category,
313 int category_position, 335 int position_in_category,
314 base::Time publish_date, 336 base::Time publish_date,
315 float score) { 337 float score) {
316 UMA_HISTOGRAM_ENUMERATION(kHistogramMenuOpened, global_position, 338 UMA_HISTOGRAM_ENUMERATION(kHistogramMenuOpened, global_position,
317 kMaxSuggestionsTotal); 339 kMaxSuggestionsTotal);
318 LogCategoryHistogramEnumeration(kHistogramMenuOpened, category, 340 LogCategoryHistogramEnumeration(kHistogramMenuOpened, category,
319 category_position, 341 position_in_category,
320 kMaxSuggestionsPerCategory); 342 kMaxSuggestionsPerCategory);
321 343
322 base::TimeDelta age = base::Time::Now() - publish_date; 344 base::TimeDelta age = base::Time::Now() - publish_date;
323 LogCategoryHistogramAge(kHistogramMenuOpenedAge, category, age); 345 LogCategoryHistogramAge(kHistogramMenuOpenedAge, category, age);
324 346
325 LogCategoryHistogramScore(kHistogramMenuOpenedScore, category, score); 347 LogCategoryHistogramScore(kHistogramMenuOpenedScore, category, score);
326 } 348 }
327 349
328 void OnSuggestionDismissed(int global_position, 350 void OnSuggestionDismissed(int global_position,
329 Category category, 351 Category category,
330 int category_position, 352 int position_in_category,
331 bool visited) { 353 bool visited) {
332 if (visited) { 354 if (visited) {
333 UMA_HISTOGRAM_ENUMERATION(kHistogramDismissedVisited, global_position, 355 UMA_HISTOGRAM_ENUMERATION(kHistogramDismissedVisited, global_position,
334 kMaxSuggestionsTotal); 356 kMaxSuggestionsTotal);
335 LogCategoryHistogramEnumeration(kHistogramDismissedVisited, category, 357 LogCategoryHistogramEnumeration(kHistogramDismissedVisited, category,
336 category_position, 358 position_in_category,
337 kMaxSuggestionsPerCategory); 359 kMaxSuggestionsPerCategory);
338 } else { 360 } else {
339 UMA_HISTOGRAM_ENUMERATION(kHistogramDismissedUnvisited, global_position, 361 UMA_HISTOGRAM_ENUMERATION(kHistogramDismissedUnvisited, global_position,
340 kMaxSuggestionsTotal); 362 kMaxSuggestionsTotal);
341 LogCategoryHistogramEnumeration(kHistogramDismissedUnvisited, category, 363 LogCategoryHistogramEnumeration(kHistogramDismissedUnvisited, category,
342 category_position, 364 position_in_category,
343 kMaxSuggestionsPerCategory); 365 kMaxSuggestionsPerCategory);
344 } 366 }
345 } 367 }
346 368
347 void OnSuggestionTargetVisited(Category category, base::TimeDelta visit_time) { 369 void OnSuggestionTargetVisited(Category category, base::TimeDelta visit_time) {
348 LogCategoryHistogramLongTimes(kHistogramVisitDuration, category, visit_time); 370 LogCategoryHistogramLongTimes(kHistogramVisitDuration, category, visit_time);
349 } 371 }
350 372
351 void OnMoreButtonShown(Category category, int position) { 373 void OnMoreButtonShown(Category category, int position) {
352 // The "more" card can appear in addition to the actual suggestions, so add 374 // The "more" card can appear in addition to the actual suggestions, so add
(...skipping 10 matching lines...) Expand all
363 } 385 }
364 386
365 void OnCategoryDismissed(Category category) { 387 void OnCategoryDismissed(Category category) {
366 UMA_HISTOGRAM_ENUMERATION(kHistogramCategoryDismissed, 388 UMA_HISTOGRAM_ENUMERATION(kHistogramCategoryDismissed,
367 static_cast<int>(GetHistogramCategory(category)), 389 static_cast<int>(GetHistogramCategory(category)),
368 static_cast<int>(HistogramCategories::COUNT)); 390 static_cast<int>(HistogramCategories::COUNT));
369 } 391 }
370 392
371 } // namespace metrics 393 } // namespace metrics
372 } // namespace ntp_snippets 394 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/content_suggestions_metrics.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698