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

Building a Search Console to BigQuery Pipeline

Website owners and developers who want Search Console data in a company data warehouse can schedule code to pull it from Google’s Search Analytics API. Your code chooses which Search Console property to query, which fields to group the results by, and where to send them. A Search Console property is a verified website or domain that an owner manages in Search Console, and BigQuery is Google Cloud’s data warehouse for storing and analyzing data.

If your platform serves multiple website owners, your worker uses each customer’s Google authorization to read their data. On a schedule, the worker queries the API, turns each response into structured records, and writes them to BigQuery. You need to store customer credentials so future runs can reuse them, and you need to make writes repeatable because a scheduled job can run more than once.

The API gives you control over custom integrations, though it does not return a complete copy of all Search Console performance data. You can also use Google’s managed BigQuery export, where Google delivers available performance data straight to BigQuery, excluding anonymized queries. The API enforces its own row limits and completeness limits.

Separate customer access from data writing

A platform integration relies on two distinct permissions. The customer authorizes your service to read their Search Console data, while your service’s Google Cloud identity gives the worker permission to write to your BigQuery project. Keeping those two permissions apart limits what each credential can reach and makes failures easier to trace.

Google’s Search Console API uses OAuth 2.0 so a user can grant your service specific access without sharing their password. Request the https://www.googleapis.com/auth/webmasters.readonly scope, which lets your service read Search Console data without changing anything. You can check the full authorization rules in the Search Console authorization documentation.

Because your worker runs on a schedule, request offline access through Google’s web-server OAuth flow. With offline access, your worker uses a refresh token to get a new access token once the short-lived one expires, so the customer never has to sign in again to keep the sync running. Save the refresh token in durable, access-restricted storage and encrypt it at rest. Tie each token to your internal customer ID, and give customers a way to reconnect if they revoke access. Google’s OAuth guidance for web-server applications covers how offline access and refresh tokens work.

A customer’s OAuth grant does not give your worker permission to write to BigQuery. Instead, assign the worker its own Google Cloud identity with write access to the destination dataset. Your service owns that identity, and the customer’s grant stays limited to reading their Search Console data.

If you are building a product for multiple customers, default to customer OAuth. A service account is a Google Cloud identity that lets services talk directly to each other, but it still has to be granted access to a Search Console property. Verify that a service account fits your API use case before relying on it, and do not assume the same setup will work for every property.

Let one worker handle the data path

Keep your Google connector separate from the code that writes to your destination. The connector handles customer credentials, picks a property the customer can access, sends Search Analytics requests, and reads the responses. The writer takes those results and formats them for BigQuery or another internal system.

For each connected property, your scheduled worker picks a date range and Search type, asks for the fields used to group results, normalizes the returned rows, and writes them out. A grouping field, called a dimension, might be a date, a page, or a device. When the worker requests data grouped by date and page, the API returns one row for each date-and-page combination it reports.

The API puts the requested dimension values in a keys array, matching the exact order of the dimensions in your request. It also returns metrics like clicks, impressions, click-through rate (CTR), and average position. Here is a Python example that requests finalized web results grouped by date, page, and device:

from googleapiclient.discovery import build

def fetch_search_analytics(credentials, property_url, start_date, end_date):
    service = build(
        "searchconsole",
        "v1",
        credentials=credentials,
        cache_discovery=False,
    )

    response = service.searchanalytics().query(
        siteUrl=property_url,
        body={
            "startDate": start_date,
            "endDate": end_date,
            "type": "web",
            "dimensions": ["date", "page", "device"],
            "dataState": "final",
            "rowLimit": 25_000,
        },
    ).execute()

    return response.get("rows", [])

The credentials object must come from the customer’s OAuth authorization and support token refresh. This request uses documented query fields and caps each response at 25,000 rows. For details on dimensions, metrics, date handling, and data-state options, see the Search Analytics query reference.

Before you write anything to BigQuery, map each response row into an explicit record shape:

def to_records(property_url, rows):
    records = []

    for row in rows:
        date, page, device = row["keys"]

        records.append({
            "property_url": property_url,
            "data_date": date,
            "page": page,
            "device": device,
            "clicks": row.get("clicks", 0),
            "impressions": row.get("impressions", 0),
            "ctr": row.get("ctr", 0),
            "position": row.get("position", 0),
        })

    return records

This mapping is tied directly to the dimensions in your request. If you change the query to group by date and query instead, the keys array will hold different values, so you need to update the mapping and the destination schema together. Store the Search type and query settings alongside your ingestion metadata so operators can see how each record was generated.

Write repeatable results

Design every run so that repeating it leaves the final table in the exact same state as the first successful run. Engineers call this idempotency. You can achieve it by giving each job a stable key built from the customer, property, Search type, and requested date range. When the worker writes data, it replaces or merges that specific property-and-date slice instead of appending duplicate rows.

In BigQuery, have your worker load incoming records into a staging table, then merge or replace the matching rows in your reporting table. Record the requested date range, property, Search type, ingestion time, and run status in durable storage. That way, if a worker restarts mid-run, you do not lose track of completed work or leave a failed date range unnoticed. BigQuery supports batch loading when data arrives in batches, so pick a load method that matches how often your pipeline updates its tables.

Stick to one clear date convention. Search Analytics request dates follow Pacific Time, so do not treat them as UTC dates without making that explicit. The API also distinguishes finalized data from fresher data that can still change. If you want stable reports, request finalized data. If your product needs more recent numbers, have the worker re-fetch a recent date range and replace those rows. Google does not define a single lookback window for every use case.

Schedule jobs that tolerate retries

Cloud Scheduler can trigger a Cloud Run service using OIDC authentication, which uses a token so one service can prove its identity to another. Scheduler uses OIDC to authenticate to your worker, and the worker then uses the stored customer OAuth grant to call Search Console. Google walks through this setup in its Cloud Scheduler to Cloud Run pattern.

Cloud Scheduler guarantees at-least-once delivery, meaning it can send the same scheduled request more than once. If a request times out, Scheduler may not know whether your worker finished the job. Have your worker check durable job status and use idempotent writes so it handles repeat requests safely. Google’s Scheduler deduplication guidance explains why targets have to expect duplicate requests.

For longer jobs, have the scheduled endpoint put work onto a queue and return right away. A separate worker can then process each property and date range on its own, so one customer’s expired authorization or API error does not stall exports for everyone else. When the worker hits temporary network or service errors, retry them with increasing delays. If a customer revokes authorization or the worker loses access to a property, stop retrying and flag the job for customer or operator action.

For every run, log the customer and property identifiers, requested dates, result count, write status, and error category, and never write access or refresh tokens to your logs. Set up an alert when a date range fails and give operators a way to replay it. Because your writes are idempotent, replaying a job will not duplicate final rows.

Set expectations about API coverage

A successful API response does not mean your pipeline captured every Search Console row. Google caps Search Console API performance data at 50,000 rows per day, per type, per property, and the Search Analytics API may also return top rows rather than every possible row. The per-request limit of up to 25,000 rows does not lift those broader caps. You can review the details in Google’s Search Console API data-export guidance and the API usage limits.

Those limits matter when you decide between building a custom API integration and using Google-managed bulk export. If you build on the API, your service controls customer authorization, grouping fields, scheduling, and the destination. If you turn on Google’s BigQuery bulk export, Google sends available performance data directly to BigQuery each day, excluding anonymized queries. Build on the API when your product needs a programmable integration or a destination other than BigQuery. Use bulk export when its managed delivery and data coverage already fit what the property owner needs.

For related architecture choices, see building an internal Search Console API integration and integrating Search Console exports into a platform.

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 *