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

Side by Side Diff: components/ntp_tiles/metrics.cc

Issue 2671983002: ntp_tiles: Add UMA histograms to correlate icon type to position (Closed)
Patch Set: Adopted histogram suffixes. Created 3 years, 10 months 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/ntp_tiles/metrics_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Suffixes for the various icon types.
30 const char kIconTypeSuffixColor[] = "IconsColor";
31 const char kIconTypeSuffixGray[] = "IconsGray";
32 const char kIconTypeSuffixReal[] = "IconsReal";
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
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.%s", icon_type_suffix),
97 rappor_service, "NTP.SuggestionsImpressions.IconsColor", url); 119 url);
98 break; 120
99 case ICON_DEFAULT: 121 std::string icon_impression_histogram = base::StringPrintf(
100 rappor::SampleDomainAndRegistryFromGURL( 122 "NewTabPage.SuggestionsImpression.%s", icon_type_suffix);
101 rappor_service, "NTP.SuggestionsImpressions.IconsGray", url); 123 LogHistogramEvent(icon_impression_histogram, index, kMaxNumTiles);
102 break;
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 } 124 }
112 } 125 }
113 126
114 if (have_tile_types) { 127 if (have_tile_types) {
115 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsReal", 128 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsReal",
116 counts_per_type[ICON_REAL]); 129 counts_per_type[ICON_REAL]);
117 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsColor", 130 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsColor",
118 counts_per_type[ICON_COLOR]); 131 counts_per_type[ICON_COLOR]);
119 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsGray", 132 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsGray",
120 counts_per_type[ICON_DEFAULT]); 133 counts_per_type[ICON_DEFAULT]);
121 } 134 }
122 } 135 }
123 136
124 void RecordTileClick(int index, 137 void RecordTileClick(int index,
125 NTPTileSource source, 138 NTPTileSource source,
126 MostVisitedTileType tile_type) { 139 MostVisitedTileType tile_type) {
127 UMA_HISTOGRAM_ENUMERATION("NewTabPage.MostVisited", index, kMaxNumTiles); 140 UMA_HISTOGRAM_ENUMERATION("NewTabPage.MostVisited", index, kMaxNumTiles);
128 141
129 std::string histogram = base::StringPrintf( 142 std::string histogram = base::StringPrintf(
130 "NewTabPage.MostVisited.%s", GetSourceHistogramName(source).c_str()); 143 "NewTabPage.MostVisited.%s", GetSourceHistogramName(source).c_str());
131 LogHistogramEvent(histogram, index, kMaxNumTiles); 144 LogHistogramEvent(histogram, index, kMaxNumTiles);
132 145
146 const char* icon_type_suffix = GetIconTypeSuffix(tile_type);
147 if (icon_type_suffix) {
148 std::string icon_histogram =
149 base::StringPrintf("NewTabPage.MostVisited.%s", icon_type_suffix);
150 LogHistogramEvent(icon_histogram, index, kMaxNumTiles);
151 }
152
133 if (tile_type < NUM_RECORDED_TILE_TYPES) { 153 if (tile_type < NUM_RECORDED_TILE_TYPES) {
134 UMA_HISTOGRAM_ENUMERATION("NewTabPage.TileTypeClicked", tile_type, 154 UMA_HISTOGRAM_ENUMERATION("NewTabPage.TileTypeClicked", tile_type,
135 NUM_RECORDED_TILE_TYPES); 155 NUM_RECORDED_TILE_TYPES);
136 156
137 std::string histogram = 157 std::string histogram =
138 base::StringPrintf("NewTabPage.TileTypeClicked.%s", 158 base::StringPrintf("NewTabPage.TileTypeClicked.%s",
139 GetSourceHistogramName(source).c_str()); 159 GetSourceHistogramName(source).c_str());
140 LogHistogramEvent(histogram, tile_type, NUM_RECORDED_TILE_TYPES); 160 LogHistogramEvent(histogram, tile_type, NUM_RECORDED_TILE_TYPES);
141 } 161 }
142 } 162 }
143 163
144 } // namespace metrics 164 } // namespace metrics
145 } // namespace ntp_tiles 165 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « no previous file | components/ntp_tiles/metrics_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698