Documentation
¶
Overview ¶
Package analyticsync copies what each connected analytics tool reports into Postgres, one row per site, report, day and key, so people and agents can query history, compare tools for the same website and add numbers up without calling the providers each time.
A connection's first run stores the last 90 days of traffic and the last 7 days of top pages, sources, search queries and events. Later runs re-read the last few days, because providers keep revising recent numbers (Search Console lags by two to three days). Runs are spaced so each tool stays well inside its rate limits.
Index ¶
- Constants
- func AskedNow(ctx context.Context) context.Context
- func BotToken(userAgent string) string
- func Enqueue(ctx context.Context, q jobs.Querier, ws, integrationID, key string) (int64, error)
- func Host(raw string) string
- func HostOf(site connectors.AnalyticsSite) string
- type Config
- type ConversionResult
- type Result
- type SearchResult
- type SiteConfig
- type SitePlan
- type Syncer
Constants ¶
const ( JobSync = "analytics.sync" // MaxSites is how many of a login's sites sync without being switched // on one by one; the rest are listed but off. MaxSites = 20 )
Variables ¶
This section is empty.
Functions ¶
func AskedNow ¶ added in v0.110.0
AskedNow marks a sync someone asked for, rather than a scheduled one: it also re-reads what a scheduled run reads once a day (the sitemaps).
func Enqueue ¶
Enqueue asks for a sync of one connection. Key de-duplicates; "" is a sync someone asked for now.
func Host ¶
Host turns a site address into the domain that lines it up across tools: "https://www.Example.com/" and "sc-domain:example.com" are both example.com. It returns "" when the text is not a domain.
func HostOf ¶
func HostOf(site connectors.AnalyticsSite) string
HostOf finds the domain of a tool's site from its address, id or name.
Types ¶
type Config ¶
type Config struct {
Site string `json:"site"`
Domain string `json:"domain"`
Sites []SiteConfig `json:"sites"`
}
Config is the part of a connection's config about sites. Site is the default for live reports; Domain is its domain from before connections read several sites.
func ParseConfig ¶
ParseConfig reads the site settings from a connection's config.
type ConversionResult ¶
ConversionResult is what one site's conversions sync stored.
type SearchResult ¶
type SearchResult struct {
Days int `json:"days"`
Rows int `json:"rows"`
Inspected int `json:"inspected"`
Sitemaps int `json:"sitemaps"`
}
SearchResult is what one property's page by page run did.
type SiteConfig ¶
type SiteConfig struct {
ID string `json:"id"`
Domain string `json:"domain,omitempty"`
Off bool `json:"off,omitempty"`
ConversionEvents []string `json:"conversion_events,omitempty"`
// FilterTestAccounts leaves out the tool's own internal and test users
// (PostHog's project filters).
FilterTestAccounts bool `json:"filter_test_accounts,omitempty"`
}
SiteConfig is one site's settings on a connection: the domain that lines it up with other tools when the tool shows none, whether the sync leaves it out, and the events that count as conversions.
type SitePlan ¶
type SitePlan struct {
connectors.AnalyticsSite
// Host is the domain the site lines up under; "" when unknown.
Host string `json:"host"`
// Domain is the domain someone set, overriding the tool's own.
Domain string `json:"domain"`
Sync bool `json:"sync"`
// ConversionEvents are the events that count as a conversion when
// visits are counted by landing page.
ConversionEvents []string `json:"conversion_events"`
// FilterTestAccounts: reports leave out the tool's internal and test
// users.
FilterTestAccounts bool `json:"filter_test_accounts"`
}
SitePlan is one site a connection can read, the domain it counts under, and whether the sync stores it.
func Plan ¶
func Plan(cfg Config, sites []connectors.AnalyticsSite) []SitePlan
Plan lines up the sites a tool lists with the connection's settings. Every site syncs unless switched off, up to MaxSites; sites past that sync only when switched on.
type Syncer ¶
type Syncer struct {
Pool *pgxpool.Pool
Store *connectors.Store
Log *slog.Logger
// Now is the clock; tests set it.
Now func() time.Time
}
Syncer runs analytics syncs as jobs.