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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ash/app_list/search/search_metrics_manager.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "chrome/browser/ash/app_list/search/common/string_util.h"
#include "chrome/browser/ash/app_list/search/ranking/constants.h"
#include "chrome/browser/ash/app_list/search/search_features.h"
#include "chrome/browser/ash/app_list/search/search_metrics_util.h"
#include "chrome/browser/profiles/profile.h"
#include "components/drive/drive_pref_names.h"
#include "components/metrics/structured/structured_events.h"
#include "components/metrics/structured/structured_metrics_client.h"
#include "components/prefs/pref_service.h"
namespace app_list {
namespace {
using Result = ash::AppListNotifier::Result;
using Location = ash::AppListNotifier::Location;
using Action = SearchMetricsManager::Action;
std::string GetViewString(Location location, const std::u16string& raw_query) {
std::u16string query;
base::TrimWhitespace(raw_query, base::TRIM_ALL, &query);
switch (location) {
case Location::kList:
return query.empty() ? "ListZeroState" : "ListSearch";
case Location::kAnswerCard:
return "AnswerCard";
case Location::kRecentApps:
return "RecentApps";
case Location::kContinue:
return "Continue";
case Location::kImage:
return "Image";
default:
LogError(Error::kUntrackedLocation);
return "Untracked";
}
}
std::set<ash::SearchResultType> TypeSet(const std::vector<Result>& results) {
std::set<ash::SearchResultType> types;
for (const auto& result : results) {
types.insert(result.type);
}
return types;
}
std::set<ash::ContinueFileSuggestionType> ContinueFileTypeSet(
const std::vector<Result>& results) {
std::set<ash::ContinueFileSuggestionType> types;
for (const auto& result : results) {
if (result.continue_file_type) {
types.insert(*result.continue_file_type);
}
}
return types;
}
// Log an action on a set of search result types.
void LogTypeActions(const std::string& action_name,
Location location,
const std::u16string& query,
const std::set<ash::SearchResultType>& types) {
const std::string histogram_name = base::StrCat(
{kHistogramPrefix, GetViewString(location, query), ".", action_name});
for (auto type : types) {
if (type == ash::SEARCH_RESULT_TYPE_BOUNDARY) {
LogError(Error::kUntypedResult);
} else {
base::UmaHistogramEnumeration(histogram_name, type,
ash::SEARCH_RESULT_TYPE_BOUNDARY);
}
}
}
void LogContinueFileTypeActions(
const std::string& action_name,
Location location,
const std::set<ash::ContinueFileSuggestionType>& continue_file_types) {
if (location != Location::kContinue) {
return;
}
const std::string histogram_name = base::StrCat(
{kHistogramPrefix, "Continue.FileSuggestionType.", action_name});
for (auto type : continue_file_types) {
base::UmaHistogramEnumeration(histogram_name, type);
}
}
// Log an action for a search result view as a whole.
void LogViewAction(Location location,
const std::u16string& query,
Action action) {
const std::string histogram_name =
base::StrCat({kHistogramPrefix, GetViewString(location, query)});
base::UmaHistogramEnumeration(histogram_name, action);
}
void LogIsDriveEnabled(Profile* profile) {
// Logs false for disabled and true for enabled, corresponding to the
// BooleanEnabled enum.
base::UmaHistogramBoolean(
"Apps.AppList.ContinueIsDriveEnabled",
!profile->GetPrefs()->GetBoolean(drive::prefs::kDisableDrive));
}
void LogContinueMetrics(const std::vector<Result>& results) {
int drive_count = 0;
int local_count = 0;
int help_app_count = 0;
for (const auto& result : results) {
switch (result.type) {
case ash::SearchResultType::ZERO_STATE_DRIVE:
++drive_count;
break;
case ash::SearchResultType::ZERO_STATE_FILE:
++local_count;
break;
case ash::SearchResultType::HELP_APP_UPDATES:
++help_app_count;
break;
case ash::SearchResultType::DESKS_ADMIN_TEMPLATE:
break;
default:
NOTREACHED() << static_cast<int>(result.type);
}
}
base::UmaHistogramExactLinear("Apps.AppList.Search.ContinueResultCount.Total",
results.size(), 10);
base::UmaHistogramExactLinear("Apps.AppList.Search.ContinueResultCount.Drive",
drive_count, 10);
base::UmaHistogramExactLinear("Apps.AppList.Search.ContinueResultCount.Local",
local_count, 10);
base::UmaHistogramExactLinear(
"Apps.AppList.Search.ContinueResultCount.HelpApp", help_app_count, 10);
base::UmaHistogramBoolean("Apps.AppList.Search.DriveContinueResultsShown",
drive_count > 0);
}
} // namespace
SearchMetricsManager::SearchMetricsManager(Profile* profile,
ash::AppListNotifier* notifier) {
if (notifier) {
observation_.Observe(notifier);
} else {
LogError(Error::kMissingNotifier);
}
if (profile)
LogIsDriveEnabled(profile);
}
SearchMetricsManager::~SearchMetricsManager() = default;
void SearchMetricsManager::OnImpression(Location location,
const std::vector<Result>& results,
const std::u16string& query) {
LogTypeActions("Impression", location, query, TypeSet(results));
LogContinueFileTypeActions("Impression", location,
ContinueFileTypeSet(results));
if (!results.empty())
LogViewAction(location, query, Action::kImpression);
if (location == Location::kContinue)
LogContinueMetrics(results);
}
void SearchMetricsManager::OnAbandon(Location location,
const std::vector<Result>& results,
const std::u16string& query) {
LogTypeActions("Abandon", location, query, TypeSet(results));
LogContinueFileTypeActions("Abandon", location, ContinueFileTypeSet(results));
if (!results.empty())
LogViewAction(location, query, Action::kAbandon);
}
void SearchMetricsManager::OnLaunch(Location location,
const Result& launched,
const std::vector<Result>& shown,
const std::u16string& query) {
LogViewAction(location, query, Action::kLaunch);
// Record an ignore for all result types in this view. If other views are
// shown, they are handled by OnIgnore.
std::set<ash::SearchResultType> types;
for (const auto& result : shown) {
if (result.type != launched.type) {
types.insert(result.type);
}
}
std::set<ash::ContinueFileSuggestionType> continue_file_types;
for (const auto& result : shown) {
if (result.continue_file_type &&
result.continue_file_type != launched.continue_file_type) {
continue_file_types.insert(*result.continue_file_type);
}
}
LogTypeActions("Ignore", location, query, types);
LogContinueFileTypeActions("Ignore", location, continue_file_types);
LogTypeActions("Launch", location, query, {launched.type});
if (launched.continue_file_type) {
LogContinueFileTypeActions("Launch", location,
{*launched.continue_file_type});
}
// Record the launch index.
int launched_index = -1;
for (size_t i = 0; i < shown.size(); ++i) {
if (shown[i].id == launched.id) {
launched_index = base::checked_cast<int>(i);
break;
}
}
const std::string histogram_name = base::StrCat(
{kHistogramPrefix, GetViewString(location, query), ".LaunchIndex"});
base::UmaHistogramExactLinear(histogram_name, launched_index, 50);
}
void SearchMetricsManager::OnIgnore(Location location,
const std::vector<Result>& results,
const std::u16string& query) {
// We have no two concurrently displayed views showing the same result types,
// so it's safe to log an ignore for all result types here.
LogTypeActions("Ignore", location, query, TypeSet(results));
if (!results.empty())
LogViewAction(location, query, Action::kIgnore);
}
// Log the length of the last query that led to the clicked result - for zero
// state search results, log 0.
void SearchMetricsManager::OnOpen(ash::AppListSearchResultType result_type,
const std::u16string& query) {
if (ash::IsZeroStateResultType(result_type)) {
ash::RecordLauncherClickedSearchQueryLength(0);
} else {
ash::RecordLauncherClickedSearchQueryLength(query.length());
}
}
void SearchMetricsManager::OnTrain(LaunchData& launch_data,
const std::string& query) {
// Record a structured metrics event.
const base::Time now = base::Time::Now();
base::Time::Exploded now_exploded;
now.LocalExplode(&now_exploded);
metrics::structured::StructuredMetricsClient::Record(
std::move(metrics::structured::events::v2::launcher_usage::LauncherUsage()
.SetTarget(NormalizeId(launch_data.id))
.SetApp(last_launched_app_id_)
.SetSearchQuery(query)
.SetSearchQueryLength(query.size())
.SetProviderType(static_cast<int>(launch_data.result_type))
.SetHour(now_exploded.hour)
.SetScore(launch_data.score)));
// Only record the last launched app if the hashed logging feature flag is
// enabled, because it is only used by hashed logging.
if (IsAppListSearchResultAnApp(launch_data.result_type)) {
last_launched_app_id_ = NormalizeId(launch_data.id);
} else if (launch_data.result_type ==
ash::AppListSearchResultType::kArcAppShortcut) {
last_launched_app_id_ = RemoveAppShortcutLabel(NormalizeId(launch_data.id));
}
}
void SearchMetricsManager::OnSearchResultsUpdated(const Scoring& scoring) {
double score = scoring.BestMatchScore();
if (search_features::IsLauncherKeywordExtractionScoringEnabled()) {
UMA_HISTOGRAM_BOOLEAN(
"Apps.AppList.Scoring.ScoreAboveBestMatchThresholdWithKeywordRanking",
score > kBestMatchThresholdWithKeywordRanking);
} else {
UMA_HISTOGRAM_BOOLEAN(
"Apps.AppList.Scoring."
"ScoreAboveBestMatchThresholdWithoutKeywordRanking",
score > kBestMatchThreshold);
}
}
} // namespace app_list
|