Currently Available: Need a skilled Software Developer for your next project?
Categories
SEO, GEO and AEO

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 need to know which page type, such as a product, category, or article page, drove the change. A template is the shared page type or layout behind a group of URLs. Search Console reports performance by individual page, and its Pages tab has no built-in way to group those pages by templates from your content management system (CMS). BigQuery, Google’s cloud data warehouse, lets you bridge that gap by matching exported URLs to a separate template mapping.

To report performance by template, you match each URL in Search Console’s export to a mapping table that assigns it a single template. Next, you sum clicks and impressions at the level you want to report, such as one row per template per day. You also keep unrecognized URLs in the results and compare totals before and after the join so duplicate mapping rows do not inflate your metrics. Google’s URL-level export table provides the landing-page URLs you need for this classification.

Choose a URL key and template source

Your template report is only as reliable as the mapping behind it, so build that map from a source that reflects how your site actually assigns page types. A CMS or routing inventory works well if it lists each page’s canonical URL (the preferred version of the page) alongside its template. If your inventory lacks that data, you can classify URLs using reviewed rules or a site crawl. Store the mapping in its own table, separate from Search Console’s performance data, so you can update and audit classifications without touching the exported table.

Make sure your mapping keys match the URLs Search Console reports. Search Console’s Performance report generally attributes clicks and impressions to a page’s canonical URL. If you build a mapping from redirecting URLs or duplicate versions, BigQuery will fail to match them to the export. Check the report’s canonical URL behavior while you assemble the map.

Use the full URL as your join key, which is the value BigQuery uses to connect a Search Console row to a template. Exact URL matches are the easiest to inspect and debug. If you normalize URLs into a consistent format, apply the exact same documented rules to both the exported URLs and your mapping keys. A rule that strips query parameters (the parts of a URL after ?), alters trailing slashes, or changes letter case can merge pages your site treats as distinct. Before you use any normalization rule, verify that it does not assign the same key to two different pages.

Your mapping table needs exactly one row per URL key. The query below shows how a CMS inventory might populate the map; replace the table and column names with the ones in your warehouse:

CREATE OR REPLACE TABLE <code>project.analytics.url_template_map AS
SELECT
  canonical_url AS url_key,
  page_template AS template
FROM project.cms.page_inventory
WHERE canonical_url IS NOT NULL;

Use this pattern only if your inventory provides a single template for each canonical URL. If the source table contains historical versions or duplicate records, resolve them there with an explicit rule instead of picking an arbitrary row. BigQuery does not enforce declared primary-key constraints, so declaring a key will not stop duplicate rows from entering the table. Run this check after every refresh:

SELECT
  url_key,
  COUNT(*) AS mapping_rows
FROM <code>project.analytics.url_template_map
GROUP BY url_key
HAVING url_key IS NULL OR COUNT(*) > 1;

Fix every key this query returns before you join the map. If a page changes templates over time and you want historical reports to show the template used on each date, store start and end dates for every template assignment. Match each performance date to one mapping period, and verify that those periods never overlap. If your map stores only the current template, BigQuery will apply today’s classification to all past performance.

Join the export and keep unmatched rows

Start with searchdata_url_impression, the Search Console bulk export table that breaks data down by URL. The companion site-level table does not identify individual landing pages. Because Google documents repeated keys in the export, the raw table can hold several rows for one URL on the same day. Sum the metrics at your target reporting level, and filter by date so BigQuery scans fewer date-based table sections, called partitions, as Google’s query guidance recommends.

This query produces one row per template per day. Swap in your own project and dataset names. It assumes an exact URL match and one mapping row per URL:

WITH page_day AS (
  SELECT
    data_date,
    url,
    SUM(clicks) AS clicks,
    SUM(impressions) AS impressions
  FROM <code>project.searchconsole.searchdata_url_impression
  WHERE data_date BETWEEN DATE '2026-11-01' AND DATE '2026-11-30'
  GROUP BY data_date, url
)
SELECT
  p.data_date,
  CASE
    WHEN p.url IS NULL THEN 'no_url'
    ELSE COALESCE(m.template, 'unmapped')
  END AS template,
  SUM(p.clicks) AS clicks,
  SUM(p.impressions) AS impressions
