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

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

Issue 2557513007: ntp_tiles::metrics: Add rappor metrics for impression URLs per icon type. (Closed)
Patch Set: Fix build. Created 4 years 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
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 14
14 namespace ntp_tiles { 15 namespace ntp_tiles {
15 namespace metrics { 16 namespace metrics {
16 17
17 namespace { 18 namespace {
18 19
19 // Maximum number of tiles to record in histograms. 20 // Maximum number of tiles to record in histograms.
20 const int kMaxNumTiles = 12; 21 const int kMaxNumTiles = 12;
21 22
22 // Identifiers for the various tile sources. 23 // Identifiers for the various tile sources.
(...skipping 25 matching lines...) Expand all
48 return kHistogramWhitelistName; 49 return kHistogramWhitelistName;
49 case NTPTileSource::SUGGESTIONS_SERVICE: 50 case NTPTileSource::SUGGESTIONS_SERVICE:
50 return kHistogramServerName; 51 return kHistogramServerName;
51 } 52 }
52 NOTREACHED(); 53 NOTREACHED();
53 return std::string(); 54 return std::string();
54 } 55 }
55 56
56 } // namespace 57 } // namespace
57 58
58 void RecordPageImpression( 59 void RecordPageImpression(const std::vector<TileImpression>& tiles,
59 const std::vector<std::pair<NTPTileSource, MostVisitedTileType>>& tiles) { 60 rappor::RapporService* rappor_service) {
60 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.NumberOfTiles", tiles.size()); 61 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.NumberOfTiles", tiles.size());
61 62
62 int counts_per_type[NUM_RECORDED_TILE_TYPES] = {0}; 63 int counts_per_type[NUM_RECORDED_TILE_TYPES] = {0};
63 bool have_tile_types = false; 64 bool have_tile_types = false;
64 for (int index = 0; index < static_cast<int>(tiles.size()); index++) { 65 for (int index = 0; index < static_cast<int>(tiles.size()); index++) {
65 NTPTileSource source = tiles[index].first; 66 NTPTileSource source = tiles[index].source;
66 MostVisitedTileType tile_type = tiles[index].second; 67 MostVisitedTileType tile_type = tiles[index].type;
68 const GURL& url = tiles[index].url;
67 69
68 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SuggestionsImpression", index, 70 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SuggestionsImpression", index,
69 kMaxNumTiles); 71 kMaxNumTiles);
70 72
71 std::string source_name = GetSourceHistogramName(source); 73 std::string source_name = GetSourceHistogramName(source);
72 std::string impression_histogram = base::StringPrintf( 74 std::string impression_histogram = base::StringPrintf(
73 "NewTabPage.SuggestionsImpression.%s", source_name.c_str()); 75 "NewTabPage.SuggestionsImpression.%s", source_name.c_str());
74 LogHistogramEvent(impression_histogram, index, kMaxNumTiles); 76 LogHistogramEvent(impression_histogram, index, kMaxNumTiles);
75 77
76 if (tile_type >= NUM_RECORDED_TILE_TYPES) { 78 if (tile_type >= NUM_RECORDED_TILE_TYPES) {
77 continue; 79 continue;
78 } 80 }
79 81
80 have_tile_types = true; 82 have_tile_types = true;
81 ++counts_per_type[tile_type]; 83 ++counts_per_type[tile_type];
82 84
83 UMA_HISTOGRAM_ENUMERATION("NewTabPage.TileType", tile_type, 85 UMA_HISTOGRAM_ENUMERATION("NewTabPage.TileType", tile_type,
84 NUM_RECORDED_TILE_TYPES); 86 NUM_RECORDED_TILE_TYPES);
85 87
86 std::string tile_type_histogram = 88 std::string tile_type_histogram =
87 base::StringPrintf("NewTabPage.TileType.%s", source_name.c_str()); 89 base::StringPrintf("NewTabPage.TileType.%s", source_name.c_str());
88 LogHistogramEvent(tile_type_histogram, tile_type, NUM_RECORDED_TILE_TYPES); 90 LogHistogramEvent(tile_type_histogram, tile_type, NUM_RECORDED_TILE_TYPES);
91
92 switch (tile_type) {
93 case ICON_COLOR:
94 rappor::SampleDomainAndRegistryFromGURL(
95 rappor_service, "NTP.SuggestionsImpressions.IconsColor", url);
Marc Treib 2016/12/08 12:58:22 It's a bit unfortunate that these use a different
mastiz 2016/12/08 13:47:07 Acknowledged, that was my rationale, although I do
96 break;
97 case ICON_DEFAULT:
98 rappor::SampleDomainAndRegistryFromGURL(
99 rappor_service, "NTP.SuggestionsImpressions.IconsGray", url);
100 break;
101 case ICON_REAL:
102 rappor::SampleDomainAndRegistryFromGURL(
103 rappor_service, "NTP.SuggestionsImpressions.IconsReal", url);
104 break;
105 default:
Marc Treib 2016/12/08 12:58:22 Explicitly list the uninteresting cases? Then we'l
mastiz 2016/12/08 13:47:07 Done.
106 break;
107 }
89 } 108 }
90 109
91 if (have_tile_types) { 110 if (have_tile_types) {
92 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsReal", 111 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsReal",
93 counts_per_type[ICON_REAL]); 112 counts_per_type[ICON_REAL]);
94 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsColor", 113 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsColor",
95 counts_per_type[ICON_COLOR]); 114 counts_per_type[ICON_COLOR]);
96 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsGray", 115 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsGray",
97 counts_per_type[ICON_DEFAULT]); 116 counts_per_type[ICON_DEFAULT]);
98 } 117 }
(...skipping 14 matching lines...) Expand all
113 132
114 std::string histogram = 133 std::string histogram =
115 base::StringPrintf("NewTabPage.TileTypeClicked.%s", 134 base::StringPrintf("NewTabPage.TileTypeClicked.%s",
116 GetSourceHistogramName(source).c_str()); 135 GetSourceHistogramName(source).c_str());
117 LogHistogramEvent(histogram, tile_type, NUM_RECORDED_TILE_TYPES); 136 LogHistogramEvent(histogram, tile_type, NUM_RECORDED_TILE_TYPES);
118 } 137 }
119 } 138 }
120 139
121 } // namespace metrics 140 } // namespace metrics
122 } // namespace ntp_tiles 141 } // namespace ntp_tiles
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698