Query search analytics
analytics.queryQuery Google Search Console search analytics to get clicks, impressions, CTR, and position, grouped by dimension or as site totals. Supports filters, pagination, and multiple search types.
Instructions
Query Google Search Console search analytics data. Returns { row_count, start_row, rows } where each row has keys (dimension values), clicks, impressions, ctr, and position. When row_count equals row_limit, the response includes next_start_row — pass it back as start_row to fetch the next page. When Google provides them, response_aggregation_type and metadata are also included; metadata may identify the first incomplete date or hour.
IMPORTANT BEHAVIORS — read before calling:
For SITE TOTALS (total impressions, total clicks, overall CTR, overall average position), call with dimensions: []. This returns a single row containing the true site-level totals. Do NOT call with dimensions: ["query"] and sum the rows — Google omits anonymized low-volume queries from per-dimension responses, so summing per-query rows will undercount.
For TOP QUERIES / PAGES / COUNTRIES / DEVICES, call with the matching dimension. Expect the returned rows to cover only a subset of total impressions; this is normal Google behavior, not a data error.
DATA FRESHNESS: Search Console data lags about 2-3 days behind real time. If the user asks about "today" or "yesterday", expect empty or partial rows for the most recent days; the latest reliably-complete date is usually 3 days ago.
AVERAGE POSITION is impression-weighted. To compute an overall position across multiple rows, use sum(position * impressions) / sum(impressions). Never plain-average the position column across rows.
CTR in the response is a 0–1 fraction. Multiply by 100 for percent.
Use search_type to query image/video/news/discover indexes separately from web.
Use dimension_filter_groups to filter by country, device, query content, page URL, or search feature. includingRegex and excludingRegex use RE2 syntax. For brand vs non-brand splits, pass a single regex filter on the 'query' dimension.
data_state defaults to 'all' which matches the GSC dashboard. Pass 'final' only when the user explicitly asks for stable, non-preliminary data.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end_date | Yes | End date (inclusive) in YYYY-MM-DD format. Note the 2-3 day data lag: the most recent complete date is usually 3 days ago. | |
| site_url | Yes | The Search Console property identifier, exactly as returned by sites.list. Two formats exist: domain properties use 'sc-domain:example.com'; URL-prefix properties use the full URL including protocol and trailing slash, e.g. 'https://www.example.com/'. Passing the wrong format returns a permission error even when the user owns the site — call sites.list first if unsure. | |
| row_limit | No | Maximum rows to return (1-25000). Defaults to 100, which is plenty for most questions; raise it only for bulk exports and page through with start_row. | |
| start_row | No | Zero-based row offset for pagination. When a response contains next_start_row, pass it here to fetch the next page. | |
| data_state | No | 'all' includes fresh (preliminary) data and matches the GSC dashboard; 'final' returns only finalized data. | all |
| dimensions | No | Dimensions to group rows by. Pass [] (empty array) to get a single row of true site-level totals. | |
| start_date | Yes | Start date (inclusive) in YYYY-MM-DD format. | |
| search_type | No | Which search index to query. Defaults to web. | web |
| aggregation_type | No | How Google aggregates metrics. Leave as 'auto' unless you specifically need byPage or byProperty semantics. | auto |
| dimension_filter_groups | No | Optional filters ANDed together, e.g. [{ groupType: 'and', filters: [{ dimension: 'country', operator: 'equals', expression: 'usa' }] }]. Countries use ISO 3166-1 alpha-3 codes. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rows | Yes | ||
| metadata | No | Google data-completeness metadata, included only when returned by Google. | |
| row_count | Yes | ||
| start_row | Yes | ||
| next_start_row | No | ||
| response_aggregation_type | No | Google response aggregation type, included only when returned by Google. |