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

Join Search Console Site and URL Data Safely

When you combine the site and URL performance tables in Google Search Console’s BigQuery bulk export, each row already summarizes data. A table’s grain is what a single row represents. The searchdata_site_impression table summarizes performance for a property, while searchdata_url_impression summarizes performance for a URL.

If you join those tables on the fields they share, BigQuery repeats a single site row once for every matching URL row. If you then sum the repeated site clicks or impressions, your totals will be too high. Instead, group each table to the level of detail you want before you join them, and keep site and URL metrics separate. You can display site metrics next to URL data, but you will not get a valid site total if you add the repeated site values across rows.

Why site and URL rows differ

Google uses shared fields to describe rows in both tables, including date, property, query, country, search type, and device. The URL table also includes the URL itself and indicators that show how a result appeared in search. Because of those extra fields, the URL table often holds multiple rows that share the exact same date, property, query, country, search type, and device. Google’s BigQuery export table reference lists the full set of fields for both tables.

The two tables also count clicks and impressions differently. For a single query, Google can count two results from the same property as one impression in the site table, while it counts each unique URL separately in the URL table. Clicks work the same way: if a user clicks one result from your property, goes back to the search results, and clicks another URL from your property, Google can count one property click and two page clicks, as explained in Google’s Search Console performance data documentation.

Suppose one site row for a given date, query, country, search type, and device matches three URL rows. A direct join returns three rows, and each row repeats the same site clicks and impressions. If you sum those repeated site values, you count them three times, while the URL metrics follow their own counting rules.

Google also does not guarantee that exported rows arrive pre-grouped by date or other fields, so its query guidance recommends aggregating them yourself. Group each table by the fields that define the row you want in your output. That way, each side enters the join with predictable values.

Group each table before joining

Start by deciding what each row in your final result should represent. The query below returns one row per URL for each combination of date, property, query, country, search type, and device. It groups site rows by the fields shared with the URL table, groups URL rows by those same fields plus url, and joins the two results on every shared field.

Set the named parameters to a single test date, property, query, country, and device that have rows in both tables. This example filters for standard web search and excludes anonymized queries. Because Google’s documentation is inconsistent about whether an anonymized query is stored as an empty string or as null, the filter checks is_anonymized_query rather than assuming a specific value in query.

WITH site AS (
  SELECT
    data_date,
    site_url,
    query,
    is_anonymized_query,
    country,
    search_type,
    device,
    SUM(clicks) AS site_clicks,
    SUM(impressions) AS site_impressions,
    COUNT(*) AS site_export_rows
  FROM <code>project.dataset.searchdata_site_impression
  WHERE data_date = @test_date
    AND site_url = @test_site_url
    AND query = @test_query
    AND country = @test_country
    AND device = @test_device
    AND search_type = 'WEB'
    AND is_anonymized_query = FALSE
  GROUP BY
    data_date,
    site_url,
    query,
    is_anonymized_query,
    country,
    search_type,
    device
),
url AS (
  SELECT
    data_date,
    site_url,
    query,
    is_anonymized_query,
    country,
    search_type,
    device,
    url,
    SUM(clicks) AS url_clicks,
    SUM(impressions) AS url_impressions
  FROM project.dataset.searchdata_url_impression
  WHERE data_date = @test_date
    AND site_url = @test_site_url
    AND query = @test_query
    AND country = @test_country
    AND device = @test_device
    AND search_type = 'WEB'
    AND is_anonymized_query = FALSE
  GROUP BY
    data_date,
    site_url,
    query,
    is_anonymized_query,
    country,
    search_type,
    device,
    url
)
SELECT
  u.data_date,
  u.site_url,
  u.query,
  u.country,
  u.search_type,
  u.device,
  u.url,
  u.url_clicks,
  u.url_impressions,
  s.site_clicks,
  s.site_impressions
FROM url AS u
LEFT JOIN site AS s
  USING (
    data_date,
    site_url,
    query,
    is_anonymized_query,
    country,
    search_type,
    device
  );

The url query leaves out the search-appearance indicators, so it combines rows that differ only by those indicators into one row per URL and shared join fields. If you keep those indicators, multiple URL rows can still match a single site row because they share the same join fields.

Even with this setup, site_clicks and site_impressions repeat on every row for URLs that share the same join fields. Do not sum them across those rows; calculate property totals separately from the grouped site table instead. If you want one row per combination of shared join fields, group the URL table by those fields before joining. Label the resulting numbers as URL metric sums, since they do not necessarily match Search Console’s property-level totals.

Test one slice before scaling

Before you run this across a large date range, test a single date and one combination of property, query, country, and device. Keep the date filter in place. Google uses Pacific Time for data_date and organizes rows into date-based partitions, as noted in its tables are date-partitioned documentation. Make sure both tables actually have data for the date you pick, because Google exports the tables separately.

Using the same site and url common table expressions from above, swap out the final SELECT for this row-count check:

SELECT
  (SELECT COUNT(*) FROM url) AS url_rows,
  COUNT(*) AS rows_after_join,
  COUNTIF(s.site_export_rows IS NOT NULL) AS rows_with_site_match
FROM url AS u
LEFT JOIN site AS s
  USING (
    data_date,
    site_url,
    query,
    is_anonymized_query,
    country,
    search_type,
    device
  );

For this left join, url_rows and rows_after_join should be equal. If rows_after_join is higher, the site table contains more than one row with the same join fields and is duplicating your URL rows. Because the site query groups by every shared field, it should produce at most one site row for each combination of join-field values. If you see URL rows without a site match, check your filters and confirm that both tables have data for that date. A missing match on its own does not mean the metrics disagree.

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 *