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

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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | tools/metrics/histograms/histograms.xml » ('J')
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..b4f2417ebc8370459f4566d73bf94120c9680ef7 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[] =
@@ -159,6 +161,24 @@ 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.
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
+void RecordContentSuggestionsUsage() {
+ 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.
+ const int kNumBuckets = 24 * 60 / kBucketSize;
+
+ base::Time now(base::Time::Now());
+ base::Time::Exploded now_exploded;
+ 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.
+ 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
+
+ UMA_HISTOGRAM_ENUMERATION(
+ kHistogramUsageTimeLocal,
+ bucket,
+ kNumBuckets);
Marc Treib 2016/11/16 14:14:29 nit: run "git cl format"
markusheintz_ 2016/11/16 14:52:13 Done.
+}
+
} // namespace
void OnPageShown(
@@ -188,6 +208,13 @@ void OnSuggestionShown(int global_position,
LogCategoryHistogramAge(kHistogramShownAge, category, age);
LogCategoryHistogramScore(kHistogramShownScore, category, score);
+
+ // 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.
+ // single usage of content suggestions.
+ // 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.
+ if (global_position == 1) {
+ RecordContentSuggestionsUsage();
+ }
}
void OnSuggestionOpened(int global_position,
« 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