| 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 <cmath> | 7 #include <cmath> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <type_traits> | 9 #include <type_traits> |
| 10 | 10 |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/metrics/histogram_functions.h" | 12 #include "base/metrics/histogram_functions.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/metrics/user_metrics.h" | 14 #include "base/metrics/user_metrics.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/template_util.h" | 16 #include "base/template_util.h" |
| 17 | 17 |
| 18 namespace ntp_snippets { | 18 namespace ntp_snippets { |
| 19 namespace metrics { | 19 namespace metrics { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const int kMaxSuggestionsPerCategory = 10; | 23 const int kMaxSuggestionsPerCategory = 10; |
| 24 const int kMaxSuggestionsTotal = 50; | 24 const int kMaxSuggestionsTotal = 50; |
| 25 const int kMaxCategories = 10; |
| 25 | 26 |
| 26 const char kHistogramCountOnNtpOpened[] = | 27 const char kHistogramCountOnNtpOpened[] = |
| 27 "NewTabPage.ContentSuggestions.CountOnNtpOpened"; | 28 "NewTabPage.ContentSuggestions.CountOnNtpOpened"; |
| 28 const char kHistogramShown[] = "NewTabPage.ContentSuggestions.Shown"; | 29 const char kHistogramShown[] = "NewTabPage.ContentSuggestions.Shown"; |
| 29 const char kHistogramShownAge[] = "NewTabPage.ContentSuggestions.ShownAge"; | 30 const char kHistogramShownAge[] = "NewTabPage.ContentSuggestions.ShownAge"; |
| 30 const char kHistogramShownScore[] = | 31 const char kHistogramShownScore[] = |
| 31 "NewTabPage.ContentSuggestions.ShownScoreNormalized"; | 32 "NewTabPage.ContentSuggestions.ShownScoreNormalized"; |
| 32 const char kHistogramOpened[] = "NewTabPage.ContentSuggestions.Opened"; | 33 const char kHistogramOpened[] = "NewTabPage.ContentSuggestions.Opened"; |
| 33 const char kHistogramOpenedAge[] = "NewTabPage.ContentSuggestions.OpenedAge"; | 34 const char kHistogramOpenedAge[] = "NewTabPage.ContentSuggestions.OpenedAge"; |
| 35 const char kHistogramOpenedCategoryIndex[] = |
| 36 "NewTabPage.ContentSuggestions.OpenedCategoryIndex"; |
| 34 const char kHistogramOpenedScore[] = | 37 const char kHistogramOpenedScore[] = |
| 35 "NewTabPage.ContentSuggestions.OpenedScoreNormalized"; | 38 "NewTabPage.ContentSuggestions.OpenedScoreNormalized"; |
| 36 const char kHistogramOpenDisposition[] = | 39 const char kHistogramOpenDisposition[] = |
| 37 "NewTabPage.ContentSuggestions.OpenDisposition"; | 40 "NewTabPage.ContentSuggestions.OpenDisposition"; |
| 38 const char kHistogramMenuOpened[] = "NewTabPage.ContentSuggestions.MenuOpened"; | 41 const char kHistogramMenuOpened[] = "NewTabPage.ContentSuggestions.MenuOpened"; |
| 39 const char kHistogramMenuOpenedAge[] = | 42 const char kHistogramMenuOpenedAge[] = |
| 40 "NewTabPage.ContentSuggestions.MenuOpenedAge"; | 43 "NewTabPage.ContentSuggestions.MenuOpenedAge"; |
| 41 const char kHistogramMenuOpenedScore[] = | 44 const char kHistogramMenuOpenedScore[] = |
| 42 "NewTabPage.ContentSuggestions.MenuOpenedScoreNormalized"; | 45 "NewTabPage.ContentSuggestions.MenuOpenedScoreNormalized"; |
| 43 const char kHistogramDismissedUnvisited[] = | 46 const char kHistogramDismissedUnvisited[] = |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 LogCategoryHistogramPosition(kHistogramCountOnNtpOpened, item.first, | 212 LogCategoryHistogramPosition(kHistogramCountOnNtpOpened, item.first, |
| 210 item.second, kMaxSuggestionsPerCategory); | 213 item.second, kMaxSuggestionsPerCategory); |
| 211 suggestions_total += item.second; | 214 suggestions_total += item.second; |
| 212 } | 215 } |
| 213 UMA_HISTOGRAM_EXACT_LINEAR(kHistogramCountOnNtpOpened, suggestions_total, | 216 UMA_HISTOGRAM_EXACT_LINEAR(kHistogramCountOnNtpOpened, suggestions_total, |
| 214 kMaxSuggestionsTotal); | 217 kMaxSuggestionsTotal); |
| 215 } | 218 } |
| 216 | 219 |
| 217 void OnSuggestionShown(int global_position, | 220 void OnSuggestionShown(int global_position, |
| 218 Category category, | 221 Category category, |
| 219 int category_position, | 222 int position_in_category, |
| 220 base::Time publish_date, | 223 base::Time publish_date, |
| 221 base::Time last_background_fetch_time, | 224 base::Time last_background_fetch_time, |
| 222 float score) { | 225 float score) { |
| 223 UMA_HISTOGRAM_EXACT_LINEAR(kHistogramShown, global_position, | 226 UMA_HISTOGRAM_EXACT_LINEAR(kHistogramShown, global_position, |
| 224 kMaxSuggestionsTotal); | 227 kMaxSuggestionsTotal); |
| 225 LogCategoryHistogramPosition(kHistogramShown, category, category_position, | 228 LogCategoryHistogramPosition(kHistogramShown, category, position_in_category, |
| 226 kMaxSuggestionsPerCategory); | 229 kMaxSuggestionsPerCategory); |
| 227 | 230 |
| 228 base::TimeDelta age = base::Time::Now() - publish_date; | 231 base::TimeDelta age = base::Time::Now() - publish_date; |
| 229 LogCategoryHistogramAge(kHistogramShownAge, category, age); | 232 LogCategoryHistogramAge(kHistogramShownAge, category, age); |
| 230 | 233 |
| 231 LogCategoryHistogramScore(kHistogramShownScore, category, score); | 234 LogCategoryHistogramScore(kHistogramShownScore, category, score); |
| 232 | 235 |
| 233 // TODO(markusheintz): Discuss whether the code below should be move into a | 236 // TODO(markusheintz): Discuss whether the code below should be move into a |
| 234 // separate method called OnSuggestionsListShown. | 237 // separate method called OnSuggestionsListShown. |
| 235 // When the first of the articles suggestions is shown, then we count this as | 238 // When the first of the articles suggestions is shown, then we count this as |
| 236 // a single usage of content suggestions. | 239 // a single usage of content suggestions. |
| 237 if (category.IsKnownCategory(KnownCategories::ARTICLES) && | 240 if (category.IsKnownCategory(KnownCategories::ARTICLES) && |
| 238 category_position == 0) { | 241 position_in_category == 0) { |
| 239 RecordContentSuggestionsUsage(); | 242 RecordContentSuggestionsUsage(); |
| 240 | 243 |
| 241 // Records the time since the last background fetch of the remote content | 244 // Records the time since the last background fetch of the remote content |
| 242 // suggestions. | 245 // suggestions. |
| 243 UMA_HISTOGRAM_CUSTOM_TIMES( | 246 UMA_HISTOGRAM_CUSTOM_TIMES( |
| 244 kHistogramContentSuggestionsTimeSinceLastBackgroundFetch, | 247 kHistogramContentSuggestionsTimeSinceLastBackgroundFetch, |
| 245 base::Time::Now() - last_background_fetch_time, | 248 base::Time::Now() - last_background_fetch_time, |
| 246 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(7), | 249 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(7), |
| 247 /*bucket_count=*/100); | 250 /*bucket_count=*/100); |
| 248 } | 251 } |
| 249 } | 252 } |
| 250 | 253 |
| 251 void OnSuggestionOpened(int global_position, | 254 void OnSuggestionOpened(int global_position, |
| 252 Category category, | 255 Category category, |
| 253 int category_position, | 256 int category_index, |
| 257 int position_in_category, |
| 254 base::Time publish_date, | 258 base::Time publish_date, |
| 255 float score, | 259 float score, |
| 256 WindowOpenDisposition disposition) { | 260 WindowOpenDisposition disposition) { |
| 261 UMA_HISTOGRAM_EXACT_LINEAR(kHistogramOpenedCategoryIndex, category_index, |
| 262 kMaxCategories); |
| 263 LogCategoryHistogramPosition(kHistogramOpenedCategoryIndex, category, |
| 264 category_index, kMaxCategories); |
| 265 |
| 257 UMA_HISTOGRAM_EXACT_LINEAR(kHistogramOpened, global_position, | 266 UMA_HISTOGRAM_EXACT_LINEAR(kHistogramOpened, global_position, |
| 258 kMaxSuggestionsTotal); | 267 kMaxSuggestionsTotal); |
| 259 LogCategoryHistogramPosition(kHistogramOpened, category, category_position, | 268 LogCategoryHistogramPosition(kHistogramOpened, category, position_in_category, |
| 260 kMaxSuggestionsPerCategory); | 269 kMaxSuggestionsPerCategory); |
| 261 | 270 |
| 262 base::TimeDelta age = base::Time::Now() - publish_date; | 271 base::TimeDelta age = base::Time::Now() - publish_date; |
| 263 LogCategoryHistogramAge(kHistogramOpenedAge, category, age); | 272 LogCategoryHistogramAge(kHistogramOpenedAge, category, age); |
| 264 | 273 |
| 265 LogCategoryHistogramScore(kHistogramOpenedScore, category, score); | 274 LogCategoryHistogramScore(kHistogramOpenedScore, category, score); |
| 266 | 275 |
| 267 // We use WindowOpenDisposition::MAX_VALUE + 1 for |value_max| since MAX_VALUE | 276 // We use WindowOpenDisposition::MAX_VALUE + 1 for |value_max| since MAX_VALUE |
| 268 // itself is a valid (and used) enum value. | 277 // itself is a valid (and used) enum value. |
| 269 UMA_HISTOGRAM_EXACT_LINEAR( | 278 UMA_HISTOGRAM_EXACT_LINEAR( |
| 270 kHistogramOpenDisposition, static_cast<int>(disposition), | 279 kHistogramOpenDisposition, static_cast<int>(disposition), |
| 271 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); | 280 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); |
| 272 base::UmaHistogramExactLinear( | 281 base::UmaHistogramExactLinear( |
| 273 GetCategoryHistogramName(kHistogramOpenDisposition, category), | 282 GetCategoryHistogramName(kHistogramOpenDisposition, category), |
| 274 static_cast<int>(disposition), | 283 static_cast<int>(disposition), |
| 275 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); | 284 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); |
| 276 | 285 |
| 277 if (category.IsKnownCategory(KnownCategories::ARTICLES)) { | 286 if (category.IsKnownCategory(KnownCategories::ARTICLES)) { |
| 278 RecordContentSuggestionsUsage(); | 287 RecordContentSuggestionsUsage(); |
| 279 } | 288 } |
| 280 } | 289 } |
| 281 | 290 |
| 282 void OnSuggestionMenuOpened(int global_position, | 291 void OnSuggestionMenuOpened(int global_position, |
| 283 Category category, | 292 Category category, |
| 284 int category_position, | 293 int position_in_category, |
| 285 base::Time publish_date, | 294 base::Time publish_date, |
| 286 float score) { | 295 float score) { |
| 287 UMA_HISTOGRAM_EXACT_LINEAR(kHistogramMenuOpened, global_position, | 296 UMA_HISTOGRAM_EXACT_LINEAR(kHistogramMenuOpened, global_position, |
| 288 kMaxSuggestionsTotal); | 297 kMaxSuggestionsTotal); |
| 289 LogCategoryHistogramPosition(kHistogramMenuOpened, category, | 298 LogCategoryHistogramPosition(kHistogramMenuOpened, category, |
| 290 category_position, kMaxSuggestionsPerCategory); | 299 position_in_category, |
| 300 kMaxSuggestionsPerCategory); |
| 291 | 301 |
| 292 base::TimeDelta age = base::Time::Now() - publish_date; | 302 base::TimeDelta age = base::Time::Now() - publish_date; |
| 293 LogCategoryHistogramAge(kHistogramMenuOpenedAge, category, age); | 303 LogCategoryHistogramAge(kHistogramMenuOpenedAge, category, age); |
| 294 | 304 |
| 295 LogCategoryHistogramScore(kHistogramMenuOpenedScore, category, score); | 305 LogCategoryHistogramScore(kHistogramMenuOpenedScore, category, score); |
| 296 } | 306 } |
| 297 | 307 |
| 298 void OnSuggestionDismissed(int global_position, | 308 void OnSuggestionDismissed(int global_position, |
| 299 Category category, | 309 Category category, |
| 300 int category_position, | 310 int position_in_category, |
| 301 bool visited) { | 311 bool visited) { |
| 302 if (visited) { | 312 if (visited) { |
| 303 UMA_HISTOGRAM_EXACT_LINEAR(kHistogramDismissedVisited, global_position, | 313 UMA_HISTOGRAM_EXACT_LINEAR(kHistogramDismissedVisited, global_position, |
| 304 kMaxSuggestionsTotal); | 314 kMaxSuggestionsTotal); |
| 305 LogCategoryHistogramPosition(kHistogramDismissedVisited, category, | 315 LogCategoryHistogramPosition(kHistogramDismissedVisited, category, |
| 306 category_position, kMaxSuggestionsPerCategory); | 316 position_in_category, |
| 317 kMaxSuggestionsPerCategory); |
| 307 } else { | 318 } else { |
| 308 UMA_HISTOGRAM_EXACT_LINEAR(kHistogramDismissedUnvisited, global_position, | 319 UMA_HISTOGRAM_EXACT_LINEAR(kHistogramDismissedUnvisited, global_position, |
| 309 kMaxSuggestionsTotal); | 320 kMaxSuggestionsTotal); |
| 310 LogCategoryHistogramPosition(kHistogramDismissedUnvisited, category, | 321 LogCategoryHistogramPosition(kHistogramDismissedUnvisited, category, |
| 311 category_position, kMaxSuggestionsPerCategory); | 322 position_in_category, |
| 323 kMaxSuggestionsPerCategory); |
| 312 } | 324 } |
| 313 } | 325 } |
| 314 | 326 |
| 315 void OnSuggestionTargetVisited(Category category, base::TimeDelta visit_time) { | 327 void OnSuggestionTargetVisited(Category category, base::TimeDelta visit_time) { |
| 316 std::string name = | 328 std::string name = |
| 317 GetCategoryHistogramName(kHistogramVisitDuration, category); | 329 GetCategoryHistogramName(kHistogramVisitDuration, category); |
| 318 base::UmaHistogramLongTimes(name, visit_time); | 330 base::UmaHistogramLongTimes(name, visit_time); |
| 319 } | 331 } |
| 320 | 332 |
| 321 void OnMoreButtonShown(Category category, int position) { | 333 void OnMoreButtonShown(Category category, int position) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 333 } | 345 } |
| 334 | 346 |
| 335 void OnCategoryDismissed(Category category) { | 347 void OnCategoryDismissed(Category category) { |
| 336 UMA_HISTOGRAM_ENUMERATION(kHistogramCategoryDismissed, | 348 UMA_HISTOGRAM_ENUMERATION(kHistogramCategoryDismissed, |
| 337 GetHistogramCategory(category), | 349 GetHistogramCategory(category), |
| 338 HistogramCategories::COUNT); | 350 HistogramCategories::COUNT); |
| 339 } | 351 } |
| 340 | 352 |
| 341 } // namespace metrics | 353 } // namespace metrics |
| 342 } // namespace ntp_snippets | 354 } // namespace ntp_snippets |
| OLD | NEW |