Documentation
¶
Overview ¶
Package gsc integrates Google Search Console: the search queries that bring people to your site, next to what they did after arriving — the one report neither GA nor the privacy tools unify well. BYO Google OAuth client (two env vars), a one-command loopback auth, a small daily poller, and the same three surfaces as everything else: dashboard card, MCP tool, verdict material.
Stdlib only, like the rest of the binary. Google endpoints are package vars so tests run against a fake server.
Index ¶
- Variables
- func AuthURL(c Creds, redirect string) string
- func Exchange(ctx context.Context, c Creds, code, redirect string) (string, error)
- func ListSites(ctx context.Context, c Creds, refreshToken string) ([]string, error)
- type Creds
- type PageRow
- type Row
- type Store
- func (s *Store) Connected() bool
- func (s *Store) PageSnapshot() (rows, prev []PageRow, fetchErr string)
- func (s *Store) Poll(ctx context.Context, c Creds) error
- func (s *Store) SetGrant(refreshToken, siteURL string) error
- func (s *Store) SetPageFetchError(msg string) error
- func (s *Store) SetPageRows(rows []PageRow) error
- func (s *Store) SetRows(rows []Row) error
- func (s *Store) Snapshot() (rows, prev []Row, site string, fetched time.Time)
Constants ¶
This section is empty.
Variables ¶
var ( AuthEndpoint = "https://accounts.google.com/o/oauth2/v2/auth" TokenEndpoint = "https://oauth2.googleapis.com/token" APIEndpoint = "https://searchconsole.googleapis.com/webmasters/v3" )
Endpoints — overridable in tests.
Functions ¶
Types ¶
type Creds ¶
type Creds struct{ ClientID, ClientSecret string }
Creds is the BYO OAuth client (SMOLANALYTICS_GSC_CLIENT_ID / _SECRET).
func CredsFromEnv ¶
type PageRow ¶ added in v0.7.2
type PageRow struct {
Page string `json:"page"`
Query string `json:"query"`
Clicks int `json:"clicks"`
Impressions int `json:"impressions"`
Position float64 `json:"position"`
}
PageRow is one (page, query) pair's performance — the page-level cut that powers the money-pages report (quick wins, CTR problems, cannibalization).
type Row ¶
type Row struct {
Query string `json:"query"`
Clicks int `json:"clicks"`
Impressions int `json:"impressions"`
CTRPct float64 `json:"ctr_pct"`
Position float64 `json:"position"`
}
Row is one search query's performance.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) PageSnapshot ¶ added in v0.7.2
PageSnapshot returns the page-level rows plus the last page-fetch error (empty when the last page fetch succeeded — or never ran).
func (*Store) Poll ¶
Poll refreshes the cached rows if stale (12h). Safe to call on a timer. Queries land first; the page-level fetch is best-effort — a page failure never discards fresh query rows, it's recorded and surfaced in the report.
func (*Store) SetPageFetchError ¶ added in v0.7.2
SetPageFetchError records a page-level fetch failure without touching the cached rows, so the report can say "pages are stale/missing because X".
func (*Store) SetPageRows ¶ added in v0.7.2
SetPageRows stores the latest page-level rows; the prior fetch becomes PrevPageRows (mirroring Rows/PrevRows) and any recorded fetch error clears.