What is GAQL (Google Ads Query Language)?
An introduction to GAQL: the structure of a query, resources, fields and the rules that trip people up.
GAQL β Google Ads Query Language β is how you ask Google Ads for data. It looks like SQL, and it is what Google Ads scripts and the Google Ads API both use for reporting.
The shape of a query
SELECT campaign.name, metrics.clicks, metrics.cost_micros
FROM campaign
WHERE campaign.status = 'ENABLED'
AND segments.date DURING LAST_30_DAYS
ORDER BY metrics.clicks DESC
LIMIT 20- SELECT β the fields you want back.
- FROM β one resource:
campaign,ad_group,keyword_view,search_term_view,shopping_performance_viewand many more. - WHERE β filters, combined with
AND. - ORDER BY and LIMIT β sorting and the number of rows.
Three kinds of field
- Attributes describe the thing itself:
campaign.name,ad_group.status. - Metrics are numbers:
metrics.impressions,metrics.conversions. - Segments split the numbers:
segments.date,segments.device.
Adding a segment to SELECT multiplies the rows: one per campaign becomes one per campaign per day.
Rules that trip people up
- One resource per query. There are no joins. Related resources are available through fields β from
ad_groupyou can selectcampaign.name. - Not every field goes with every resource. Each resource has its own list of compatible fields.
- No `OR`. Use
IN (...)or run separate queries. - Cost is in micros. Divide
metrics.cost_microsby 1,000,000. - Dates need a filter. If you select or segment by date, filter on
segments.date.
Trying it out
GAQL Lab lets you write queries with autocomplete, validates them before they run, and shows results from any connected account. The Builder tab assembles a query from a form if you do not know the field names yet.
- 1
Pick the account to query.
- 2
Start from an example and adapt it.
- 3
Run Query, or press
Cmd+Enter. The validator flags unknown fields and syntax errors before you run. - 4
Results with readable column names. Cost values in micros are converted for you.
- 5
Copy the query as an
AdsApp.search()snippet for a script, or download the rows as CSV.