Grouping Search Console Pages by Template in BigQuery
When you spot a traffic shift in Search Console’s Pages tab, the report lists the individual landing-page URLs that moved. You still…
Website owners use branded and nonbranded query reports to compare searches for their organization, products, or services against other searches. Search Console’s BigQuery export includes clicks and impressions alongside query text, but Google’s documented export schema has no branded or nonbranded field. You have to write SQL rules to assign those labels yourself.
Google does offer a separate AI-assisted branded-query classification inside Search Console and through the Search Analytics API for eligible properties. That system can pick up related products or services and query variants even when a query does not contain the exact brand name. Those labels work differently from SQL rules you write yourself, and Google’s published BigQuery schema does not list them as a field. Check the table schema in your own project before you assume that column exists.
To build a report you can trust, you need to version your rules, keep the original query text for review, and separate unresolved queries from the ones you have classified as nonbranded.
Decide what counts as “branded” before you write any SQL. You might include your organization’s name, known misspellings, product names, and service names. You also need to decide how to handle shared terms, acronyms, or names that mean something else outside your business.
Google’s own branded-query filter relies on contextual rules that you cannot inspect or edit. Google notes that its system can recognize brand-related searches without the brand name, though it also warns that the classification can occasionally be wrong. When you use the Search Console filter or API, treat those labels as Google’s assessment. When you report from BigQuery, treat the labels as your own reporting convention.
Store your rules in a dedicated table instead of copying a long regular expression into every query. Give each row a version, a rule ID, a match type, and a match value, along with the assigned class and a priority. Adding a rationale and an owner helps your team review changes later, and the version column lets you apply the exact same rule set to both periods in a comparison.
Use exact matches for reviewed query strings and regular expressions for known patterns or spelling variants. For example, an exact rule can mark a reviewed query as ambiguous, while a broader regular expression identifies your organization’s name. Give exact exceptions higher priority than broad patterns so a query that matches both follows the documented exception. The sample values below are hypothetical and need to be replaced with tested, site-specific rules.
| Rule version | Match type | Match value | Class | Priority | Rationale |
|---|---|---|---|---|---|
v1 |
regex |
(?i)(^|[^[:alnum:]])examplebrand([^[:alnum:]]|$) |
branded |
@broad_priority |
Hypothetical organization name |
v1 |
exact |
exampelbrand |
branded |
@exact_priority |
Hypothetical reviewed misspelling |
v1 |
exact |
example |
ambiguous |
@exception_priority |
Hypothetical shared or unclear term |
GoogleSQL’s REGEXP_CONTAINS looks for a partial match, so a pattern without word boundaries will also match longer words that happen to contain that text. BigQuery regex matching is case-sensitive by default, which is why the example uses the (?i) flag to ignore case. Check the BigQuery string-function documentation and GoogleSQL syntax documentation before you add new patterns, and test each one against sample queries. BigQuery returns an error if a pattern is invalid.
The SQL below applies a single rule version to a property-level Search Console export. It preserves query as original_query for auditing and creates a lowercased, trimmed copy only for exact matching. If a query is anonymized or empty, the SQL labels it unavailable because you have no text to classify. If no rule matches, the SQL assigns unmatched_review instead of silently counting the search as nonbranded.
WITH source AS ( SELECT data_date, query AS original_query, LOWER(TRIM(query)) AS normalized_query, is_anonymized_query, search_type, device, country, clicks, impressions FROM <code>project.dataset.searchdata_site_impressionWHERE data_date BETWEEN @start_date AND @end_date ), rules AS ( SELECT rule_id, match_type, match_value, query_class, priority FROMproject.dataset.query_classification_rulesWHERE rule_version = @rule_version ), classified AS ( SELECT s.*, CASE WHEN COALESCE(s.is_anonymized_query, FALSE) OR s.original_query IS NULL OR TRIM(s.original_query) = '' THEN 'unavailable' ELSE COALESCE( ( SELECT r.query_class FROM rules AS r WHERE ( r.match_type = 'exact' AND s.normalized_query = LOWER(TRIM(r.match_value)) ) OR ( r.match_type = 'regex' AND REGEXP_CONTAINS(s.original_query, r.match_value) ) ORDER BY r.priority DESC, r.rule_id LIMIT 1 ), 'unmatched_review' ) END AS query_class FROM source AS s ) SELECT data_date, original_query, query_class, search_type, device, country, SUM(clicks) AS clicks, SUM(impressions) AS impressions FROM classified GROUP BY data_date, original_query, query_class, search_type, device, country;
This query keeps the output at the query level so you can see which search terms received each label and how the rules grouped their metrics. You can save the result as a view or a table to support both audits and downstream reporting. Replace the placeholder table and parameter names with your own. Filtering on data_date also limits the data BigQuery scans from the date-partitioned export.
In this setup, a query only becomes nonbranded when a rule explicitly assigns that label. Review high-impression rows marked unmatched_review and decide whether each one belongs under a branded, nonbranded, or ambiguous rule. Leaving unresolved rows visible until you review them stops you from treating every new query or missed spelling variant as nonbranded.
Aggregate clicks and impressions only after you classify the queries. For a monthly report, sum clicks and impressions by month and class, then divide total clicks by total impressions to get the click-through rate (CTR). If you average query-level or daily CTRs instead, you give small and large groups equal weight. Search Console’s query guidance also recommends aggregating exported metrics because the export can contain repeated keys.
For example, after saving the query-level output as classified_query_daily, a monthly summary can use:
SELECT
DATE_TRUNC(data_date, MONTH) AS month,
query_class,
search_type,
device,
country,
SUM(clicks) AS clicks,
SUM(impressions) AS impressions,
SAFE_DIVIDE(SUM(clicks), SUM(impressions)) AS ctr
FROM <code>project.dataset.classified_query_daily
WHERE data_date BETWEEN @start_date AND @end_date
GROUP BY month, query_class, search_type, device, country
ORDER BY month, query_class;
Compare the same search type and other dimensions across periods, and use the same rule version on both sides. If you change a rule, either reclassify both periods with the new version or keep the old version for the comparison. Otherwise, a change in labels can look like a change in search behavior.
Keep unmatched_review and unavailable visible in your summary tables. Anonymized rows carry no query text for your rules to inspect, and the export can signal them with a flag, a null, or an empty string. The SQL above catches all three cases. Because you cannot assign hidden queries to a brand class, your classified totals will not necessarily match your overall property totals.
Search Console’s data_date column uses Pacific Time, and export timing can vary. Use consistent date boundaries and confirm that both periods contain complete dates before you compare trends. You can catch missing days that would skew your numbers by verifying BigQuery data before reporting.
Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.
Take a look at vroni.com