| 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 // Each suffix here should correspond to an entry under histogram suffix |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 154 } |
| 153 | 155 |
| 154 void LogCategoryHistogramScore(const char* base_name, | 156 void LogCategoryHistogramScore(const char* base_name, |
| 155 Category category, | 157 Category category, |
| 156 float score) { | 158 float score) { |
| 157 std::string name = GetCategoryHistogramName(base_name, category); | 159 std::string name = GetCategoryHistogramName(base_name, category); |
| 158 // Since the histogram name is dynamic, we can't use the regular macro. | 160 // Since the histogram name is dynamic, we can't use the regular macro. |
| 159 UmaHistogramScore(name, score); | 161 UmaHistogramScore(name, score); |
| 160 } | 162 } |
| 161 | 163 |
| 164 // Records ContentSuggestions usage. Therefore the day is sliced into 20min |
| 165 // buckets. Depending on the current local time the count of the corresponding |
| 166 // bucket is increased. |
| 167 void RecordContentSuggestionsUsage() { |
| 168 const int kBucketSizeMins = 20; |
| 169 const int kNumBuckets = 24 * 60 / kBucketSizeMins; |
| 170 |
| 171 base::Time::Exploded now_exploded; |
| 172 base::Time::Now().LocalExplode(&now_exploded); |
| 173 size_t bucket = |
| 174 (now_exploded.hour * 60 + now_exploded.minute) / kBucketSizeMins; |
| 175 |
| 176 UMA_HISTOGRAM_ENUMERATION(kHistogramUsageTimeLocal, bucket, kNumBuckets); |
| 177 |
| 178 LOG(ERROR) << " ****************** Zine Usage"; |
| 179 } |
| 180 |
| 162 } // namespace | 181 } // namespace |
| 163 | 182 |
| 164 void OnPageShown( | 183 void OnPageShown( |
| 165 const std::vector<std::pair<Category, int>>& suggestions_per_category) { | 184 const std::vector<std::pair<Category, int>>& suggestions_per_category) { |
| 166 int suggestions_total = 0; | 185 int suggestions_total = 0; |
| 167 for (const std::pair<Category, int>& item : suggestions_per_category) { | 186 for (const std::pair<Category, int>& item : suggestions_per_category) { |
| 168 LogCategoryHistogramEnumeration(kHistogramCountOnNtpOpened, item.first, | 187 LogCategoryHistogramEnumeration(kHistogramCountOnNtpOpened, item.first, |
| 169 item.second, kMaxSuggestionsPerCategory); | 188 item.second, kMaxSuggestionsPerCategory); |
| 170 suggestions_total += item.second; | 189 suggestions_total += item.second; |
| 171 } | 190 } |
| 172 | 191 |
| 173 UMA_HISTOGRAM_ENUMERATION(kHistogramCountOnNtpOpened, suggestions_total, | 192 UMA_HISTOGRAM_ENUMERATION(kHistogramCountOnNtpOpened, suggestions_total, |
| 174 kMaxSuggestionsTotal); | 193 kMaxSuggestionsTotal); |
| 175 } | 194 } |
| 176 | 195 |
| 177 void OnSuggestionShown(int global_position, | 196 void OnSuggestionShown(int global_position, |
| 178 Category category, | 197 Category category, |
| 179 int category_position, | 198 int category_position, |
| 180 base::Time publish_date, | 199 base::Time publish_date, |
| 181 float score) { | 200 float score) { |
| 182 UMA_HISTOGRAM_ENUMERATION(kHistogramShown, global_position, | 201 UMA_HISTOGRAM_ENUMERATION(kHistogramShown, global_position, |
| 183 kMaxSuggestionsTotal); | 202 kMaxSuggestionsTotal); |
| 184 LogCategoryHistogramEnumeration(kHistogramShown, category, category_position, | 203 LogCategoryHistogramEnumeration(kHistogramShown, category, category_position, |
| 185 kMaxSuggestionsPerCategory); | 204 kMaxSuggestionsPerCategory); |
| 186 | 205 |
| 187 base::TimeDelta age = base::Time::Now() - publish_date; | 206 base::TimeDelta age = base::Time::Now() - publish_date; |
| 188 LogCategoryHistogramAge(kHistogramShownAge, category, age); | 207 LogCategoryHistogramAge(kHistogramShownAge, category, age); |
| 189 | 208 |
| 190 LogCategoryHistogramScore(kHistogramShownScore, category, score); | 209 LogCategoryHistogramScore(kHistogramShownScore, category, score); |
| 210 |
| 211 // When the first of the articles suggestions is shown, then we count this as |
| 212 // a single usage of content suggestions. |
| 213 if (category.IsKnownCategory(KnownCategories::ARTICLES) && |
| 214 category_position == 0) { |
| 215 RecordContentSuggestionsUsage(); |
| 216 } |
| 191 } | 217 } |
| 192 | 218 |
| 193 void OnSuggestionOpened(int global_position, | 219 void OnSuggestionOpened(int global_position, |
| 194 Category category, | 220 Category category, |
| 195 int category_position, | 221 int category_position, |
| 196 base::Time publish_date, | 222 base::Time publish_date, |
| 197 float score, | 223 float score, |
| 198 WindowOpenDisposition disposition) { | 224 WindowOpenDisposition disposition) { |
| 199 UMA_HISTOGRAM_ENUMERATION(kHistogramOpened, global_position, | 225 UMA_HISTOGRAM_ENUMERATION(kHistogramOpened, global_position, |
| 200 kMaxSuggestionsTotal); | 226 kMaxSuggestionsTotal); |
| 201 LogCategoryHistogramEnumeration(kHistogramOpened, category, category_position, | 227 LogCategoryHistogramEnumeration(kHistogramOpened, category, category_position, |
| 202 kMaxSuggestionsPerCategory); | 228 kMaxSuggestionsPerCategory); |
| 203 | 229 |
| 204 base::TimeDelta age = base::Time::Now() - publish_date; | 230 base::TimeDelta age = base::Time::Now() - publish_date; |
| 205 LogCategoryHistogramAge(kHistogramOpenedAge, category, age); | 231 LogCategoryHistogramAge(kHistogramOpenedAge, category, age); |
| 206 | 232 |
| 207 LogCategoryHistogramScore(kHistogramOpenedScore, category, score); | 233 LogCategoryHistogramScore(kHistogramOpenedScore, category, score); |
| 208 | 234 |
| 209 UMA_HISTOGRAM_ENUMERATION( | 235 UMA_HISTOGRAM_ENUMERATION( |
| 210 kHistogramOpenDisposition, static_cast<int>(disposition), | 236 kHistogramOpenDisposition, static_cast<int>(disposition), |
| 211 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); | 237 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); |
| 212 LogCategoryHistogramEnumeration( | 238 LogCategoryHistogramEnumeration( |
| 213 kHistogramOpenDisposition, category, static_cast<int>(disposition), | 239 kHistogramOpenDisposition, category, static_cast<int>(disposition), |
| 214 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); | 240 static_cast<int>(WindowOpenDisposition::MAX_VALUE) + 1); |
| 241 |
| 242 if (category.IsKnownCategory(KnownCategories::ARTICLES)) { |
| 243 RecordContentSuggestionsUsage(); |
| 244 } |
| 215 } | 245 } |
| 216 | 246 |
| 217 void OnSuggestionMenuOpened(int global_position, | 247 void OnSuggestionMenuOpened(int global_position, |
| 218 Category category, | 248 Category category, |
| 219 int category_position, | 249 int category_position, |
| 220 base::Time publish_date, | 250 base::Time publish_date, |
| 221 float score) { | 251 float score) { |
| 222 UMA_HISTOGRAM_ENUMERATION(kHistogramMenuOpened, global_position, | 252 UMA_HISTOGRAM_ENUMERATION(kHistogramMenuOpened, global_position, |
| 223 kMaxSuggestionsTotal); | 253 kMaxSuggestionsTotal); |
| 224 LogCategoryHistogramEnumeration(kHistogramMenuOpened, category, | 254 LogCategoryHistogramEnumeration(kHistogramMenuOpened, category, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 293 |
| 264 void OnMoreButtonClicked(Category category, int position) { | 294 void OnMoreButtonClicked(Category category, int position) { |
| 265 // The "more" card can appear in addition to the actual suggestions, so add | 295 // The "more" card can appear in addition to the actual suggestions, so add |
| 266 // one extra bucket to this histogram. | 296 // one extra bucket to this histogram. |
| 267 LogCategoryHistogramEnumeration(kHistogramMoreButtonClicked, category, | 297 LogCategoryHistogramEnumeration(kHistogramMoreButtonClicked, category, |
| 268 position, kMaxSuggestionsPerCategory + 1); | 298 position, kMaxSuggestionsPerCategory + 1); |
| 269 } | 299 } |
| 270 | 300 |
| 271 } // namespace metrics | 301 } // namespace metrics |
| 272 } // namespace ntp_snippets | 302 } // namespace ntp_snippets |
| OLD | NEW |