1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/ntp_tiles/metrics.h"
#include <string>
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/notreached.h"
#include "base/strings/stringprintf.h"
#include "components/ntp_tiles/constants.h"
namespace ntp_tiles {
namespace metrics {
namespace {
const int kLastTitleSource = static_cast<int>(TileTitleSource::LAST);
// Identifiers for the various tile sources. Should sync with
// NewTabPageProviders in histogram_suffixes_list.xml.
const char kHistogramClientName[] = "client";
const char kHistogramPopularName[] = "popular_fetched";
const char kHistogramBakedInName[] = "popular_baked_in";
const char kHistogramAllowlistName[] = "allowlist";
const char kHistogramHomepageName[] = "homepage";
const char kHistogramCustomLinksName[] = "custom_links";
// Suffixes for the various icon types.
const char kTileTypeSuffixIconColor[] = "IconsColor";
const char kTileTypeSuffixIconGray[] = "IconsGray";
const char kTileTypeSuffixIconReal[] = "IconsReal";
std::string GetSourceHistogramName(TileSource source) {
switch (source) {
case TileSource::TOP_SITES:
return kHistogramClientName;
case TileSource::POPULAR_BAKED_IN:
return kHistogramBakedInName;
case TileSource::POPULAR:
return kHistogramPopularName;
case TileSource::ALLOWLIST:
return kHistogramAllowlistName;
case TileSource::HOMEPAGE:
return kHistogramHomepageName;
case TileSource::CUSTOM_LINKS:
return kHistogramCustomLinksName;
}
NOTREACHED();
}
const char* GetTileTypeSuffix(TileVisualType type) {
switch (type) {
case TileVisualType::ICON_COLOR:
return kTileTypeSuffixIconColor;
case TileVisualType::ICON_DEFAULT:
return kTileTypeSuffixIconGray;
case TileVisualType::ICON_REAL:
return kTileTypeSuffixIconReal;
case TileVisualType::NONE: // Fall through.
case TileVisualType::UNKNOWN_TILE_TYPE:
break;
}
return nullptr;
}
} // namespace
void RecordPageImpression(int number_of_tiles) {
base::UmaHistogramSparse("NewTabPage.NumberOfTiles", number_of_tiles);
}
void RecordNumberOfCustomTilesOnFirstNtp(int number_of_custom_tiles) {
base::UmaHistogramSparse(
"NewTabPage.MostVisited.NumberOfCustomTilesOnFirstNtp",
number_of_custom_tiles);
}
void RecordTileImpression(const NTPTileImpression& impression) {
UMA_HISTOGRAM_ENUMERATION("NewTabPage.SuggestionsImpression",
impression.index, kMaxNumTiles);
std::string source_name = GetSourceHistogramName(impression.source);
base::UmaHistogramExactLinear(
base::StringPrintf("NewTabPage.SuggestionsImpression.%s",
source_name.c_str()),
impression.index, kMaxNumTiles);
UMA_HISTOGRAM_ENUMERATION("NewTabPage.TileTitle",
static_cast<int>(impression.title_source),
kLastTitleSource + 1);
base::UmaHistogramExactLinear(
base::StringPrintf("NewTabPage.TileTitle.%s",
GetSourceHistogramName(impression.source).c_str()),
static_cast<int>(impression.title_source), kLastTitleSource + 1);
if (impression.visual_type > LAST_RECORDED_TILE_TYPE) {
return;
}
UMA_HISTOGRAM_ENUMERATION("NewTabPage.TileType", impression.visual_type,
LAST_RECORDED_TILE_TYPE + 1);
base::UmaHistogramExactLinear(
base::StringPrintf("NewTabPage.TileType.%s", source_name.c_str()),
impression.visual_type, LAST_RECORDED_TILE_TYPE + 1);
const char* tile_type_suffix = GetTileTypeSuffix(impression.visual_type);
if (tile_type_suffix) {
// TODO(http://crbug.com/1021598): Add UKM here.
base::UmaHistogramExactLinear(
base::StringPrintf("NewTabPage.SuggestionsImpression.%s",
tile_type_suffix),
impression.index, kMaxNumTiles);
}
}
void RecordTileClick(const NTPTileImpression& impression) {
UMA_HISTOGRAM_ENUMERATION("NewTabPage.MostVisited", impression.index,
kMaxNumTiles);
base::RecordAction(base::UserMetricsAction("NewTabPage.MostVisited.Clicked"));
std::string source_name = GetSourceHistogramName(impression.source);
base::UmaHistogramExactLinear(
base::StringPrintf("NewTabPage.MostVisited.%s", source_name.c_str()),
impression.index, kMaxNumTiles);
const char* tile_type_suffix = GetTileTypeSuffix(impression.visual_type);
if (tile_type_suffix) {
base::UmaHistogramExactLinear(
base::StringPrintf("NewTabPage.MostVisited.%s", tile_type_suffix),
impression.index, kMaxNumTiles);
}
UMA_HISTOGRAM_ENUMERATION("NewTabPage.TileTitleClicked",
static_cast<int>(impression.title_source),
kLastTitleSource + 1);
base::UmaHistogramExactLinear(
base::StringPrintf("NewTabPage.TileTitleClicked.%s",
GetSourceHistogramName(impression.source).c_str()),
static_cast<int>(impression.title_source), kLastTitleSource + 1);
if (impression.visual_type <= LAST_RECORDED_TILE_TYPE) {
UMA_HISTOGRAM_ENUMERATION("NewTabPage.TileTypeClicked",
impression.visual_type,
LAST_RECORDED_TILE_TYPE + 1);
base::UmaHistogramExactLinear(
base::StringPrintf("NewTabPage.TileTypeClicked.%s",
GetSourceHistogramName(impression.source).c_str()),
impression.visual_type, LAST_RECORDED_TILE_TYPE + 1);
}
}
void RecordsMigratedDefaultAppDeleted(
const DeletedTileType& most_visited_app_type) {
base::UmaHistogramEnumeration("NewTabPage.MostVisitedMigratedDefaultAppType",
most_visited_app_type);
}
} // namespace metrics
} // namespace ntp_tiles
|