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_tiles/metrics.h" | 5 #include "components/ntp_tiles/metrics.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
11 #include "base/metrics/sparse_histogram.h" | 11 #include "base/metrics/sparse_histogram.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "components/rappor/public/rappor_utils.h" | 13 #include "components/rappor/public/rappor_utils.h" |
14 | 14 |
15 namespace ntp_tiles { | 15 namespace ntp_tiles { |
16 namespace metrics { | 16 namespace metrics { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // Maximum number of tiles to record in histograms. | 20 // Maximum number of tiles to record in histograms. |
21 const int kMaxNumTiles = 12; | 21 const int kMaxNumTiles = 12; |
22 | 22 |
23 // Identifiers for the various tile sources. | 23 // Identifiers for the various tile sources. |
24 const char kHistogramClientName[] = "client"; | 24 const char kHistogramClientName[] = "client"; |
25 const char kHistogramServerName[] = "server"; | 25 const char kHistogramServerName[] = "server"; |
26 const char kHistogramPopularName[] = "popular"; | 26 const char kHistogramPopularName[] = "popular"; |
27 const char kHistogramWhitelistName[] = "whitelist"; | 27 const char kHistogramWhitelistName[] = "whitelist"; |
28 | 28 |
29 // Prefixes for the various icon types. | |
Marc Treib
2017/02/03 15:03:31
nit: Suffixes
mastiz
2017/02/06 10:59:49
Done.
| |
30 const char kIconTypeSuffixColor[] = "Color"; | |
31 const char kIconTypeSuffixGray[] = "Gray"; | |
32 const char kIconTypeSuffixReal[] = "Real"; | |
33 | |
29 // Log an event for a given |histogram| at a given element |position|. This | 34 // Log an event for a given |histogram| at a given element |position|. This |
30 // routine exists because regular histogram macros are cached thus can't be used | 35 // routine exists because regular histogram macros are cached thus can't be used |
31 // if the name of the histogram will change at a given call site. | 36 // if the name of the histogram will change at a given call site. |
32 void LogHistogramEvent(const std::string& histogram, | 37 void LogHistogramEvent(const std::string& histogram, |
33 int position, | 38 int position, |
34 int num_sites) { | 39 int num_sites) { |
35 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( | 40 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
36 histogram, 1, num_sites, num_sites + 1, | 41 histogram, 1, num_sites, num_sites + 1, |
37 base::Histogram::kUmaTargetedHistogramFlag); | 42 base::Histogram::kUmaTargetedHistogramFlag); |
38 if (counter) | 43 if (counter) |
39 counter->Add(position); | 44 counter->Add(position); |
40 } | 45 } |
41 | 46 |
42 std::string GetSourceHistogramName(NTPTileSource source) { | 47 std::string GetSourceHistogramName(NTPTileSource source) { |
43 switch (source) { | 48 switch (source) { |
44 case NTPTileSource::TOP_SITES: | 49 case NTPTileSource::TOP_SITES: |
45 return kHistogramClientName; | 50 return kHistogramClientName; |
46 case NTPTileSource::POPULAR: | 51 case NTPTileSource::POPULAR: |
47 return kHistogramPopularName; | 52 return kHistogramPopularName; |
48 case NTPTileSource::WHITELIST: | 53 case NTPTileSource::WHITELIST: |
49 return kHistogramWhitelistName; | 54 return kHistogramWhitelistName; |
50 case NTPTileSource::SUGGESTIONS_SERVICE: | 55 case NTPTileSource::SUGGESTIONS_SERVICE: |
51 return kHistogramServerName; | 56 return kHistogramServerName; |
52 } | 57 } |
53 NOTREACHED(); | 58 NOTREACHED(); |
54 return std::string(); | 59 return std::string(); |
55 } | 60 } |
56 | 61 |
62 const char* GetIconTypeSuffix(MostVisitedTileType type) { | |
63 switch (type) { | |
64 case ICON_COLOR: | |
65 return kIconTypeSuffixColor; | |
66 case ICON_DEFAULT: | |
67 return kIconTypeSuffixGray; | |
68 case ICON_REAL: | |
69 return kIconTypeSuffixReal; | |
70 case NONE: // Fall through. | |
71 case NUM_RECORDED_TILE_TYPES: // Fall through. | |
72 case THUMBNAIL: // Fall through. | |
73 case UNKNOWN_TILE_TYPE: | |
74 break; | |
75 } | |
76 return nullptr; | |
77 } | |
78 | |
57 } // namespace | 79 } // namespace |
58 | 80 |
59 void RecordPageImpression(const std::vector<TileImpression>& tiles, | 81 void RecordPageImpression(const std::vector<TileImpression>& tiles, |
60 rappor::RapporService* rappor_service) { | 82 rappor::RapporService* rappor_service) { |
61 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.NumberOfTiles", tiles.size()); | 83 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.NumberOfTiles", tiles.size()); |
62 | 84 |
63 int counts_per_type[NUM_RECORDED_TILE_TYPES] = {0}; | 85 int counts_per_type[NUM_RECORDED_TILE_TYPES] = {0}; |
64 bool have_tile_types = false; | 86 bool have_tile_types = false; |
65 for (int index = 0; index < static_cast<int>(tiles.size()); index++) { | 87 for (int index = 0; index < static_cast<int>(tiles.size()); index++) { |
66 NTPTileSource source = tiles[index].source; | 88 NTPTileSource source = tiles[index].source; |
(...skipping 15 matching lines...) Expand all Loading... | |
82 have_tile_types = true; | 104 have_tile_types = true; |
83 ++counts_per_type[tile_type]; | 105 ++counts_per_type[tile_type]; |
84 | 106 |
85 UMA_HISTOGRAM_ENUMERATION("NewTabPage.TileType", tile_type, | 107 UMA_HISTOGRAM_ENUMERATION("NewTabPage.TileType", tile_type, |
86 NUM_RECORDED_TILE_TYPES); | 108 NUM_RECORDED_TILE_TYPES); |
87 | 109 |
88 std::string tile_type_histogram = | 110 std::string tile_type_histogram = |
89 base::StringPrintf("NewTabPage.TileType.%s", source_name.c_str()); | 111 base::StringPrintf("NewTabPage.TileType.%s", source_name.c_str()); |
90 LogHistogramEvent(tile_type_histogram, tile_type, NUM_RECORDED_TILE_TYPES); | 112 LogHistogramEvent(tile_type_histogram, tile_type, NUM_RECORDED_TILE_TYPES); |
91 | 113 |
92 switch (tile_type) { | 114 const char* icon_type_suffix = GetIconTypeSuffix(tile_type); |
93 case NONE: | 115 if (icon_type_suffix) { |
94 break; | 116 rappor::SampleDomainAndRegistryFromGURL( |
95 case ICON_COLOR: | 117 rappor_service, |
96 rappor::SampleDomainAndRegistryFromGURL( | 118 base::StringPrintf("NTP.SuggestionsImpressions.Icons%s", |
97 rappor_service, "NTP.SuggestionsImpressions.IconsColor", url); | 119 icon_type_suffix), |
98 break; | 120 url); |
99 case ICON_DEFAULT: | 121 |
100 rappor::SampleDomainAndRegistryFromGURL( | 122 std::string icon_impression_histogram = base::StringPrintf( |
101 rappor_service, "NTP.SuggestionsImpressions.IconsGray", url); | 123 "NewTabPage.SuggestionsImpressionIcon.%s", icon_type_suffix); |
Marc Treib
2017/02/03 15:03:31
Hrm, somehow all our metrics use different naming
mastiz
2017/02/06 10:59:49
Acknowledged.
| |
102 break; | 124 LogHistogramEvent(icon_impression_histogram, index, kMaxNumTiles); |
103 case ICON_REAL: | |
104 rappor::SampleDomainAndRegistryFromGURL( | |
105 rappor_service, "NTP.SuggestionsImpressions.IconsReal", url); | |
106 break; | |
107 case NUM_RECORDED_TILE_TYPES: // Fall through. | |
108 case THUMBNAIL: // Fall through. | |
109 case UNKNOWN_TILE_TYPE: | |
110 NOTREACHED(); | |
111 } | 125 } |
112 } | 126 } |
113 | 127 |
114 if (have_tile_types) { | 128 if (have_tile_types) { |
115 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsReal", | 129 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsReal", |
116 counts_per_type[ICON_REAL]); | 130 counts_per_type[ICON_REAL]); |
117 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsColor", | 131 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsColor", |
118 counts_per_type[ICON_COLOR]); | 132 counts_per_type[ICON_COLOR]); |
119 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsGray", | 133 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsGray", |
120 counts_per_type[ICON_DEFAULT]); | 134 counts_per_type[ICON_DEFAULT]); |
121 } | 135 } |
122 } | 136 } |
123 | 137 |
124 void RecordTileClick(int index, | 138 void RecordTileClick(int index, |
125 NTPTileSource source, | 139 NTPTileSource source, |
126 MostVisitedTileType tile_type) { | 140 MostVisitedTileType tile_type) { |
127 UMA_HISTOGRAM_ENUMERATION("NewTabPage.MostVisited", index, kMaxNumTiles); | 141 UMA_HISTOGRAM_ENUMERATION("NewTabPage.MostVisited", index, kMaxNumTiles); |
128 | 142 |
129 std::string histogram = base::StringPrintf( | 143 std::string histogram = base::StringPrintf( |
130 "NewTabPage.MostVisited.%s", GetSourceHistogramName(source).c_str()); | 144 "NewTabPage.MostVisited.%s", GetSourceHistogramName(source).c_str()); |
131 LogHistogramEvent(histogram, index, kMaxNumTiles); | 145 LogHistogramEvent(histogram, index, kMaxNumTiles); |
132 | 146 |
147 const char* icon_type_suffix = GetIconTypeSuffix(tile_type); | |
148 if (icon_type_suffix) { | |
149 std::string icon_histogram = base::StringPrintf( | |
150 "NewTabPage.MostVisitedClickIcon.%s", icon_type_suffix); | |
Marc Treib
2017/02/03 15:03:31
Just MostVisitedIcon, to be slightly more consiste
mastiz
2017/02/06 10:59:49
Unless you feel strongly, I'd really like to put C
Marc Treib
2017/02/06 11:09:54
Eh.. I tend to value consistency over accuracy, bu
mastiz
2017/02/07 08:27:41
Thanks, I'll then stick to having Clicks in the na
| |
151 LogHistogramEvent(icon_histogram, index, kMaxNumTiles); | |
152 } | |
153 | |
133 if (tile_type < NUM_RECORDED_TILE_TYPES) { | 154 if (tile_type < NUM_RECORDED_TILE_TYPES) { |
134 UMA_HISTOGRAM_ENUMERATION("NewTabPage.TileTypeClicked", tile_type, | 155 UMA_HISTOGRAM_ENUMERATION("NewTabPage.TileTypeClicked", tile_type, |
135 NUM_RECORDED_TILE_TYPES); | 156 NUM_RECORDED_TILE_TYPES); |
136 | 157 |
137 std::string histogram = | 158 std::string histogram = |
138 base::StringPrintf("NewTabPage.TileTypeClicked.%s", | 159 base::StringPrintf("NewTabPage.TileTypeClicked.%s", |
139 GetSourceHistogramName(source).c_str()); | 160 GetSourceHistogramName(source).c_str()); |
140 LogHistogramEvent(histogram, tile_type, NUM_RECORDED_TILE_TYPES); | 161 LogHistogramEvent(histogram, tile_type, NUM_RECORDED_TILE_TYPES); |
141 } | 162 } |
142 } | 163 } |
143 | 164 |
144 } // namespace metrics | 165 } // namespace metrics |
145 } // namespace ntp_tiles | 166 } // namespace ntp_tiles |
OLD | NEW |