Add server-side web usage metrics with !petestats command

Track per-page/per-channel view counts and a privacy-preserving daily
unique-visitor estimate (salted IP+UA hash, salt rotated daily and never
persisted). No third-party analytics, no JS beacon. Surfaced via the
admin-gated !petestats Matrix command (named to avoid an existing !stats
bot in the rooms).
This commit is contained in:
prosolis
2026-06-22 01:54:34 -07:00
parent aaf6e551a0
commit e65ffb1373
8 changed files with 367 additions and 3 deletions

View File

@@ -123,6 +123,7 @@ func (s *Server) base(r *http.Request) pageData {
}
func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) {
s.track(r, "home")
const (
justPostedLimit = 6
latestLimit = 16
@@ -177,6 +178,7 @@ func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) {
}
func (s *Server) handleChannel(w http.ResponseWriter, r *http.Request, ch Channel) {
s.track(r, ch.Slug)
page := 1
if p := r.URL.Query().Get("page"); p != "" {
if n, err := strconv.Atoi(p); err == nil && n > 0 {