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" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 "NewTabPage.ContentSuggestions.OpenDisposition"; | 33 "NewTabPage.ContentSuggestions.OpenDisposition"; |
| 34 const char kHistogramMenuOpened[] = "NewTabPage.ContentSuggestions.MenuOpened"; | 34 const char kHistogramMenuOpened[] = "NewTabPage.ContentSuggestions.MenuOpened"; |
| 35 const char kHistogramMenuOpenedAge[] = | 35 const char kHistogramMenuOpenedAge[] = |
| 36 "NewTabPage.ContentSuggestions.MenuOpenedAge"; | 36 "NewTabPage.ContentSuggestions.MenuOpenedAge"; |
| 37 const char kHistogramMenuOpenedScore[] = | 37 const char kHistogramMenuOpenedScore[] = |
| 38 "NewTabPage.ContentSuggestions.MenuOpenedScore"; | 38 "NewTabPage.ContentSuggestions.MenuOpenedScore"; |
| 39 const char kHistogramDismissedUnvisited[] = | 39 const char kHistogramDismissedUnvisited[] = |
| 40 "NewTabPage.ContentSuggestions.DismissedUnvisited"; | 40 "NewTabPage.ContentSuggestions.DismissedUnvisited"; |
| 41 const char kHistogramDismissedVisited[] = | 41 const char kHistogramDismissedVisited[] = |
| 42 "NewTabPage.ContentSuggestions.DismissedVisited"; | 42 "NewTabPage.ContentSuggestions.DismissedVisited"; |
| 43 const char kHistogramUsageTimeLocal[] = | |
| 44 "NewTabPage.ContentSuggestions.UsageTimeLocal"; | |
| 43 const char kHistogramVisitDuration[] = | 45 const char kHistogramVisitDuration[] = |
| 44 "NewTabPage.ContentSuggestions.VisitDuration"; | 46 "NewTabPage.ContentSuggestions.VisitDuration"; |
| 45 const char kHistogramMoreButtonShown[] = | 47 const char kHistogramMoreButtonShown[] = |
| 46 "NewTabPage.ContentSuggestions.MoreButtonShown"; | 48 "NewTabPage.ContentSuggestions.MoreButtonShown"; |
| 47 const char kHistogramMoreButtonClicked[] = | 49 const char kHistogramMoreButtonClicked[] = |
| 48 "NewTabPage.ContentSuggestions.MoreButtonClicked"; | 50 "NewTabPage.ContentSuggestions.MoreButtonClicked"; |
| 49 | 51 |
| 50 const char kPerCategoryHistogramFormat[] = "%s.%s"; | 52 const char kPerCategoryHistogramFormat[] = "%s.%s"; |
| 51 | 53 |
| 52 // Each suffix here should correspond to an entry under histogram suffix | 54 // Returns the KnownCategory value for the given Category. |
| 53 // ContentSuggestionCategory in histograms.xml. | 55 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.
| |
| 54 std::string GetCategorySuffix(Category category) { | |
| 55 static_assert( | 56 static_assert( |
| 56 std::is_same<decltype(category.id()), typename base::underlying_type< | 57 std::is_same<decltype(category.id()), typename base::underlying_type< |
| 57 KnownCategories>::type>::value, | 58 KnownCategories>::type>::value, |
| 58 "KnownCategories must have the same underlying type as category.id()"); | 59 "KnownCategories must have the same underlying type as category.id()"); |
| 59 // Note: Since the underlying type of KnownCategories is int, it's legal to | 60 // Note: Since the underlying type of KnownCategories is int, it's legal to |
| 60 // cast from int to KnownCategories, even if the given value isn't listed in | 61 // cast from int to KnownCategories, even if the given value isn't listed in |
| 61 // the enumeration. The switch still makes sure that all known values are | 62 // the enumeration. The switch still makes sure that all known values are |
| 62 // listed here. | 63 // listed here. |
| 63 KnownCategories known_category = static_cast<KnownCategories>(category.id()); | 64 return static_cast<KnownCategories>(category.id()); |
| 65 } | |
| 66 | |
| 67 // Each suffix here should correspond to an entry under histogram suffix | |
| 68 // ContentSuggestionCategory in histograms.xml. | |
| 69 std::string GetCategorySuffix(Category category) { | |
| 70 KnownCategories known_category = GetKnownCategory(category); | |
| 64 switch (known_category) { | 71 switch (known_category) { |
| 65 case KnownCategories::RECENT_TABS: | 72 case KnownCategories::RECENT_TABS: |
| 66 return "RecentTabs"; | 73 return "RecentTabs"; |
| 67 case KnownCategories::DOWNLOADS: | 74 case KnownCategories::DOWNLOADS: |
| 68 return "Downloads"; | 75 return "Downloads"; |
| 69 case KnownCategories::BOOKMARKS: | 76 case KnownCategories::BOOKMARKS: |
| 70 return "Bookmarks"; | 77 return "Bookmarks"; |
| 71 case KnownCategories::PHYSICAL_WEB_PAGES: | 78 case KnownCategories::PHYSICAL_WEB_PAGES: |
| 72 return "PhysicalWeb"; | 79 return "PhysicalWeb"; |
| 73 case KnownCategories::FOREIGN_TABS: | 80 case KnownCategories::FOREIGN_TABS: |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 } | 159 } |
| 153 | 160 |
| 154 void LogCategoryHistogramScore(const char* base_name, | 161 void LogCategoryHistogramScore(const char* base_name, |
| 155 Category category, | 162 Category category, |
| 156 float score) { | 163 float score) { |
| 157 std::string name = GetCategoryHistogramName(base_name, category); | 164 std::string name = GetCategoryHistogramName(base_name, category); |
| 158 // Since the histogram name is dynamic, we can't use the regular macro. | 165 // Since the histogram name is dynamic, we can't use the regular macro. |
| 159 UmaHistogramScore(name, score); | 166 UmaHistogramScore(name, score); |
| 160 } | 167 } |
| 161 | 168 |
| 169 // Records ContentSuggestions usage. Therefore the day is sliced into 20min | |
| 170 // buckets. Depending on the current local time the count of the corresponding | |
| 171 // bucket is increased. | |
| 172 void RecordContentSuggestionsUsage() { | |
| 173 const int kBucketSizeMins = 20; | |
| 174 const int kNumBuckets = 24 * 60 / kBucketSizeMins; | |
| 175 | |
| 176 base::Time::Exploded now_exploded; | |
| 177 base::Time::Now().LocalExplode(&now_exploded); | |
| 178 size_t bucket = | |
| 179 (now_exploded.hour * 60 + now_exploded.minute) / kBucketSizeMins; | |
| 180 | |
| 181 UMA_HISTOGRAM_ENUMERATION(kHistogramUsageTimeLocal, bucket, kNumBuckets); | |
| 182 } | |
| 183 | |
| 162 } // namespace | 184 } // namespace |
| 163 | 185 |
| 164 void OnPageShown( | 186 void OnPageShown( |
| 165 const std::vector<std::pair<Category, int>>& suggestions_per_category) { | 187 const std::vector<std::pair<Category, int>>& suggestions_per_category) { |
| 166 int suggestions_total = 0; | 188 int suggestions_total = 0; |
| 167 for (const std::pair<Category, int>& item : suggestions_per_category) { | 189 for (const std::pair<Category, int>& item : suggestions_per_category) { |
| 168 LogCategoryHistogramEnumeration(kHistogramCountOnNtpOpened, item.first, | 190 LogCategoryHistogramEnumeration(kHistogramCountOnNtpOpened, item.first, |
| 169 item.second, kMaxSuggestionsPerCategory); | 191 item.second, kMaxSuggestionsPerCategory); |
| 170 suggestions_total += item.second; | 192 suggestions_total += item.second; |
| 171 } | 193 } |
| 172 | 194 |
| 173 UMA_HISTOGRAM_ENUMERATION(kHistogramCountOnNtpOpened, suggestions_total, | 195 UMA_HISTOGRAM_ENUMERATION(kHistogramCountOnNtpOpened, suggestions_total, |
| 174 kMaxSuggestionsTotal); | 196 kMaxSuggestionsTotal); |
| 175 } | 197 } |
| 176 | 198 |
| 177 void OnSuggestionShown(int global_position, | 199 void OnSuggestionShown(int global_position, |
| 178 Category category, | 200 Category category, |
| 179 int category_position, | 201 int category_position, |
| 180 base::Time publish_date, | 202 base::Time publish_date, |
| 181 float score) { | 203 float score) { |
| 182 UMA_HISTOGRAM_ENUMERATION(kHistogramShown, global_position, | 204 UMA_HISTOGRAM_ENUMERATION(kHistogramShown, global_position, |
| 183 kMaxSuggestionsTotal); | 205 kMaxSuggestionsTotal); |
| 184 LogCategoryHistogramEnumeration(kHistogramShown, category, category_position, | 206 LogCategoryHistogramEnumeration(kHistogramShown, category, category_position, |
| 185 kMaxSuggestionsPerCategory); | 207 kMaxSuggestionsPerCategory); |
| 186 | 208 |
| 187 base::TimeDelta age = base::Time::Now() - publish_date; | 209 base::TimeDelta age = base::Time::Now() - publish_date; |
| 188 LogCategoryHistogramAge(kHistogramShownAge, category, age); | 210 LogCategoryHistogramAge(kHistogramShownAge, category, age); |
| 189 | 211 |
| 190 LogCategoryHistogramScore(kHistogramShownScore, category, score); | 212 LogCategoryHistogramScore(kHistogramShownScore, category, score); |
| 213 | |
| 214 // 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.
| |
| 215 // single usage of content suggestions. | |
| 216 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.
| |
| 217 category_position == 0) { | |
| 218 RecordContentSuggestionsUsage(); | |
| 219 } | |
| 191 } | 220 } |
| 192 | 221 |
| 193 void OnSuggestionOpened(int global_position, | 222 void OnSuggestionOpened(int global_position, |
| 194 Category category, | 223 Category category, |
| 195 int category_position, | 224 int category_position, |
| 196 base::Time publish_date, | 225 base::Time publish_date, |
| 197 float score, | 226 float score, |
| 198 WindowOpenDisposition disposition) { | 227 WindowOpenDisposition disposition) { |
| 199 UMA_HISTOGRAM_ENUMERATION(kHistogramOpened, global_position, | 228 UMA_HISTOGRAM_ENUMERATION(kHistogramOpened, global_position, |
| 200 kMaxSuggestionsTotal); | 229 kMaxSuggestionsTotal); |
| 201 LogCategoryHistogramEnumeration(kHistogramOpened, category, category_position, | 230 LogCategoryHistogramEnumeration(kHistogramOpened, category, category_position, |
| 202 kMaxSuggestionsPerCategory); | 231 kMaxSuggestionsPerCategory); |
| 203 | 232 |
| 204 base::TimeDelta age = base::Time::Now() - publish_date; | 233 base::TimeDelta age = base::Time::Now() - publish_date; |
| 205 LogCategoryHistogramAge(kHistogramOpenedAge, category, age); | 234 LogCategoryHistogramAge(kHistogramOpenedAge, category, age); |
| 206 | 235 |
| 207 LogCategoryHistogramScore(kHistogramOpenedScore, category, score); | 236 LogCategoryHistogramScore(kHistogramOpenedScore, category, score); |
| 208 | 237 |
| 209 UMA_HISTOGRAM_ENUMERATION( | 238 UMA_HISTOGRAM_ENUMERATION( |
| 210 kHistogramOpenDisposition, static_cast<int>(disposition), | 239 kHistogramOpenDisposition, static_cast<int>(disposition), |
| 211 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); | 240 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); |
| 212 LogCategoryHistogramEnumeration( | 241 LogCategoryHistogramEnumeration( |
| 213 kHistogramOpenDisposition, category, static_cast<int>(disposition), | 242 kHistogramOpenDisposition, category, static_cast<int>(disposition), |
| 214 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); | 243 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); |
| 244 | |
| 245 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.
| |
| 246 RecordContentSuggestionsUsage(); | |
| 247 } | |
| 215 } | 248 } |
| 216 | 249 |
| 217 void OnSuggestionMenuOpened(int global_position, | 250 void OnSuggestionMenuOpened(int global_position, |
| 218 Category category, | 251 Category category, |
| 219 int category_position, | 252 int category_position, |
| 220 base::Time publish_date, | 253 base::Time publish_date, |
| 221 float score) { | 254 float score) { |
| 222 UMA_HISTOGRAM_ENUMERATION(kHistogramMenuOpened, global_position, | 255 UMA_HISTOGRAM_ENUMERATION(kHistogramMenuOpened, global_position, |
| 223 kMaxSuggestionsTotal); | 256 kMaxSuggestionsTotal); |
| 224 LogCategoryHistogramEnumeration(kHistogramMenuOpened, category, | 257 LogCategoryHistogramEnumeration(kHistogramMenuOpened, category, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 | 296 |
| 264 void OnMoreButtonClicked(Category category, int position) { | 297 void OnMoreButtonClicked(Category category, int position) { |
| 265 // The "more" card can appear in addition to the actual suggestions, so add | 298 // The "more" card can appear in addition to the actual suggestions, so add |
| 266 // one extra bucket to this histogram. | 299 // one extra bucket to this histogram. |
| 267 LogCategoryHistogramEnumeration(kHistogramMoreButtonClicked, category, | 300 LogCategoryHistogramEnumeration(kHistogramMoreButtonClicked, category, |
| 268 position, kMaxSuggestionsPerCategory + 1); | 301 position, kMaxSuggestionsPerCategory + 1); |
| 269 } | 302 } |
| 270 | 303 |
| 271 } // namespace metrics | 304 } // namespace metrics |
| 272 } // namespace ntp_snippets | 305 } // namespace ntp_snippets |
| OLD | NEW |