Documentation
¶
Overview ¶
Package gsc is a small client for the Google Search Console Search Analytics API.
Index ¶
- Constants
- func DefaultRange(now time.Time) (start, end string)
- type APIError
- type AggregationType
- type AmpInspectionResult
- type AmpIssue
- type Client
- func (c *Client) AddSite(ctx context.Context, site string) error
- func (c *Client) Dates(ctx context.Context, siteURL, start, end string, t SearchType) ([]Row, error)
- func (c *Client) DeleteSite(ctx context.Context, site string) error
- func (c *Client) DeleteSitemap(ctx context.Context, site, feed string) error
- func (c *Client) GetSite(ctx context.Context, site string) (*Site, error)
- func (c *Client) GetSitemap(ctx context.Context, site, feed string) (*Sitemap, error)
- func (c *Client) InspectURL(ctx context.Context, req InspectRequest) (*InspectionResult, error)
- func (c *Client) ListSitemaps(ctx context.Context, site, sitemapIndex string) ([]Sitemap, error)
- func (c *Client) Query(ctx context.Context, siteURL string, req QueryRequest) (*QueryResponse, error)
- func (c *Client) QueryAll(ctx context.Context, siteURL string, req QueryRequest, maxRows int) (*QueryResponse, error)
- func (c *Client) Sites(ctx context.Context) ([]Site, error)
- func (c *Client) SubmitSitemap(ctx context.Context, site, feed string) error
- type DataState
- type DetectedItems
- type Dimension
- type Filter
- type FilterGroup
- type IndexStatusInspectionResult
- type InspectRequest
- type InspectionResult
- type Item
- type Metadata
- type MobileUsabilityInspectionResult
- type MobileUsabilityIssue
- type Operator
- type Option
- type QueryRequest
- type QueryResponse
- type RichResultsInspectionResult
- type RichResultsIssue
- type Row
- type SearchType
- type Site
- type Sitemap
- type SitemapContent
Constants ¶
const ( ScopeReadOnly = "https://www.googleapis.com/auth/webmasters.readonly" ScopeFull = "https://www.googleapis.com/auth/webmasters" )
OAuth scopes supported by Search Console.
const DefaultBaseURL = "https://www.googleapis.com/webmasters/v3"
DefaultBaseURL is the Search Console webmasters v3 endpoint.
const DefaultInspectionBaseURL = "https://searchconsole.googleapis.com/v1"
DefaultInspectionBaseURL is the URL Inspection v1 endpoint.
const MaxRowLimit = 25000
MaxRowLimit is the largest rowLimit the API accepts.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APIError ¶
type APIError struct {
HTTPStatus int
Code int `json:"code"`
Message string `json:"message"`
Status string `json:"status"`
}
APIError is a Google API error response.
type AggregationType ¶
type AggregationType string
AggregationType controls how rows are aggregated.
const ( AggAuto AggregationType = "auto" AggByPage AggregationType = "byPage" AggByProperty AggregationType = "byProperty" AggByNewsShowcasePanel AggregationType = "byNewsShowcasePanel" )
type AmpInspectionResult ¶
type AmpInspectionResult struct {
Issues []AmpIssue `json:"issues,omitempty"`
Verdict string `json:"verdict,omitempty"`
AmpURL string `json:"ampUrl,omitempty"`
RobotsTxtState string `json:"robotsTxtState,omitempty"`
IndexingState string `json:"indexingState,omitempty"`
AmpIndexStatusVerdict string `json:"ampIndexStatusVerdict,omitempty"`
LastCrawlTime string `json:"lastCrawlTime,omitempty"`
PageFetchState string `json:"pageFetchState,omitempty"`
}
AmpInspectionResult mirrors the Search Console API resource. Enum values are API strings.
type AmpIssue ¶
type AmpIssue struct {
IssueMessage string `json:"issueMessage,omitempty"`
Severity string `json:"severity,omitempty"`
}
AmpIssue mirrors the Search Console API resource. Enum values are API strings.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the Search Console API. The HTTP client must add auth (for example an oauth2.Client).
func New ¶
New returns a Client using an authenticated HTTP client.
func (*Client) AddSite ¶
AddSite adds a property to the user's sites.
func (*Client) Dates ¶
func (c *Client) Dates(ctx context.Context, siteURL, start, end string, t SearchType) ([]Row, error)
Dates returns the days with data in the range, the recommended first check.
func (*Client) DeleteSite ¶
DeleteSite removes a property from the user's sites.
func (*Client) DeleteSitemap ¶
DeleteSitemap deletes a sitemap submission.
func (*Client) GetSite ¶
GetSite retrieves a property.
func (*Client) GetSitemap ¶
GetSitemap retrieves a sitemap.
func (*Client) InspectURL ¶
func (c *Client) InspectURL(ctx context.Context, req InspectRequest) (*InspectionResult, error)
InspectURL inspects Google's indexed version of a URL (not a live test).
func (*Client) ListSitemaps ¶
ListSitemaps lists submitted sitemaps, optionally within an index.
func (*Client) Query ¶
func (c *Client) Query(ctx context.Context, siteURL string, req QueryRequest) (*QueryResponse, error)
Query runs one searchAnalytics.query call.
func (*Client) QueryAll ¶
func (c *Client) QueryAll(ctx context.Context, siteURL string, req QueryRequest, maxRows int) (*QueryResponse, error)
QueryAll pages through results with startRow in MaxRowLimit batches. It stops on a short or empty page, or once maxRows rows are collected (maxRows <= 0 means no cap). Metadata comes from the first page.
func (*Client) Sites ¶
Sites lists the properties visible to the user.
type DetectedItems ¶
type DetectedItems struct {
Items []Item `json:"items,omitempty"`
RichResultType string `json:"richResultType,omitempty"`
}
DetectedItems mirrors the Search Console API resource. Enum values are API strings.
type Filter ¶
type Filter struct {
Dimension Dimension `json:"dimension"`
Operator Operator `json:"operator,omitempty"`
Expression string `json:"expression"`
}
Filter matches one dimension. Operator defaults to equals.
func ParseFilter ¶
ParseFilter parses "dim op expr" or "dim=expr". The expression may contain spaces, e.g. "query contains seo tools".
type FilterGroup ¶
type FilterGroup struct {
GroupType string `json:"groupType,omitempty"`
Filters []Filter `json:"filters"`
}
FilterGroup is a set of filters that must all match ("and").
func AndGroup ¶
func AndGroup(filters ...Filter) []FilterGroup
AndGroup builds one "and" group, or nil when filters is empty.
type IndexStatusInspectionResult ¶
type IndexStatusInspectionResult struct {
Sitemap []string `json:"sitemap,omitempty"`
ReferringURLs []string `json:"referringUrls,omitempty"`
Verdict string `json:"verdict,omitempty"`
CoverageState string `json:"coverageState,omitempty"`
RobotsTxtState string `json:"robotsTxtState,omitempty"`
IndexingState string `json:"indexingState,omitempty"`
LastCrawlTime string `json:"lastCrawlTime,omitempty"`
PageFetchState string `json:"pageFetchState,omitempty"`
GoogleCanonical string `json:"googleCanonical,omitempty"`
UserCanonical string `json:"userCanonical,omitempty"`
CrawledAs string `json:"crawledAs,omitempty"`
}
IndexStatusInspectionResult mirrors the Search Console API resource. Enum values are API strings.
type InspectRequest ¶
type InspectRequest struct {
InspectionURL string `json:"inspectionUrl,omitempty"`
SiteURL string `json:"siteUrl,omitempty"`
LanguageCode string `json:"languageCode,omitempty"`
}
InspectRequest mirrors the Search Console API resource. Enum values are API strings.
type InspectionResult ¶
type InspectionResult struct {
InspectionResultLink string `json:"inspectionResultLink,omitempty"`
IndexStatusResult *IndexStatusInspectionResult `json:"indexStatusResult,omitempty"`
AmpResult *AmpInspectionResult `json:"ampResult,omitempty"`
MobileUsabilityResult *MobileUsabilityInspectionResult `json:"mobileUsabilityResult,omitempty"`
RichResultsResult *RichResultsInspectionResult `json:"richResultsResult,omitempty"`
}
InspectionResult mirrors the Search Console API resource. Enum values are API strings.
type Item ¶
type Item struct {
Issues []RichResultsIssue `json:"issues,omitempty"`
Name string `json:"name,omitempty"`
}
Item mirrors the Search Console API resource. Enum values are API strings.
type Metadata ¶
type Metadata struct {
FirstIncompleteDate string `json:"first_incomplete_date,omitempty"`
FirstIncompleteHour string `json:"first_incomplete_hour,omitempty"`
}
Metadata marks where fresh data is still incomplete (America/Los_Angeles).
type MobileUsabilityInspectionResult ¶
type MobileUsabilityInspectionResult struct {
Issues []MobileUsabilityIssue `json:"issues,omitempty"`
Verdict string `json:"verdict,omitempty"`
}
MobileUsabilityInspectionResult mirrors the Search Console API resource. Enum values are API strings.
type MobileUsabilityIssue ¶
type MobileUsabilityIssue struct {
IssueType string `json:"issueType,omitempty"`
Severity string `json:"severity,omitempty"`
Message string `json:"message,omitempty"`
}
MobileUsabilityIssue mirrors the Search Console API resource. Enum values are API strings.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithBaseURL ¶
WithBaseURL overrides the API base URL (useful for tests).
type QueryRequest ¶
type QueryRequest struct {
StartDate string `json:"startDate"`
EndDate string `json:"endDate"`
Dimensions []Dimension `json:"dimensions,omitempty"`
Type SearchType `json:"type,omitempty"`
DimensionFilterGroups []FilterGroup `json:"dimensionFilterGroups,omitempty"`
AggregationType AggregationType `json:"aggregationType,omitempty"`
RowLimit int `json:"rowLimit,omitempty"`
StartRow int `json:"startRow,omitempty"`
DataState DataState `json:"dataState,omitempty"`
}
QueryRequest is the searchAnalytics.query request body. Dates use YYYY-MM-DD in Pacific Time and are inclusive.
func (QueryRequest) Validate ¶
func (r QueryRequest) Validate() error
Validate checks the request before it is sent.
type QueryResponse ¶
type QueryResponse struct {
Rows []Row `json:"rows"`
ResponseAggregationType string `json:"responseAggregationType,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
}
QueryResponse is the searchAnalytics.query response body.
type RichResultsInspectionResult ¶
type RichResultsInspectionResult struct {
DetectedItems []DetectedItems `json:"detectedItems,omitempty"`
Verdict string `json:"verdict,omitempty"`
}
RichResultsInspectionResult mirrors the Search Console API resource. Enum values are API strings.
type RichResultsIssue ¶
type RichResultsIssue struct {
IssueMessage string `json:"issueMessage,omitempty"`
Severity string `json:"severity,omitempty"`
}
RichResultsIssue mirrors the Search Console API resource. Enum values are API strings.
type Row ¶
type Row struct {
Keys []string `json:"keys"`
Clicks float64 `json:"clicks"`
Impressions float64 `json:"impressions"`
CTR float64 `json:"ctr"`
Position float64 `json:"position"`
}
Row is one result row. Keys follow the requested dimension order.
type SearchType ¶
type SearchType string
SearchType selects the Google Search surface.
const ( TypeWeb SearchType = "web" TypeImage SearchType = "image" TypeVideo SearchType = "video" TypeNews SearchType = "news" TypeDiscover SearchType = "discover" TypeGoogleNews SearchType = "googleNews" )
type Site ¶
type Site struct {
SiteURL string `json:"siteUrl"`
PermissionLevel string `json:"permissionLevel"`
}
Site is a Search Console property visible to the user.
type Sitemap ¶
type Sitemap struct {
Path string `json:"path,omitempty"`
LastSubmitted string `json:"lastSubmitted,omitempty"`
IsPending bool `json:"isPending"`
IsSitemapsIndex bool `json:"isSitemapsIndex"`
Type string `json:"type,omitempty"`
LastDownloaded string `json:"lastDownloaded,omitempty"`
Warnings string `json:"warnings,omitempty"`
Errors string `json:"errors,omitempty"`
Contents []SitemapContent `json:"contents,omitempty"`
}
Sitemap mirrors the Search Console API resource. Counters use plain strings to preserve the API int64 JSON representation.
Source Files
¶
- client.go
- endpoints.go
- filter.go
- resources.go
- types.go
- validate.go