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

Unified Diff: components/ntp_snippets/content_suggestions_metrics.cc

Issue 2509663002: Add a histogram for recording content suggestions local usage time stats. (Closed)
Patch Set: Address comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ntp_snippets/content_suggestions_metrics.cc
diff --git a/components/ntp_snippets/content_suggestions_metrics.cc b/components/ntp_snippets/content_suggestions_metrics.cc
index 4117fae096bb855d15ecd5949833e97b1e046919..32d52cfdb7ef64ccc31854d474e68db2e9deb164 100644
--- a/components/ntp_snippets/content_suggestions_metrics.cc
+++ b/components/ntp_snippets/content_suggestions_metrics.cc
@@ -40,6 +40,8 @@ const char kHistogramDismissedUnvisited[] =
"NewTabPage.ContentSuggestions.DismissedUnvisited";
const char kHistogramDismissedVisited[] =
"NewTabPage.ContentSuggestions.DismissedVisited";
+const char kHistogramUsageTimeLocal[] =
+ "NewTabPage.ContentSuggestions.UsageTimeLocal";
const char kHistogramVisitDuration[] =
"NewTabPage.ContentSuggestions.VisitDuration";
const char kHistogramMoreButtonShown[] =
@@ -49,9 +51,8 @@ const char kHistogramMoreButtonClicked[] =
const char kPerCategoryHistogramFormat[] = "%s.%s";
-// Each suffix here should correspond to an entry under histogram suffix
-// ContentSuggestionCategory in histograms.xml.
-std::string GetCategorySuffix(Category category) {
+// Returns the KnownCategory value for the given Category.
+KnownCategories GetKnownCategory(Category category) {
Marc Treib 2016/11/16 16:00:55 Per the comments below, this isn't necessary. (I w
markusheintz_ 2016/11/16 16:09:42 Done.
static_assert(
std::is_same<decltype(category.id()), typename base::underlying_type<
KnownCategories>::type>::value,
@@ -60,7 +61,13 @@ std::string GetCategorySuffix(Category category) {
// cast from int to KnownCategories, even if the given value isn't listed in
// the enumeration. The switch still makes sure that all known values are
// listed here.
- KnownCategories known_category = static_cast<KnownCategories>(category.id());
+ return static_cast<KnownCategories>(category.id());
+}
+
+// Each suffix here should correspond to an entry under histogram suffix
+// ContentSuggestionCategory in histograms.xml.
+std::string GetCategorySuffix(Category category) {
+ KnownCategories known_category = GetKnownCategory(category);
switch (known_category) {
case KnownCategories::RECENT_TABS:
return "RecentTabs";
@@ -159,6 +166,21 @@ void LogCategoryHistogramScore(const char* base_name,
UmaHistogramScore(name, score);
}
+// Records ContentSuggestions usage. Therefore the day is sliced into 20min
+// buckets. Depending on the current local time the count of the corresponding
+// bucket is increased.
+void RecordContentSuggestionsUsage() {
+ const int kBucketSizeMins = 20;
+ const int kNumBuckets = 24 * 60 / kBucketSizeMins;
+
+ base::Time::Exploded now_exploded;
+ base::Time::Now().LocalExplode(&now_exploded);
+ size_t bucket =
+ (now_exploded.hour * 60 + now_exploded.minute) / kBucketSizeMins;
+
+ UMA_HISTOGRAM_ENUMERATION(kHistogramUsageTimeLocal, bucket, kNumBuckets);
+}
+
} // namespace
void OnPageShown(
@@ -188,6 +210,13 @@ void OnSuggestionShown(int global_position,
LogCategoryHistogramAge(kHistogramShownAge, category, age);
LogCategoryHistogramScore(kHistogramShownScore, category, score);
+
+ // When the first of all suggestions is shown, then we count this as a
Marc Treib 2016/11/16 16:00:55 nit: Now it's not the first of all suggestions any
markusheintz_ 2016/11/16 16:09:42 Done.
+ // single usage of content suggestions.
+ if (GetKnownCategory(category) == KnownCategories::ARTICLES &&
Marc Treib 2016/11/16 16:00:55 category.IsKnownCategory(KnownCategories::ARTICLES
markusheintz_ 2016/11/16 16:09:42 Done.
+ category_position == 0) {
+ RecordContentSuggestionsUsage();
+ }
}
void OnSuggestionOpened(int global_position,
@@ -212,6 +241,10 @@ void OnSuggestionOpened(int global_position,
LogCategoryHistogramEnumeration(
kHistogramOpenDisposition, category, static_cast<int>(disposition),
static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1);
+
+ if (GetKnownCategory(category) == KnownCategories::ARTICLES) {
Marc Treib 2016/11/16 16:00:55 Also here: category.IsKnownCategory(KnownCategorie
markusheintz_ 2016/11/16 16:09:42 Done.
+ RecordContentSuggestionsUsage();
+ }
}
void OnSuggestionMenuOpened(int global_position,
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698