carlos / platform Public

console analytics: Top pages capped at 25 with a pages view; Named events removed

Paul, 2026-10-30: a crawler walked /posts/1.html..N.html and Top pages
listed every one. The tab now shows the first 25 pages and referrers; past
that, "See all N pages" opens ?show=pages for the same period: every page
grouped by its top folder (a folder holding only its own index joins the
top level), biggest group first, each page with its share and, over 7 or
30 days, a line of its days. A filter box narrows the list; the minute
refresh keeps the filter text and which groups are open. Period and day
links keep the view.

The read keeps each day's page counts (DaySummary.Pages, not in the API)
for those lines, only for the pages view: other views drop them before
the traffic memo holds a window, and the memo key carries the view.

Named events are removed from the tab: nothing on main sends them yet
(Meter.Track has no caller); carlos.js is later work.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 3d93a9c089eea1254f56cdbf425bf7e24d5d6fba parent 250e56e
8 files changed, +446 −23
  • internal/analytics/read.go +7 −0
  • internal/console/analyticsdisplay.go +160 −0
  • internal/console/analyticslive.go +31 −2
  • internal/console/analyticspages_test.go +133 −0
  • internal/console/analyticsview.go +29 −9
  • internal/console/apianalytics_test.go +1 −1
  • internal/console/templates/app_analytics.html +70 −11
  • internal/console/templates/layout.html +15 −0

CI cancelled — superseded by a newer push — run details

Intent

Human

<task-notification> <task-id>bq0g9sfc6</task-id> <tool-use-id>toolu_01A2bJ8PXrJht4HqonV8smSZ</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ce90495f-c7a7-490e-9b84-a6251050e87f/tasks/bq0g9sfc6.output</output-file> <status>completed</status> <summary>Background command "until s=$(amadan ci status carlos/platform -branch analytics-live 2&gt;&amp;1); echo "$s" | head -1 | grep -q '250e56e7' &amp;&amp; echo "$s" | head -1 | grep -q -E 'CI (passed|failed)'; do sleep 60; done; echo "$s" | head -1; echo "$s" | grep -A14 -E 'Failure summary|timed out' | head -25" completed (exit code 0)</summary> </task-notification>

