Phase 8 part 1: links that bring visitors

The daily Plausible import also reads the visitors by referring site,
linking page and entry page, with their sign-ups and leads (a new
referrer_days table). Search engines, social networks, AI assistants,
email and mail filters, work apps, the company's own sites and tagged
links are told apart from links on other sites. SEO → Links lists the
sites that sent visitors in 90 days, the pages they landed on and the
sign-ups they brought, new ones first. A linking page Plausible names
in full is kept as a known backlink (a new backlinks table, for parts 2
and 3); browsers mostly send only the site, so most aren't.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 08:23:47 -07:00
co-authored by Claude Opus 5.5
parent db0d079ee5
commit 392980aff6
10 changed files with 535 additions and 18 deletions
+26 -17
View File
@@ -173,23 +173,9 @@ func ImportPages(ctx context.Context, d *db.DB, c *plausible.Client, sites []str
if err != nil {
return save(d, "pages", res, fmt.Errorf("%s: %w", site, err))
}
var signups []plausible.Row
if len(set.Patterns) > 0 {
var pats []any
for _, p := range set.Patterns {
pats = append(pats, p)
}
signups, err = runAll(ctx, c, plausible.Query{SiteID: site, Metrics: []string{"visitors"}, DateRange: span, Dimensions: dims,
Filters: [][]any{{"is", "event:goal", []any{OutboundGoal}}, {"contains", "event:props:url", pats, map[string]any{"case_sensitive": false}}}})
if err != nil {
// Older Plausibles lack the case_sensitive modifier; patterns
// are stored in lower case, as links usually are.
signups, err = runAll(ctx, c, plausible.Query{SiteID: site, Metrics: []string{"visitors"}, DateRange: span, Dimensions: dims,
Filters: [][]any{{"is", "event:goal", []any{OutboundGoal}}, {"contains", "event:props:url", pats}}})
}
if err != nil {
return save(d, "pages", res, fmt.Errorf("%s: sign-ups: %w", site, err))
}
signups, err := signupRows(ctx, c, set, plausible.Query{SiteID: site, Metrics: []string{"visitors"}, DateRange: span, Dimensions: dims})
if err != nil {
return save(d, "pages", res, fmt.Errorf("%s: sign-ups: %w", site, err))
}
leads, err := runAll(ctx, c, plausible.Query{SiteID: site, Metrics: []string{"visitors"}, DateRange: span, Dimensions: dims,
Filters: [][]any{{"is", "event:goal", []any{LeadGoal}}}})
@@ -239,6 +225,29 @@ func ImportPages(ctx context.Context, d *db.DB, c *plausible.Client, sites []str
return save(d, "pages", res, nil)
}
// signupRows runs q for the visitors who clicked a sign-up link (none
// without a definition).
func signupRows(ctx context.Context, c *plausible.Client, set SignupSettings, q plausible.Query) ([]plausible.Row, error) {
if len(set.Patterns) == 0 {
return nil, nil
}
var pats []any
for _, p := range set.Patterns {
pats = append(pats, p)
}
base := q.Filters
q.Filters = append(append([][]any{}, base...), []any{"is", "event:goal", []any{OutboundGoal}},
[]any{"contains", "event:props:url", pats, map[string]any{"case_sensitive": false}})
rows, err := runAll(ctx, c, q)
if err != nil {
// Older Plausibles lack the case_sensitive modifier; patterns are
// stored in lower case, as links usually are.
q.Filters = append(append([][]any{}, base...), []any{"is", "event:goal", []any{OutboundGoal}}, []any{"contains", "event:props:url", pats})
rows, err = runAll(ctx, c, q)
}
return rows, err
}
// runAll runs a query through every page of its results.
func runAll(ctx context.Context, c *plausible.Client, q plausible.Query) ([]plausible.Row, error) {
const size = 10000