gads_get_keyword_performance
Google Ads read low risk
Part of the Keyword Research Agent.
What it does
Pull keyword-level performance (impressions, clicks, CTR, avg CPC, cost, conversions, conv. value, CPA, ROAS) over a date range from keyword_view, with an automatic prior_period deltas via include_prior_period=true (immediately preceding equal-length window). Money fields are micros->currency (/1e6); CTR/conv-rate returned as ratios; avg CPC = metrics.average_cpc/1e6; CPA = metrics.cost_per_conversion (Google-provided, micros->currency, with a cost_per_conversion_display twin); ROAS = client-side `roas` key (conversions_value / cost; null when cost is 0). Every selected metrics key is present on every row — counters default to 0, ratio/average metrics to null when Google reports no value. Segment-aware: if segments.date/device/network are selected, rows multiply and must be aggregated per keyword for headline figures. Reconciles to the Google Ads UI within +/-1%. Returns {success, data:[{keyword, match_type, metrics, prior_period}], count, warnings}.
When to use it
When the user asks how keywords perform — spend, clicks, conversions, CPA per keyword — or wants keyword winners and losers.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
customer_id | string | yes | 10-digit CID, dashes stripped. |
ad_group_id | string | no | Restrict to one ad group; recommended to bound result size. |
campaign_id | string | no | Restrict to one campaign. |
date_range | string | yes | GAQL macro (LAST_7_DAYS/LAST_30_DAYS/THIS_MONTH/LAST_MONTH) or explicit YYYY-MM-DD..YYYY-MM-DD. Prior period = the immediately preceding equal-length window. ALL_TIME removes the date filter entirely. |
limit | integer | no | Max rows (GAQL LIMIT); default a safe cap. Large accounts use SearchStream. |
include_prior_period | boolean | no | Opt-in: also run the equal-length preceding window and attach prior_period={date_range, metrics, delta_pct} to every row. Needs a translatable date_range (LAST_7/14/30_DAYS, TODAY, YESTERDAY, THIS_MONTH, LAST_MONTH, or explicit 'YYYY-MM-DD,YYYY-MM-DD'); untranslatable ranges skip with a warning. |
Safeguards
Policy
Never fabricate or approximate a metric; if a figure can't be reconciled to the UI within +/-1%, say so. Quality/performance signals are diagnostic, not promises.
Reminder
Treat keyword/search performance as sensitive account data; do not retain beyond the request.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
CUSTOMER_NOT_FOUND | Account {customer_id} not found/linked. | Verify CID and authorization. | no |
TOKEN_REVOKED | Authorization expired/revoked. | needs_reauth — reconnect. | no |
INVALID_ARGUMENT | Bad date range, malformed YYYY-MM-DD, or invalid GAQL field/segment. | Surface Google's message; fix the query, don't guess. | no |
MANAGER_ACCOUNT_METRICS_UNSUPPORTED | Metrics on a manager (MCC) account return empty. | Query a child serving account. | no |
PERMISSION_DENIED | Lacks read access / out of bearer scope. | Confirm role/scope. | no |
RESOURCE_EXHAUSTED | Rate/quota limit (HTTP 429). | Backoff 5/10/20s cap 60s; honor retryDelay. | yes |
INTERNAL_ERROR | Transient 5xx. | Retry once after backoff. | yes |
Edge cases
- No data in range -> success count:0; prior_period also 0.
- Zero clicks -> CTR/CPC reported as 0, not a divide-by-zero error.
- Zero conversions -> CPA/ROAS returned as null (avoid divide-by-zero), with a note.
- Segment multiplication -> warn and aggregate per keyword for headline figures.
- Prior window crossing a month boundary -> still an equal-length preceding window; label both date ranges explicitly.
- Truncation by limit -> warn to narrow scope.
- Conversions can lag (attribution windows) -> recent-day figures may rise later; note for very recent ranges.
- Expired token -> refresh once and retry.