GSCClient
The GSC client wraps the Google Search Console API, handling authentication, pagination, and data fetching.
Constructor
import { GSCClient } from '@pagebridge/core'
const client = new GSCClient({
credentials: {
client_email: 'pagebridge@project.iam.gserviceaccount.com',
private_key: '-----BEGIN PRIVATE KEY-----\n...'
}
})Options
| Property | Type | Description |
|---|---|---|
credentials.client_email | string | Service account email |
credentials.private_key | string | Service account private key (PEM format) |
fetchSearchAnalytics(options)
Fetches search analytics data from Google Search Console. Handles pagination automatically (max 25,000 rows per request).
const rows = await client.fetchSearchAnalytics({
siteUrl: 'sc-domain:example.com',
startDate: new Date('2025-01-01'),
endDate: new Date('2025-03-01'),
dimensions: ['page', 'query', 'date']
})
// rows: SearchAnalyticsRow[]
// { page, query, date, clicks, impressions, ctr, position }SearchAnalyticsRow
interface SearchAnalyticsRow {
page: string
query?: string
date?: string
clicks: number
impressions: number
ctr: number
position: number
}listSites()
Lists all Search Console properties accessible to the service account.
const sites = await client.listSites()
// ['sc-domain:example.com', 'https://other-site.com/']inspectUrl(siteUrl, inspectionUrl)
Checks the Google index status for a specific URL using the URL Inspection API.
const result = await client.inspectUrl(
'sc-domain:example.com',
'https://example.com/blog/my-post'
)
// result: IndexStatusResult
// {
// verdict: 'PASS' | 'FAIL' | 'NEUTRAL' | 'VERDICT_UNSPECIFIED',
// coverageState: string | null,
// indexingState: string | null,
// pageFetchState: string | null,
// lastCrawlTime: Date | null,
// robotsTxtState: string | null
// }IndexStatusResult
type IndexVerdict = 'PASS' | 'FAIL' | 'NEUTRAL' | 'VERDICT_UNSPECIFIED'
interface IndexStatusResult {
verdict: IndexVerdict
coverageState: string | null
indexingState: string | null
pageFetchState: string | null
lastCrawlTime: Date | null
robotsTxtState: string | null
}