Google vertical searches are identified by the presence of a `tbm` parameter (images, news, video, shopping, books) or a `udm` parameter set to a vertical value (images, video, shopping, forums, short videos). Previously these were counted toward Google SERP metrics alongside regular web searches, inflating the count. This adds `IsGoogleWebSearch` to filter them out so only plain web searches are recorded. `udm=0` (implicit default), `udm=14` (web without AI Overviews), and `udm=web` are all treated as web searches.
62 lines
2.1 KiB
C++
62 lines
2.1 KiB
C++
/* Copyright (c) 2026 The Brave Authors. All rights reserved.
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "brave/components/serp_metrics/serp_classifier_utils.h"
|
|
|
|
#include <string>
|
|
|
|
#include "base/containers/fixed_flat_set.h"
|
|
#include "net/base/url_util.h"
|
|
#include "url/gurl.h"
|
|
|
|
namespace serp_metrics {
|
|
|
|
namespace {
|
|
|
|
constexpr auto kAllowedSearchEngines = base::MakeFixedFlatSet<SearchEngineType>(
|
|
base::sorted_unique,
|
|
{SEARCH_ENGINE_BING, SEARCH_ENGINE_GOOGLE, SEARCH_ENGINE_YAHOO,
|
|
SEARCH_ENGINE_DUCKDUCKGO, SEARCH_ENGINE_QWANT, SEARCH_ENGINE_ECOSIA,
|
|
SEARCH_ENGINE_BRAVE, SEARCH_ENGINE_STARTPAGE});
|
|
|
|
// Google URL query parameter names that select a search vertical.
|
|
// Known `tbm` verticals: isch (images), nws (news), vid (video), shop
|
|
// (shopping), bks (books).
|
|
// Known `udm` verticals: 2 (images), 7 (video), 12 (news), 18 (forums), 28
|
|
// (shopping), 39 (short videos).
|
|
constexpr std::string_view kTbmParam = "tbm";
|
|
constexpr std::string_view kUdmParam = "udm";
|
|
|
|
// `udm` values that represent a plain web search. `udm=0` is the implicit
|
|
// default; `udm=14` is the Web tab without AI Overviews; `udm=web` is a string
|
|
// alias Google uses for the Web tab.
|
|
constexpr std::string_view kUdmAllResults = "0";
|
|
constexpr std::string_view kUdmWebNoAiOverview = "14";
|
|
constexpr std::string_view kUdmWebString = "web";
|
|
|
|
} // namespace
|
|
|
|
bool IsAllowedSearchEngine(SearchEngineType type) {
|
|
return kAllowedSearchEngines.contains(type);
|
|
}
|
|
|
|
bool IsGoogleWebSearch(const GURL& url) {
|
|
std::string value;
|
|
if (net::GetValueForKeyInQuery(url, kTbmParam, &value)) {
|
|
// Any `tbm` value routes to a vertical search (images, news, video, etc.).
|
|
return false;
|
|
}
|
|
if (net::GetValueForKeyInQuery(url, kUdmParam, &value) &&
|
|
value != kUdmAllResults && value != kUdmWebNoAiOverview &&
|
|
value != kUdmWebString) {
|
|
// Any other `udm` value routes to a vertical search (images, video,
|
|
// shopping, etc.).
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
} // namespace serp_metrics
|