Chromium Code Reviews| OLD | NEW |
|---|---|
| 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; |
| 22 const int kMaxSuggestionsTotal = 50; | 22 const int kMaxSuggestionsTotal = 50; |
| 23 const int kMaxCategories = 20; | |
|
Marc Treib
2017/01/16 10:45:42
This seems a bit excessive - I don't think we'll e
vitaliii
2017/01/18 09:19:20
Is there any downside of overestimating it?
We may
Marc Treib
2017/01/18 09:30:04
Well, the histogram will use more memory, probably
vitaliii
2017/01/18 09:36:30
Done, 10 now.
| |
| 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 kHistogramOpenedCategoryRank[] = | |
| 33 "NewTabPage.ContentSuggestions.OpenedCategoryRank"; | |
| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 item.second, kMaxSuggestionsPerCategory); | 244 item.second, kMaxSuggestionsPerCategory); |
| 242 suggestions_total += item.second; | 245 suggestions_total += item.second; |
| 243 } | 246 } |
| 244 | 247 |
| 245 UMA_HISTOGRAM_ENUMERATION(kHistogramCountOnNtpOpened, suggestions_total, | 248 UMA_HISTOGRAM_ENUMERATION(kHistogramCountOnNtpOpened, suggestions_total, |
| 246 kMaxSuggestionsTotal); | 249 kMaxSuggestionsTotal); |
| 247 } | 250 } |
| 248 | 251 |
| 249 void OnSuggestionShown(int global_position, | 252 void OnSuggestionShown(int global_position, |
| 250 Category category, | 253 Category category, |
| 251 int category_position, | 254 int position_in_category, |
| 252 base::Time publish_date, | 255 base::Time publish_date, |
| 253 base::Time last_background_fetch_time, | 256 base::Time last_background_fetch_time, |
| 254 float score) { | 257 float score) { |
| 255 UMA_HISTOGRAM_ENUMERATION(kHistogramShown, global_position, | 258 UMA_HISTOGRAM_ENUMERATION(kHistogramShown, global_position, |
| 256 kMaxSuggestionsTotal); | 259 kMaxSuggestionsTotal); |
| 257 LogCategoryHistogramEnumeration(kHistogramShown, category, category_position, | 260 LogCategoryHistogramEnumeration(kHistogramShown, category, |
| 261 position_in_category, | |
| 258 kMaxSuggestionsPerCategory); | 262 kMaxSuggestionsPerCategory); |
| 259 | 263 |
| 260 base::TimeDelta age = base::Time::Now() - publish_date; | 264 base::TimeDelta age = base::Time::Now() - publish_date; |
| 261 LogCategoryHistogramAge(kHistogramShownAge, category, age); | 265 LogCategoryHistogramAge(kHistogramShownAge, category, age); |
| 262 | 266 |
| 263 LogCategoryHistogramScore(kHistogramShownScore, category, score); | 267 LogCategoryHistogramScore(kHistogramShownScore, category, score); |
| 264 | 268 |
| 265 // TODO(markusheintz): Discuss whether the code below should be move into a | 269 // TODO(markusheintz): Discuss whether the code below should be move into a |
| 266 // separate method called OnSuggestionsListShown. | 270 // separate method called OnSuggestionsListShown. |
| 267 // When the first of the articles suggestions is shown, then we count this as | 271 // When the first of the articles suggestions is shown, then we count this as |
| 268 // a single usage of content suggestions. | 272 // a single usage of content suggestions. |
| 269 if (category.IsKnownCategory(KnownCategories::ARTICLES) && | 273 if (category.IsKnownCategory(KnownCategories::ARTICLES) && |
| 270 category_position == 0) { | 274 position_in_category == 0) { |
| 271 RecordContentSuggestionsUsage(); | 275 RecordContentSuggestionsUsage(); |
| 272 | 276 |
| 273 // Records the time since the last background fetch of the remote content | 277 // Records the time since the last background fetch of the remote content |
| 274 // suggestions. | 278 // suggestions. |
| 275 UMA_HISTOGRAM_CUSTOM_TIMES( | 279 UMA_HISTOGRAM_CUSTOM_TIMES( |
| 276 kHistogramContentSuggestionsTimeSinceLastBackgroundFetch, | 280 kHistogramContentSuggestionsTimeSinceLastBackgroundFetch, |
| 277 base::Time::Now() - last_background_fetch_time, | 281 base::Time::Now() - last_background_fetch_time, |
| 278 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(7), | 282 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(7), |
| 279 /*bucket_count=*/100); | 283 /*bucket_count=*/100); |
| 280 } | 284 } |
| 281 } | 285 } |
| 282 | 286 |
| 283 void OnSuggestionOpened(int global_position, | 287 void OnSuggestionOpened(int global_position, |
| 284 Category category, | 288 Category category, |
| 285 int category_position, | 289 int category_rank, |
| 290 int position_in_category, | |
| 286 base::Time publish_date, | 291 base::Time publish_date, |
| 287 float score, | 292 float score, |
| 288 WindowOpenDisposition disposition) { | 293 WindowOpenDisposition disposition) { |
| 294 UMA_HISTOGRAM_ENUMERATION(kHistogramOpenedCategoryRank, category_rank, | |
| 295 kMaxCategories); | |
| 296 LogCategoryHistogramEnumeration(kHistogramOpenedCategoryRank, category, | |
| 297 category_rank, kMaxCategories); | |
| 298 | |
| 289 UMA_HISTOGRAM_ENUMERATION(kHistogramOpened, global_position, | 299 UMA_HISTOGRAM_ENUMERATION(kHistogramOpened, global_position, |
| 290 kMaxSuggestionsTotal); | 300 kMaxSuggestionsTotal); |
| 291 LogCategoryHistogramEnumeration(kHistogramOpened, category, category_position, | 301 LogCategoryHistogramEnumeration(kHistogramOpened, category, |
| 302 position_in_category, | |
| 292 kMaxSuggestionsPerCategory); | 303 kMaxSuggestionsPerCategory); |
| 293 | 304 |
| 294 base::TimeDelta age = base::Time::Now() - publish_date; | 305 base::TimeDelta age = base::Time::Now() - publish_date; |
| 295 LogCategoryHistogramAge(kHistogramOpenedAge, category, age); | 306 LogCategoryHistogramAge(kHistogramOpenedAge, category, age); |
| 296 | 307 |
| 297 LogCategoryHistogramScore(kHistogramOpenedScore, category, score); | 308 LogCategoryHistogramScore(kHistogramOpenedScore, category, score); |
| 298 | 309 |
| 299 UMA_HISTOGRAM_ENUMERATION( | 310 UMA_HISTOGRAM_ENUMERATION( |
| 300 kHistogramOpenDisposition, static_cast<int>(disposition), | 311 kHistogramOpenDisposition, static_cast<int>(disposition), |
| 301 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); | 312 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); |
| 302 LogCategoryHistogramEnumeration( | 313 LogCategoryHistogramEnumeration( |
| 303 kHistogramOpenDisposition, category, static_cast<int>(disposition), | 314 kHistogramOpenDisposition, category, static_cast<int>(disposition), |
| 304 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); | 315 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); |
| 305 | 316 |
| 306 if (category.IsKnownCategory(KnownCategories::ARTICLES)) { | 317 if (category.IsKnownCategory(KnownCategories::ARTICLES)) { |
| 307 RecordContentSuggestionsUsage(); | 318 RecordContentSuggestionsUsage(); |
| 308 } | 319 } |
| 309 } | 320 } |
| 310 | 321 |
| 311 void OnSuggestionMenuOpened(int global_position, | 322 void OnSuggestionMenuOpened(int global_position, |
| 312 Category category, | 323 Category category, |
| 313 int category_position, | 324 int position_in_category, |
| 314 base::Time publish_date, | 325 base::Time publish_date, |
| 315 float score) { | 326 float score) { |
| 316 UMA_HISTOGRAM_ENUMERATION(kHistogramMenuOpened, global_position, | 327 UMA_HISTOGRAM_ENUMERATION(kHistogramMenuOpened, global_position, |
| 317 kMaxSuggestionsTotal); | 328 kMaxSuggestionsTotal); |
| 318 LogCategoryHistogramEnumeration(kHistogramMenuOpened, category, | 329 LogCategoryHistogramEnumeration(kHistogramMenuOpened, category, |
| 319 category_position, | 330 position_in_category, |
| 320 kMaxSuggestionsPerCategory); | 331 kMaxSuggestionsPerCategory); |
| 321 | 332 |
| 322 base::TimeDelta age = base::Time::Now() - publish_date; | 333 base::TimeDelta age = base::Time::Now() - publish_date; |
| 323 LogCategoryHistogramAge(kHistogramMenuOpenedAge, category, age); | 334 LogCategoryHistogramAge(kHistogramMenuOpenedAge, category, age); |
| 324 | 335 |
| 325 LogCategoryHistogramScore(kHistogramMenuOpenedScore, category, score); | 336 LogCategoryHistogramScore(kHistogramMenuOpenedScore, category, score); |
| 326 } | 337 } |
| 327 | 338 |
| 328 void OnSuggestionDismissed(int global_position, | 339 void OnSuggestionDismissed(int global_position, |
| 329 Category category, | 340 Category category, |
| 330 int category_position, | 341 int position_in_category, |
| 331 bool visited) { | 342 bool visited) { |
| 332 if (visited) { | 343 if (visited) { |
| 333 UMA_HISTOGRAM_ENUMERATION(kHistogramDismissedVisited, global_position, | 344 UMA_HISTOGRAM_ENUMERATION(kHistogramDismissedVisited, global_position, |
| 334 kMaxSuggestionsTotal); | 345 kMaxSuggestionsTotal); |
| 335 LogCategoryHistogramEnumeration(kHistogramDismissedVisited, category, | 346 LogCategoryHistogramEnumeration(kHistogramDismissedVisited, category, |
| 336 category_position, | 347 position_in_category, |
| 337 kMaxSuggestionsPerCategory); | 348 kMaxSuggestionsPerCategory); |
| 338 } else { | 349 } else { |
| 339 UMA_HISTOGRAM_ENUMERATION(kHistogramDismissedUnvisited, global_position, | 350 UMA_HISTOGRAM_ENUMERATION(kHistogramDismissedUnvisited, global_position, |
| 340 kMaxSuggestionsTotal); | 351 kMaxSuggestionsTotal); |
| 341 LogCategoryHistogramEnumeration(kHistogramDismissedUnvisited, category, | 352 LogCategoryHistogramEnumeration(kHistogramDismissedUnvisited, category, |
| 342 category_position, | 353 position_in_category, |
| 343 kMaxSuggestionsPerCategory); | 354 kMaxSuggestionsPerCategory); |
| 344 } | 355 } |
| 345 } | 356 } |
| 346 | 357 |
| 347 void OnSuggestionTargetVisited(Category category, base::TimeDelta visit_time) { | 358 void OnSuggestionTargetVisited(Category category, base::TimeDelta visit_time) { |
| 348 LogCategoryHistogramLongTimes(kHistogramVisitDuration, category, visit_time); | 359 LogCategoryHistogramLongTimes(kHistogramVisitDuration, category, visit_time); |
| 349 } | 360 } |
| 350 | 361 |
| 351 void OnMoreButtonShown(Category category, int position) { | 362 void OnMoreButtonShown(Category category, int position) { |
| 352 // The "more" card can appear in addition to the actual suggestions, so add | 363 // The "more" card can appear in addition to the actual suggestions, so add |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 363 } | 374 } |
| 364 | 375 |
| 365 void OnCategoryDismissed(Category category) { | 376 void OnCategoryDismissed(Category category) { |
| 366 UMA_HISTOGRAM_ENUMERATION(kHistogramCategoryDismissed, | 377 UMA_HISTOGRAM_ENUMERATION(kHistogramCategoryDismissed, |
| 367 static_cast<int>(GetHistogramCategory(category)), | 378 static_cast<int>(GetHistogramCategory(category)), |
| 368 static_cast<int>(HistogramCategories::COUNT)); | 379 static_cast<int>(HistogramCategories::COUNT)); |
| 369 } | 380 } |
| 370 | 381 |
| 371 } // namespace metrics | 382 } // namespace metrics |
| 372 } // namespace ntp_snippets | 383 } // namespace ntp_snippets |
| OLD | NEW |