Read hosted analytics rows and Reports
Use a server-held user API key for a Site you can access. The first request is in Hosted first result.
Before you start
The key needs analytics:execute and authorization for the exact siteId. Keep Google search types separate when comparing results. Recent Search Console days can still change.
Query rows
const rows = await client.queryAnalyticsRows({
params: { siteId },
body: {
dimensions: ['query'],
metrics: ['clicks', 'impressions'],
searchType: 'web',
rowLimit: 100,
},
})
console.log(rows.data.rows, rows.meta.sourceName)Here client is the server client from the first-result guide. data.rows can be empty. meta identifies the source, query time, and request.
Query a Report
const report = await client.queryAnalyticsReport({
params: { siteId },
body: { state: { dimensions: ['query'], searchType: 'web' } },
})
console.log(report.data.rows, report.data.totals, report.data.meta.syncStatus)A Report adds totalCount, totals, comparison fields when requested, and sync metadata such as newestDateSynced. The detail operation, queryAnalyticsReportDetail, uses a different state contract. Check the hosted HTTP specification before changing dimensions.
| Result | Read it for |
|---|---|
| Raw rows | One filtered slice and its source metadata |
| Report | Totals, comparison, and Store sync coverage |
If the result looks incomplete
Read the Report's sync metadata before drawing a trend conclusion. A raw row query cannot prove full coverage. An empty row set can mean no matching rows. Check Errors and retry if the request fails.
Choose an integration
Render a small slice in Nuxt, or receive change notices after the initial HTTP read.