OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" | 5 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/search/most_visited_iframe_source.h" | 10 #include "chrome/browser/search/most_visited_iframe_source.h" |
11 #include "chrome/browser/search/search.h" | 11 #include "chrome/browser/search/search.h" |
12 #include "chrome/common/search_urls.h" | 12 #include "chrome/common/search_urls.h" |
13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
14 #include "content/public/browser/navigation_details.h" | 14 #include "content/public/browser/navigation_details.h" |
15 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 | 17 |
| 18 // Macro to log UMA statistics related to the 8 tiles shown on the NTP. |
| 19 #define UMA_HISTOGRAM_NTP_TILES(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ |
| 20 name, sample, 0, 8, 9) |
| 21 |
18 namespace { | 22 namespace { |
19 | 23 |
20 // Used to track if suggestions were issued by the client or the server. | 24 // Used to track if suggestions were issued by the client or the server. |
21 enum SuggestionsType { | 25 enum SuggestionsType { |
22 CLIENT_SIDE = 0, | 26 CLIENT_SIDE = 0, |
23 SERVER_SIDE = 1, | 27 SERVER_SIDE = 1, |
24 SUGGESTIONS_TYPE_COUNT = 2 | 28 SUGGESTIONS_TYPE_COUNT = 2 |
25 }; | 29 }; |
26 | 30 |
27 // Format string to generate the name for the histogram keeping track of | 31 // Format string to generate the name for the histogram keeping track of |
(...skipping 19 matching lines...) Expand all Loading... |
47 // originate from it. We use the NavigationController's URL since it might | 51 // originate from it. We use the NavigationController's URL since it might |
48 // differ from the WebContents URL which is usually chrome://newtab/. | 52 // differ from the WebContents URL which is usually chrome://newtab/. |
49 const content::NavigationEntry* entry = | 53 const content::NavigationEntry* entry = |
50 content->GetController().GetVisibleEntry(); | 54 content->GetController().GetVisibleEntry(); |
51 if (entry) | 55 if (entry) |
52 logger->ntp_url_ = entry->GetURL(); | 56 logger->ntp_url_ = entry->GetURL(); |
53 | 57 |
54 return logger; | 58 return logger; |
55 } | 59 } |
56 | 60 |
57 void NTPUserDataLogger::EmitThumbnailErrorRate() { | |
58 DCHECK_LE(number_of_thumbnail_errors_, number_of_thumbnail_attempts_); | |
59 if (number_of_thumbnail_attempts_ != 0) { | |
60 UMA_HISTOGRAM_PERCENTAGE( | |
61 "NewTabPage.ThumbnailErrorRate", | |
62 GetPercentError(number_of_thumbnail_errors_, | |
63 number_of_thumbnail_attempts_)); | |
64 } | |
65 DCHECK_LE(number_of_fallback_thumbnails_used_, | |
66 number_of_fallback_thumbnails_requested_); | |
67 if (number_of_fallback_thumbnails_requested_ != 0) { | |
68 UMA_HISTOGRAM_PERCENTAGE( | |
69 "NewTabPage.ThumbnailFallbackRate", | |
70 GetPercentError(number_of_fallback_thumbnails_used_, | |
71 number_of_fallback_thumbnails_requested_)); | |
72 } | |
73 number_of_thumbnail_attempts_ = 0; | |
74 number_of_thumbnail_errors_ = 0; | |
75 number_of_fallback_thumbnails_requested_ = 0; | |
76 number_of_fallback_thumbnails_used_ = 0; | |
77 } | |
78 | |
79 void NTPUserDataLogger::EmitNtpStatistics() { | 61 void NTPUserDataLogger::EmitNtpStatistics() { |
80 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers", number_of_mouseovers_); | 62 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers", number_of_mouseovers_); |
81 number_of_mouseovers_ = 0; | 63 number_of_mouseovers_ = 0; |
82 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfExternalTiles", | 64 |
83 number_of_external_tiles_); | 65 // Only log the following statistics if at least one tile is recorded. This |
84 number_of_external_tiles_ = 0; | 66 // check is required because the statistics are emitted whenever the user |
85 UMA_HISTOGRAM_ENUMERATION( | 67 // changes tab away from the NTP. However, if the user comes back to that NTP |
86 "NewTabPage.SuggestionsType", | 68 // later the statistics are not regenerated (i.e. they are all 0). If we log |
87 server_side_suggestions_ ? SERVER_SIDE : CLIENT_SIDE, | 69 // them again we get a strong bias. |
88 SUGGESTIONS_TYPE_COUNT); | 70 if (number_of_tiles_ > 0) { |
89 server_side_suggestions_ = false; | 71 UMA_HISTOGRAM_ENUMERATION( |
| 72 "NewTabPage.SuggestionsType", |
| 73 server_side_suggestions_ ? SERVER_SIDE : CLIENT_SIDE, |
| 74 SUGGESTIONS_TYPE_COUNT); |
| 75 server_side_suggestions_ = false; |
| 76 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfTiles", number_of_tiles_); |
| 77 number_of_tiles_ = 0; |
| 78 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfThumbnailTiles", |
| 79 number_of_thumbnail_tiles_); |
| 80 number_of_thumbnail_tiles_ = 0; |
| 81 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfGrayTiles", |
| 82 number_of_gray_tiles_); |
| 83 number_of_gray_tiles_ = 0; |
| 84 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfExternalTiles", |
| 85 number_of_external_tiles_); |
| 86 number_of_external_tiles_ = 0; |
| 87 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfThumbnailErrors", |
| 88 number_of_thumbnail_errors_); |
| 89 number_of_thumbnail_errors_ = 0; |
| 90 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfGrayTileFallbacks", |
| 91 number_of_gray_tile_fallbacks_); |
| 92 number_of_gray_tile_fallbacks_ = 0; |
| 93 UMA_HISTOGRAM_NTP_TILES("NewTabPage.NumberOfExternalTileFallbacks", |
| 94 number_of_external_tile_fallbacks_); |
| 95 number_of_external_tile_fallbacks_ = 0; |
| 96 } |
90 } | 97 } |
91 | 98 |
92 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event) { | 99 void NTPUserDataLogger::LogEvent(NTPLoggingEventType event) { |
93 switch (event) { | 100 switch (event) { |
94 case NTP_MOUSEOVER: | |
95 number_of_mouseovers_++; | |
96 break; | |
97 case NTP_THUMBNAIL_ATTEMPT: | |
98 number_of_thumbnail_attempts_++; | |
99 break; | |
100 case NTP_THUMBNAIL_ERROR: | |
101 number_of_thumbnail_errors_++; | |
102 break; | |
103 case NTP_FALLBACK_THUMBNAIL_REQUESTED: | |
104 number_of_fallback_thumbnails_requested_++; | |
105 break; | |
106 case NTP_FALLBACK_THUMBNAIL_USED: | |
107 number_of_fallback_thumbnails_used_++; | |
108 break; | |
109 case NTP_SERVER_SIDE_SUGGESTION: | 101 case NTP_SERVER_SIDE_SUGGESTION: |
110 server_side_suggestions_ = true; | 102 server_side_suggestions_ = true; |
111 break; | 103 break; |
112 case NTP_CLIENT_SIDE_SUGGESTION: | 104 case NTP_CLIENT_SIDE_SUGGESTION: |
113 // We should never get a mix of server and client side suggestions, | 105 // We should never get a mix of server and client side suggestions, |
114 // otherwise there could be a race condition depending on the order in | 106 // otherwise there could be a race condition depending on the order in |
115 // which the iframes call this method. | 107 // which the iframes call this method. |
116 DCHECK(!server_side_suggestions_); | 108 DCHECK(!server_side_suggestions_); |
117 break; | 109 break; |
| 110 case NTP_TILE: |
| 111 number_of_tiles_++; |
| 112 break; |
| 113 case NTP_THUMBNAIL_TILE: |
| 114 number_of_thumbnail_tiles_++; |
| 115 break; |
| 116 case NTP_GRAY_TILE: |
| 117 number_of_gray_tiles_++; |
| 118 break; |
118 case NTP_EXTERNAL_TILE: | 119 case NTP_EXTERNAL_TILE: |
119 number_of_external_tiles_++; | 120 number_of_external_tiles_++; |
120 break; | 121 break; |
| 122 case NTP_THUMBNAIL_ERROR: |
| 123 number_of_thumbnail_errors_++; |
| 124 break; |
| 125 case NTP_GRAY_TILE_FALLBACK: |
| 126 number_of_gray_tile_fallbacks_++; |
| 127 break; |
| 128 case NTP_EXTERNAL_TILE_FALLBACK: |
| 129 number_of_external_tile_fallbacks_++; |
| 130 break; |
| 131 case NTP_MOUSEOVER: |
| 132 number_of_mouseovers_++; |
| 133 break; |
121 default: | 134 default: |
122 NOTREACHED(); | 135 NOTREACHED(); |
123 } | 136 } |
124 } | 137 } |
125 | 138 |
126 void NTPUserDataLogger::LogImpression(int position, | 139 void NTPUserDataLogger::LogImpression(int position, |
127 const base::string16& provider) { | 140 const base::string16& provider) { |
128 // Cannot rely on UMA histograms macro because the name of the histogram is | 141 // Cannot rely on UMA histograms macro because the name of the histogram is |
129 // generated dynamically. | 142 // generated dynamically. |
130 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( | 143 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
131 base::StringPrintf(kImpressionHistogramWithProvider, | 144 base::StringPrintf(kImpressionHistogramWithProvider, |
132 base::UTF16ToUTF8(provider).c_str()), | 145 base::UTF16ToUTF8(provider).c_str()), |
133 1, MostVisitedIframeSource::kNumMostVisited, | 146 1, MostVisitedIframeSource::kNumMostVisited, |
134 MostVisitedIframeSource::kNumMostVisited + 1, | 147 MostVisitedIframeSource::kNumMostVisited + 1, |
135 base::Histogram::kUmaTargetedHistogramFlag); | 148 base::Histogram::kUmaTargetedHistogramFlag); |
136 counter->Add(position); | 149 counter->Add(position); |
137 } | 150 } |
138 | 151 |
139 // content::WebContentsObserver override | 152 // content::WebContentsObserver override |
140 void NTPUserDataLogger::NavigationEntryCommitted( | 153 void NTPUserDataLogger::NavigationEntryCommitted( |
141 const content::LoadCommittedDetails& load_details) { | 154 const content::LoadCommittedDetails& load_details) { |
142 if (!load_details.previous_url.is_valid()) | 155 if (!load_details.previous_url.is_valid()) |
143 return; | 156 return; |
144 | 157 |
145 if (search::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) { | 158 if (search::MatchesOriginAndPath(ntp_url_, load_details.previous_url)) { |
146 EmitNtpStatistics(); | 159 EmitNtpStatistics(); |
147 // Only log thumbnail error rates for Instant NTP pages, as we do not have | |
148 // this data for non-Instant NTPs. | |
149 if (ntp_url_ != GURL(chrome::kChromeUINewTabURL)) | |
150 EmitThumbnailErrorRate(); | |
151 } | 160 } |
152 } | 161 } |
153 | 162 |
154 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) | 163 NTPUserDataLogger::NTPUserDataLogger(content::WebContents* contents) |
155 : content::WebContentsObserver(contents), | 164 : content::WebContentsObserver(contents), |
156 number_of_mouseovers_(0), | 165 server_side_suggestions_(false), |
157 number_of_thumbnail_attempts_(0), | 166 number_of_tiles_(0), |
| 167 number_of_thumbnail_tiles_(0), |
| 168 number_of_gray_tiles_(0), |
| 169 number_of_external_tiles_(0), |
158 number_of_thumbnail_errors_(0), | 170 number_of_thumbnail_errors_(0), |
159 number_of_fallback_thumbnails_requested_(0), | 171 number_of_gray_tile_fallbacks_(0), |
160 number_of_fallback_thumbnails_used_(0), | 172 number_of_external_tile_fallbacks_(0), |
161 number_of_external_tiles_(0), | 173 number_of_mouseovers_(0) { |
162 server_side_suggestions_(false) { | |
163 } | 174 } |
164 | |
165 size_t NTPUserDataLogger::GetPercentError(size_t errors, size_t events) const { | |
166 return (100 * errors) / events; | |
167 } | |
OLD | NEW |