FROM page_day AS p
LEFT JOIN project.analytics.url_template_map AS m
  ON p.url = m.url_key
GROUP BY p.data_date, template;

The LEFT JOIN keeps every row from the Search Console export, including URLs that have no match in your map. When a match is missing, BigQuery fills the mapping fields with NULL, its marker for a missing value. The COALESCE function returns the mapped template when it exists and 'unmapped' when it is missing. The query gives rows without a URL a separate 'no_url' label because you cannot assign a missing URL to a page template. Some Discover rows flagged by is_anonymized_discover lack a URL, and you should not try to infer a template for them.

If you also want to break results down by device, country, or search type, add each field to both the GROUP BY before the join and the final GROUP BY. Each field you include changes what a single result row represents. For more on keeping rows at the right level of detail while summing metrics, see Search Console aggregation logic in BigQuery. Also note that the exported data_date uses Pacific Time. If you compare these numbers to a report in another time zone, account for that offset; Google’s table reference covers the date field in detail.

Check coverage and compare totals

Review your unmatched URLs to see which pages the mapping missed. This query lists every unmapped URL that earned impressions during the same date range:

SELECT
  s.url,
  SUM(s.clicks) AS clicks,
  SUM(s.impressions) AS impressions
FROM <code>project.searchconsole.searchdata_url_impression AS s
LEFT JOIN project.analytics.url_template_map AS m
  ON s.url = m.url_key
WHERE s.data_date BETWEEN DATE '2026-11-01' AND DATE '2026-11-30'
  AND s.url IS NOT NULL
  AND m.url_key IS NULL
GROUP BY s.url
ORDER BY impressions DESC;

An unmatched URL usually comes from a newly launched page, a changed URL, or a gap in your inventory. Inspect the live page and your mapping source before assigning a template. If you leave a URL unclassified on purpose, keep it visible in the output and document that decision.

Before you rely on the template totals, compare clicks, impressions, and row counts before and after the join using the exact same dates and filters. With a left join and one mapping row per URL, those totals should be identical. If clicks, impressions, or row counts climb, one or more Search Console rows matched multiple mapping records. If any total drops, the query removed rows, which happens when an inner join discards unmatched URLs or a later filter excludes rows with NULL mapping values.

WITH page_day AS (
  SELECT
    data_date,
    url,
    SUM(clicks) AS clicks,
    SUM(impressions) AS impressions
  FROM <code>project.searchconsole.searchdata_url_impression
  WHERE data_date BETWEEN DATE '2026-11-01' AND DATE '2026-11-30'
  GROUP BY data_date, url
),
joined AS (
  SELECT p.*
  FROM page_day AS p
  LEFT JOIN project.analytics.url_template_map AS m
    ON p.url = m.url_key
)
SELECT
  'before_join' AS stage,
  COUNT(*) AS rows,
  SUM(clicks) AS clicks,
  SUM(impressions) AS impressions
FROM page_day

UNION ALL

SELECT
  'after_join' AS stage,
  COUNT(*) AS rows,
  SUM(clicks) AS clicks,
  SUM(impressions) AS impressions
FROM joined;

Compare these numbers before you filter by template. If clicks or impressions rise, fix the mapping table or the join condition instead of adding DISTINCT, which can hide the underlying bug. BigQuery’s join troubleshooting guidance recommends checking for duplicate values in the columns used to match rows. For a broader reconciliation of Search Console data, see verifying Search Console data in BigQuery before reporting.

What I'm building

Delegate tasks. Get software.

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

Email updates

Usually a new article and a few links I found interesting.

No spam. Unsubscribe with one click.

Leave a Reply

Your email address will not be published. Required fields are marked *