diff --git a/internal/analytics/read.go b/internal/analytics/read.go
index af9cd99d9..255104ca3 100644
--- a/internal/analytics/read.go
+++ b/internal/analytics/read.go
@@ -24,6 +24,10 @@ type DaySummary struct {
Visitors int64 `json:"visitors"`
Hours [24]int64 `json:"hours"`
Restarted bool `json:"restarted"`
+ // Pages is the day's page views by page, merged across boxes and
+ // folded as the window's own Pages is. The console's pages view draws
+ // each page's days from it; the API leaves it out.
+ Pages map[string]int64 `json:"-"`
}
// Summary is what the tab and the API render: per-day rows plus totals.
@@ -79,6 +83,7 @@ func ReadRange(ctx context.Context, s release.Store, sqid, app string, from, to
for _, date := range Dates(from, to) {
ds := DaySummary{Date: date}
vis := &HLL{}
+ dayPages := NewTopK()
for _, box := range sum.Boxes {
key, err := DayKey(sqid, app, box, date)
if err != nil {
@@ -107,6 +112,7 @@ func ReadRange(ctx context.Context, s release.Store, sqid, app string, from, to
vis.Merge(v)
}
pages.Merge(TopKFrom(day.Pages))
+ dayPages.Merge(TopKFrom(day.Pages))
refs.Merge(TopKFrom(day.Referers))
events.Merge(TopKFrom(day.Events))
mergeCounts(countries, day.Countries, maxCountryKeys, nil)
@@ -119,6 +125,7 @@ func ReadRange(ctx context.Context, s release.Store, sqid, app string, from, to
if !vis.Empty() {
ds.Visitors = int64(math.Round(vis.Count()))
}
+ ds.Pages = dayPages.Fold()
sum.Days = append(sum.Days, ds)
sum.PV += ds.PV
sum.Bots += ds.Bots
diff --git a/internal/console/analyticsdisplay.go b/internal/console/analyticsdisplay.go
index 77af1e4ef..c29435826 100644
--- a/internal/console/analyticsdisplay.go
+++ b/internal/console/analyticsdisplay.go
@@ -15,6 +15,7 @@ package console
import (
"fmt"
"math"
+ "sort"
"strconv"
"strings"
"time"
@@ -466,3 +467,162 @@ func restartNote(days []analytics.DaySummary, now time.Time) string {
return fmt.Sprintf("The edge restarted on %d of these days. Counts it had not saved yet may be missing for each of them. Those days are marked under the chart.", n)
}
}
+
+// topRows is how many rows the tab's Top pages and Referrers show; the
+// pages view shows every page.
+const topRows = 25
+
+// capRows keeps the first n rows that are pages, referrers or countries,
+// and counts the rest (the overflow row included). The overflow row is the
+// last row sortedKV gives, so a cut list never shows "Everything else" for
+// a remainder it is not.
+func capRows(rows []shareRow, n int) ([]shareRow, int) {
+ if len(rows) <= n {
+ return rows, 0
+ }
+ return rows[:n], len(rows) - n
+}
+
+// pageSection is one group of the pages view: the pages under one top
+// folder, "/" for the pages at the top level.
+type pageSection struct {
+ Name string // "/blog/", or "/" for the top level
+ Label string // what the heading says
+ Views int64
+ Share string
+ Bar float64
+ Pages []pageRow
+ Count int64 // len(Pages), for the heading
+ Open bool // shown open: small groups, and the biggest
+}
+
+// pageRow is one page of a section, with its views on each day of the
+// window as Spark, the points of a small line ("" for a one-day view).
+type pageRow struct {
+ Path string
+ Label string
+ Views int64
+ Share string
+ Spark string
+ Muted bool
+}
+
+// sectionOf is the group a page belongs to: its first folder ("/blog/",
+// "/blog/post/" and "/blog/post.html" are all in "/blog/"), else the top
+// level ("/", "/ai.html"). buildPageSections folds a folder that holds only
+// its own index ("/faq/" alone) back into the top level. The overflow row
+// is a group of its own, last.
+func sectionOf(p string) string {
+ if p == analytics.OtherKey {
+ return analytics.OtherKey
+ }
+ rest := strings.TrimPrefix(p, "/")
+ i := strings.IndexByte(rest, '/')
+ if i < 0 {
+ return "/"
+ }
+ return "/" + rest[:i+1]
+}
+
+// buildPageSections groups every page of the window by sectionOf, biggest
+// group first, pages biggest first within a group. daily draws each page's
+// line from its days (a multi-day window); a one-day view has none.
+func buildPageSections(sum analytics.Summary, daily bool) []pageSection {
+ var total int64
+ for _, v := range sum.Pages {
+ total += v
+ }
+ if total == 0 {
+ return nil
+ }
+ bySection := map[string]*pageSection{}
+ var order []string
+ for _, kv := range sortedKV(sum.Pages) {
+ name := sectionOf(kv.Key)
+ sec, ok := bySection[name]
+ if !ok {
+ sec = &pageSection{Name: name, Label: name}
+ switch name {
+ case "/":
+ sec.Label = "Top level"
+ case analytics.OtherKey:
+ sec.Label = "Everything else"
+ }
+ bySection[name] = sec
+ order = append(order, name)
+ }
+ label, _, muted := pageLabel(kv.Key)
+ row := pageRow{Path: kv.Key, Label: label, Views: kv.Value, Share: sharePct(kv.Value, total), Muted: muted}
+ if daily && kv.Key != analytics.OtherKey {
+ row.Spark = pageSpark(kv.Key, sum.Days)
+ }
+ sec.Pages = append(sec.Pages, row)
+ sec.Views += kv.Value
+ }
+ out := make([]pageSection, 0, len(order))
+ var top *pageSection
+ for _, name := range order {
+ sec := bySection[name]
+ if name != "/" && len(sec.Pages) == 1 && sec.Pages[0].Path == name {
+ // A folder of one, its own index: a top-level page.
+ if top = bySection["/"]; top == nil {
+ top = &pageSection{Name: "/", Label: "Top level"}
+ bySection["/"] = top
+ order = append(order, "/")
+ }
+ top.Pages = append(top.Pages, sec.Pages[0])
+ top.Views += sec.Views
+ delete(bySection, name)
+ }
+ }
+ for _, name := range order {
+ if sec, ok := bySection[name]; ok {
+ sort.SliceStable(sec.Pages, func(i, j int) bool { return sec.Pages[i].Views > sec.Pages[j].Views })
+ out = append(out, *sec)
+ }
+ }
+ sort.SliceStable(out, func(i, j int) bool {
+ if a, b := out[i].Name == analytics.OtherKey, out[j].Name == analytics.OtherKey; a != b {
+ return b
+ }
+ return out[i].Views > out[j].Views
+ })
+ most := out[0].Views
+ for i := range out {
+ out[i].Count = int64(len(out[i].Pages))
+ out[i].Share = sharePct(out[i].Views, total)
+ out[i].Bar = round2(float64(out[i].Views) / float64(most) * 100)
+ out[i].Open = i == 0 || len(out[i].Pages) <= 10
+ }
+ return out
+}
+
+// pageSpark is a page's views on each day of days as polyline points on a
+// 60 x 16 box, scaled to its own busiest day. A page seen on one day only
+// still draws a line, flat but for that day.
+func pageSpark(p string, days []analytics.DaySummary) string {
+ if len(days) < 2 {
+ return ""
+ }
+ var peak int64
+ for _, d := range days {
+ if v := d.Pages[p]; v > peak {
+ peak = v
+ }
+ }
+ if peak == 0 {
+ return ""
+ }
+ var b strings.Builder
+ step := 60.0 / float64(len(days)-1)
+ for i, d := range days {
+ if i > 0 {
+ b.WriteByte(' ')
+ }
+ y := 15 - float64(d.Pages[p])/float64(peak)*14
+ b.WriteString(strconv.FormatFloat(round2(float64(i)*step), 'f', -1, 64))
+ b.WriteByte(',')
+ b.WriteString(strconv.FormatFloat(round2(y), 'f', -1, 64))
+ }
+ return b.String()
+}
diff --git a/internal/console/analyticslive.go b/internal/console/analyticslive.go
index 96bbdd1e7..3bcc12d4f 100644
--- a/internal/console/analyticslive.go
+++ b/internal/console/analyticslive.go
@@ -36,13 +36,26 @@ const analyticsDays = 30
type analyticsQuery struct {
Range string // today | 7d | 30d | day
Date string // YYYY-MM-DD when Range is day
+ Show string // "pages" for every page in the period; "" for the tab
}
+// showPages is the Show of the pages view.
+const showPages = "pages"
+
// parseAnalyticsQuery reads ?date and ?range. A date in the last 30 UTC days
// is that day; today's date is the today range; anything else falls back to
// the range, and an unknown range to today. A page never 400s over its own
// query string.
func parseAnalyticsQuery(q url.Values, now time.Time) analyticsQuery {
+ out := parsePeriod(q, now)
+ if q.Get("show") == showPages {
+ out.Show = showPages
+ }
+ return out
+}
+
+// parsePeriod is the period half of parseAnalyticsQuery.
+func parsePeriod(q url.Values, now time.Time) analyticsQuery {
if d := q.Get("date"); d != "" {
if t, err := time.Parse("2006-01-02", d); err == nil && t.Format("2006-01-02") == d {
today := now.UTC().Truncate(24 * time.Hour)
@@ -62,10 +75,26 @@ func parseAnalyticsQuery(q url.Values, now time.Time) analyticsQuery {
// values is the query as URL parameters, for the live door's address.
func (q analyticsQuery) values() url.Values {
+ v := url.Values{"range": {q.Range}}
if q.Range == rangeDay {
- return url.Values{"date": {q.Date}}
+ v = url.Values{"date": {q.Date}}
+ }
+ if q.Show != "" {
+ v.Set("show", q.Show)
}
- return url.Values{"range": {q.Range}}
+ return v
+}
+
+// PagesLink and TabLink are the query strings of this period's pages view
+// and of its tab, for the "See all" and "Back" links.
+func (q analyticsQuery) PagesLink() string {
+ q.Show = showPages
+ return "?" + q.values().Encode()
+}
+
+func (q analyticsQuery) TabLink() string {
+ q.Show = ""
+ return "?" + q.values().Encode()
}
// dayNeighbours are the days either side of date that can be opened: ""
diff --git a/internal/console/analyticspages_test.go b/internal/console/analyticspages_test.go
new file mode 100644
index 000000000..c06886ca8
--- /dev/null
+++ b/internal/console/analyticspages_test.go
@@ -0,0 +1,133 @@
+package console
+
+import (
+ "context"
+ "fmt"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/analytics"
+ "github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/telemetry"
+)
+
+func TestSectionOf(t *testing.T) {
+ for p, want := range map[string]string{
+ "/": "/",
+ "/ai.html": "/",
+ "/faq/": "/faq/",
+ "/blog/": "/blog/",
+ "/blog/deshittification/": "/blog/",
+ "/posts/27.html": "/posts/",
+ analytics.OtherKey: analytics.OtherKey,
+ } {
+ if got := sectionOf(p); got != want {
+ t.Errorf("sectionOf(%q) = %q, want %q", p, got, want)
+ }
+ }
+}
+
+// Pages group by top folder, biggest first; a folder holding only its own
+// index joins the top level; each page of a multi-day window has a line.
+func TestBuildPageSections(t *testing.T) {
+ pages := map[string]int64{"/": 20, "/faq/": 2, "/ai.html": 1, "/blog/": 1, "/blog/a/": 12, "/blog/b/": 4}
+ for i := 1; i <= 30; i++ {
+ pages[fmt.Sprintf("/posts/%d.html", i)] = 1
+ }
+ days := []analytics.DaySummary{{Date: "2026-10-28", Pages: map[string]int64{"/blog/a/": 2}}, {Date: "2026-10-29", Pages: map[string]int64{"/blog/a/": 10}}}
+ secs := buildPageSections(analytics.Summary{Pages: pages, Days: days}, true)
+ if len(secs) != 3 || secs[0].Name != "/posts/" || secs[1].Name != "/" || secs[2].Name != "/blog/" {
+ t.Fatalf("sections = %v", sectionNames(secs))
+ }
+ // The biggest group is open even with more than 10 pages; others that
+ // size start closed.
+ if secs[0].Count != 30 || secs[0].Views != 30 || !secs[0].Open {
+ t.Errorf("/posts/ = %d pages %d views open %v, want 30, 30, open", secs[0].Count, secs[0].Views, secs[0].Open)
+ }
+ top := secs[1]
+ if top.Label != "Top level" || top.Count != 3 || top.Pages[0].Path != "/" {
+ t.Errorf("top level = %+v", top)
+ }
+ blog := secs[2]
+ if blog.Count != 3 || blog.Pages[0].Path != "/blog/a/" || blog.Pages[0].Spark != "0,12.2 60,1" {
+ t.Errorf("/blog/ = %+v", blog)
+ }
+ if one := buildPageSections(analytics.Summary{Pages: pages, Days: days[:1]}, false); one[2].Pages[0].Spark != "" {
+ t.Error("a one-day view drew a line")
+ }
+}
+
+func sectionNames(secs []pageSection) []string {
+ var out []string
+ for _, s := range secs {
+ out = append(out, s.Name)
+ }
+ return out
+}
+
+// The tab shows 25 pages and a link to all of them; the pages view lists
+// every page by group, with a filter, and its period links keep the view.
+// Named events are gone from the tab.
+func TestAnalyticsPagesView(t *testing.T) {
+ fx, _ := instanceFixture(t, "code-analytics-pages")
+ when := seedTime()
+ m := analytics.NewMeter(t.TempDir(), "box1", func() time.Time { return when })
+ for i := 0; i < 30; i++ {
+ m.Observe(analytics.Obs{Acct: release.OpsAccount, App: "titogo", Host: "titogo.example.com", Method: "GET", Status: 200,
+ ContentType: "text/html", Path: fmt.Sprintf("/posts/%d.html", i), UA: "Mozilla/5.0 Safari", ClientIP: "203.0.113.9", When: when})
+ }
+ for k, ds := range m.Drain() {
+ for _, d := range ds {
+ if err := analytics.UpsertDay(context.Background(), fx.rel, k.Acct, k.App, d); err != nil {
+ t.Fatal(err)
+ }
+ }
+ }
+ if err := telemetry.Update(context.Background(), fx.rel, telemetry.AppKey(fx.sqid, "titogo"), func(st *telemetry.Settings) {
+ st.Analytics = &telemetry.Analytics{Count: telemetry.CountEdge}
+ }); err != nil {
+ t.Fatal(err)
+ }
+ fx.setUser("paul@keymail.dev")
+ c := newBrowser(t)
+ signUp(t, fx, c, "code-analytics-pages-browser")
+
+ _, _, body := get(t, c, fx.u("/apps/titogo/analytics?range=7d"))
+ if n := strings.Count(body, `<span class="an-key" title="/posts/`); n != topRows {
+ t.Errorf("tab shows %d pages, want %d", n, topRows)
+ }
+ if !strings.Contains(body, `href="?range=7d&amp;show=pages">See all 30 pages</a>`) {
+ t.Error("tab has no See all link")
+ }
+ if strings.Contains(body, "Named events") {
+ t.Error("tab still shows Named events")
+ }
+
+ _, _, body = get(t, c, fx.u("/apps/titogo/analytics?range=7d&show=pages"))
+ for _, want := range []string{"All pages", `data-section="/posts/"`, "30 pages", `data-filter`, `href="?range=7d">Back to the summary</a>`,
+ `href="?range=30d&show=pages"`, `data-path="/posts/29.html"`} {
+ if !strings.Contains(body, want) {
+ t.Errorf("pages view missing %q", want)
+ }
+ }
+ if n := strings.Count(body, `<li data-path="/posts/`); n != 30 {
+ t.Errorf("pages view lists %d pages, want 30", n)
+ }
+ // The live door answers the pages view too.
+ status, _, live := get(t, c, fx.u("/apps/titogo/analytics/live?view=tab&range=7d&show=pages"))
+ if status != 200 || !strings.Contains(live, "All pages") {
+ t.Errorf("live pages view = %d", status)
+ }
+}
+
+func TestCapRows(t *testing.T) {
+ rows := make([]shareRow, 30)
+ got, more := capRows(rows, 25)
+ if len(got) != 25 || more != 5 {
+ t.Fatalf("capRows = %d rows, %d more", len(got), more)
+ }
+ if got, more := capRows(rows[:3], 25); len(got) != 3 || more != 0 {
+ t.Fatalf("short list = %d rows, %d more", len(got), more)
+ }
+}
diff --git a/internal/console/analyticsview.go b/internal/console/analyticsview.go
index 8a8072f95..d47fc1acb 100644
--- a/internal/console/analyticsview.go
+++ b/internal/console/analyticsview.go
@@ -243,7 +243,6 @@ type analyticsWindow struct {
Insights []string
Pages []shareRow
Referers []shareRow
- Events []shareRow
// Countries is the top 10 plus the rest (geoip spec §9).
Countries []shareRow
// Restarts is restartNote's sentence, "" when no edge restarted.
@@ -251,6 +250,11 @@ type analyticsWindow struct {
// Date is the day a day view shows (Range "day"), with the days either
// side that can be opened (dayNeighbours).
Date, Prev, Next string
+ // PagesMore and ReferersMore are the rows past the tab's first 25,
+ // shown in full by the pages view (Sections) or counted.
+ PagesMore, ReferersMore int
+ PagesTotal int64 // pages counted, not the overflow row
+ Sections []pageSection
}
// HasData reports whether the window holds anything counted. With analytics
@@ -463,14 +467,23 @@ func (s *Server) readAnalyticsFor(ctx context.Context, sqid, app string, q analy
return out, nil
}
from, to := analyticsQuerySpan(q, now)
- key := sqid + "/" + app + "/" + rng + "/" + q.Date + "/" + now.UTC().Format("2006-01-02")
+ key := sqid + "/" + app + "/" + rng + "/" + q.Date + "/" + q.Show + "/" + now.UTC().Format("2006-01-02")
+ read := func() (analytics.Summary, error) {
+ sum, err := s.readAnalyticsRange(ctx, sqid, app, from, to, now)
+ // Each day's page counts are for the pages view's trends only: up
+ // to 500 pages a day is not worth holding for any other view.
+ if q.Show != showPages {
+ for i := range sum.Days {
+ sum.Days[i].Pages = nil
+ }
+ }
+ return sum, err
+ }
var sum analytics.Summary
if memo == nil {
- sum, err = s.readAnalyticsRange(ctx, sqid, app, from, to, now)
+ sum, err = read()
} else {
- sum, err = memo.load(ctx, key, now, func() (analytics.Summary, error) {
- return s.readAnalyticsRange(ctx, sqid, app, from, to, now)
- })
+ sum, err = memo.load(ctx, key, now, read)
}
if err != nil {
return out, err
@@ -486,9 +499,16 @@ func (s *Server) readAnalyticsFor(ctx context.Context, sqid, app string, q analy
}
out.Chart = buildTrafficChart(shape, sum, now)
out.Insights = analyticsInsights(shape, sum, now)
- out.Pages = shareRows(sum.Pages, pageLabel)
- out.Referers = shareRows(sum.Referers, refererLabel)
- out.Events = shareRows(sum.Events, pageLabel)
+ out.Pages, out.PagesMore = capRows(shareRows(sum.Pages, pageLabel), topRows)
+ out.Referers, out.ReferersMore = capRows(shareRows(sum.Referers, refererLabel), topRows)
+ for k := range sum.Pages {
+ if k != analytics.OtherKey {
+ out.PagesTotal++
+ }
+ }
+ if q.Show == showPages {
+ out.Sections = buildPageSections(sum, rng == range7d || rng == range30d)
+ }
out.Countries = shareRows(geoCountries(sum.Countries), countryLabel)
out.Restarts = restartNote(sum.Days, now)
return out, nil
diff --git a/internal/console/apianalytics_test.go b/internal/console/apianalytics_test.go
index 6abcf5a42..71aed18ae 100644
--- a/internal/console/apianalytics_test.go
+++ b/internal/console/apianalytics_test.go
@@ -170,7 +170,7 @@ func TestAppAnalyticsPage(t *testing.T) {
t.Fatalf("%d %s", status, body)
}
// Off: the switch and the reading, and the numbers that exist already.
- for _, want := range []string{"Analytics is off for this app", "No JavaScript, no cookie", "/pricing", "news.ycombinator.com", "signup", `class="an-chart an-chart-hour"`} {
+ for _, want := range []string{"Analytics is off for this app", "No JavaScript, no cookie", "/pricing", "news.ycombinator.com", `class="an-chart an-chart-hour"`} {
if !strings.Contains(body, want) {
t.Errorf("page missing %q", want)
}
diff --git a/internal/console/templates/app_analytics.html b/internal/console/templates/app_analytics.html
index 161c93e53..9daaa2149 100644
--- a/internal/console/templates/app_analytics.html
+++ b/internal/console/templates/app_analytics.html
@@ -37,13 +37,14 @@ When analytics is on, the edge counts HTML page views and daily visitors. No Jav
{{/* The numbers part of the tab: what a reload would show, and what the
live door (analyticslive.go) answers to the page's minute refresh. */}}
{{define "analyticsnav"}}<nav class="an-range" aria-label="Period">
- <a href="?range=today"{{if eq .Query.Range "today"}} aria-current="page"{{end}}>Today</a>
- <a href="?range=7d"{{if eq .Query.Range "7d"}} aria-current="page"{{end}}>7 days</a>
- <a href="?range=30d"{{if eq .Query.Range "30d"}} aria-current="page"{{end}}>30 days</a>
+ {{/* The view is kept as literal text: a value spliced into a query
+ string is escaped as data, which would turn the & into %26. */}}{{$p := eq .Query.Show "pages"}}<a href="?range=today{{if $p}}&show=pages{{end}}"{{if eq .Query.Range "today"}} aria-current="page"{{end}}>Today</a>
+ <a href="?range=7d{{if $p}}&show=pages{{end}}"{{if eq .Query.Range "7d"}} aria-current="page"{{end}}>7 days</a>
+ <a href="?range=30d{{if $p}}&show=pages{{end}}"{{if eq .Query.Range "30d"}} aria-current="page"{{end}}>30 days</a>
{{with .Win}}{{if .Span}}<span class="an-span">{{.Span}}</span>{{end}}
{{if eq .Range "day"}}<span class="an-daynav">
- {{if .Prev}}<a href="?date={{.Prev}}">Previous day</a>{{end}}
- {{if eq .Next "today"}}<a href="?range=today">Next day</a>{{else if .Next}}<a href="?date={{.Next}}">Next day</a>{{end}}
+ {{if .Prev}}<a href="?date={{.Prev}}{{if $p}}&show=pages{{end}}">Previous day</a>{{end}}
+ {{if eq .Next "today"}}<a href="?range=today{{if $p}}&show=pages{{end}}">Next day</a>{{else if .Next}}<a href="?date={{.Next}}{{if $p}}&show=pages{{end}}">Next day</a>{{end}}
</span>{{end}}{{end}}
</nav>{{end}}
@@ -56,15 +57,18 @@ When analytics is on, the edge counts HTML page views and daily visitors. No Jav
<p class="an-empty">No page views in this period.</p>
{{end}}
{{template "trafficquality" .}}
+{{if eq $.Query.Show "pages"}}{{template "analyticspages" $}}{{else}}
<div class="an-breakdowns">
<section class="an-card" aria-labelledby="an-pages">
<h3 id="an-pages">Top pages</h3>
{{template "sharelist" .Pages}}
+ {{if .PagesMore}}<p class="an-more"><a href="{{$.Query.PagesLink}}">See all {{count .PagesTotal}} pages</a></p>{{end}}
{{if .Sum.PagesApprox}}<p class="small">Approximate: more than 500 different pages were viewed.</p>{{end}}
</section>
<section class="an-card" aria-labelledby="an-referers">
<h3 id="an-referers">Referrers</h3>
{{template "sharelist" .Referers}}
+ {{if .ReferersMore}}<p class="small">{{count .ReferersMore}} more referrer{{if ne .ReferersMore 1}}s{{end}} not shown.</p>{{end}}
{{if .Sum.ReferersApprox}}<p class="small">Approximate: more than 500 referrers were seen.</p>{{end}}
</section>
<section class="an-card" aria-labelledby="an-countries">
@@ -72,16 +76,38 @@ When analytics is on, the edge counts HTML page views and daily visitors. No Jav
{{if .Countries}}{{template "sharelist" .Countries}}{{else}}<p class="small">No country data for this period.</p>{{end}}
{{range geoAttributions .Sum.GeoSources}}<p class="small"><a href="{{.URL}}">{{.Text}}</a></p>{{end}}
</section>
- <section class="an-card" aria-labelledby="an-events">
- <h3 id="an-events">Named events</h3>
- {{template "sharelist" .Events}}
- {{if .Sum.EventsApprox}}<p class="small">Approximate: more than 500 event names were seen.</p>{{end}}
- </section>
-</div>
+</div>{{end}}
{{end}}
<p class="small">Updated {{.Updated}}. Times are UTC.{{if ne .Query.Range "day"}} The same view from a terminal: <code>carlos analytics --app {{.AppName}} --range {{.Query.Range}}</code>.{{end}}</p>
{{end}}
+{{/* Every page of the period, grouped by top folder, each with its share
+ and, over several days, a line of its days. A filter box narrows the
+ list in place (analyticsscript). */}}
+{{define "analyticspages"}}{{with .Win}}
+<section class="an-pages" aria-labelledby="an-allpages">
+ <div class="an-pages-head">
+ <h3 id="an-allpages">All pages</h3>
+ <a href="{{$.Query.TabLink}}">Back to the summary</a>
+ </div>
+ {{if .Sections}}
+ <input type="search" class="an-filter" placeholder="Filter pages" aria-label="Filter pages" data-filter>
+ {{range .Sections}}
+ <details class="an-section" data-section="{{.Name}}"{{if .Open}} open{{end}}>
+ <summary><span class="an-key">{{.Label}}</span><span class="an-val">{{count .Views}}</span><span class="an-pct">{{.Share}}</span><span class="an-count">{{count .Count}} page{{if ne .Count 1}}s{{end}}</span></summary>
+ <ol class="an-share an-pagelist">{{range .Pages}}<li data-path="{{.Path}}"{{if .Muted}} class="an-muted"{{end}}>
+ <span class="an-key" title="{{.Path}}">{{.Label}}</span>
+ {{if .Spark}}<svg class="an-spark" viewBox="0 0 60 16" aria-hidden="true"><polyline points="{{.Spark}}"/></svg>{{else}}<span></span>{{end}}
+ <span class="an-val">{{count .Views}}</span>
+ <span class="an-pct">{{.Share}}</span>
+ </li>{{end}}</ol>
+ </details>
+ {{end}}
+ {{if .Sum.PagesApprox}}<p class="small">Approximate: more than 500 different pages were viewed.</p>{{end}}
+ {{else}}<p class="small">Nothing yet.</p>{{end}}
+</section>
+{{end}}{{end}}
+
{{/* The Overview's traffic card body, refreshed the same way. */}}
{{define "trafficcard"}}
{{if .Slow}}
@@ -179,7 +205,29 @@ When analytics is on, the edge counts HTML page views and daily visitors. No Jav
});
});
}
+ // The pages view's filter: rows whose path does not contain the text are
+ // hidden, groups with none left are hidden, groups with a match open.
+ function initFilter(root) {
+ var f = root.querySelector("[data-filter]");
+ if (!f) return;
+ function apply() {
+ var q = f.value.trim().toLowerCase();
+ root.querySelectorAll(".an-section").forEach(function (sec) {
+ var shown = 0;
+ sec.querySelectorAll("li[data-path]").forEach(function (li) {
+ var hit = !q || li.getAttribute("data-path").toLowerCase().indexOf(q) >= 0;
+ li.hidden = !hit;
+ if (hit) shown++;
+ });
+ sec.hidden = shown === 0;
+ if (q && shown) sec.open = true;
+ });
+ }
+ f.addEventListener("input", apply);
+ apply();
+ }
initCharts(document);
+ initFilter(document);
if (window.anLive || !window.fetch) return;
window.anLive = true;
var lastInput = Date.now(), lastRun = Date.now();
@@ -197,8 +245,19 @@ When analytics is on, the edge counts HTML page views and daily visitors. No Jav
.then(function (r) { return r.ok && r.headers.get("X-Carlos-Live") === "1" ? r.text() : null; })
.then(function (html) {
if (html === null || busy(el)) return;
+ // Keep what the reader set: the filter text and which groups are open.
+ var f = el.querySelector("[data-filter]"), q = f ? f.value : "";
+ var open = {};
+ el.querySelectorAll(".an-section").forEach(function (s) { open[s.getAttribute("data-section")] = s.open; });
el.innerHTML = html;
+ el.querySelectorAll(".an-section").forEach(function (s) {
+ var k = s.getAttribute("data-section");
+ if (k in open) s.open = open[k];
+ });
+ var nf = el.querySelector("[data-filter]");
+ if (nf) nf.value = q;
initCharts(el);
+ initFilter(el);
})
.catch(function () {});
});
diff --git a/internal/console/templates/layout.html b/internal/console/templates/layout.html
index 904ca0731..17fec0605 100644
--- a/internal/console/templates/layout.html
+++ b/internal/console/templates/layout.html
@@ -774,6 +774,21 @@
.an-muted .an-key { color: var(--muted); }
.an-muted .an-track span { background: var(--muted); opacity: 0.5; }
+ .an-more { margin: 0.6rem 0 0; font-size: 0.9rem; }
+ .an-pages { margin: 0 0 2rem; }
+ .an-pages-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin: 0 0 0.8rem; }
+ .an-pages-head h3 { font-size: 1rem; margin: 0; }
+ input.an-filter { width: 100%; max-width: 24rem; margin: 0 0 1rem; }
+ .an-section { border-bottom: 1px solid var(--rule); }
+ .an-section summary {
+ display: grid; grid-template-columns: minmax(0, 1fr) auto 3rem 5.5rem; column-gap: 0.75rem;
+ align-items: baseline; padding: 0.55rem 0; cursor: pointer; font-weight: 600;
+ }
+ .an-section summary .an-count { color: var(--muted); font-size: 0.85rem; font-weight: 400; text-align: right; }
+ .an-pagelist { margin: 0 0 0.75rem 1rem; }
+ .an-pagelist li { grid-template-columns: minmax(0, 1fr) 60px auto 3rem; }
+ .an-spark { width: 60px; height: 16px; align-self: center; }
+ .an-spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.an-overview { margin: 0 0 2rem; padding: 1.25rem 1.4rem 1.4rem; border: 1px solid var(--rule); border-radius: 0.6rem; }
.an-overview-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin: 0 0 1rem; }
.an-overview-head h2 { font-size: 1rem; margin: 0; }