Add self-hosted usage analytics: pageview tracking + admin stats dashboard
Records pageviews (path, referrer, browser/OS/device, IP, GeoIP country) via a POST /api/track beacon into a new PageView table, and exposes aggregated daily/breakdown stats behind a token-gated GET /api/admin/stats endpoint with brute-force lockout. Frontend gets a /admin dashboard (charts + breakdown tables) built on recharts, with a switchable per-day pageviews chart. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+21
-2
@@ -1,6 +1,6 @@
|
||||
"""ORM modely: Player, Game, Guess.
|
||||
"""ORM modely: Player, Game, Guess, PageView.
|
||||
|
||||
Zamerne minimalne (3 tabulky). `won` sa neuklada -- vyplyva z `points > 0`
|
||||
`won` sa neuklada -- vyplyva z `points > 0`
|
||||
(trafeny tip = 10 + tip, inak 0; pozri Round.get_points_summary v bridzik.py).
|
||||
"""
|
||||
|
||||
@@ -83,3 +83,22 @@ class Guess(Base):
|
||||
round_number: Mapped[int] = mapped_column(Integer)
|
||||
guess: Mapped[int] = mapped_column(Integer)
|
||||
points: Mapped[int] = mapped_column(Integer)
|
||||
|
||||
|
||||
class PageView(Base):
|
||||
"""Jedna navsteva stranky (pre /track). Bez schema migracii -- create_all only."""
|
||||
|
||||
__tablename__ = "page_views"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
path: Mapped[str] = mapped_column(String(200))
|
||||
referrer: Mapped[str] = mapped_column(String(300), default="")
|
||||
user_agent: Mapped[str] = mapped_column(String(300), default="")
|
||||
browser: Mapped[str] = mapped_column(String(40), default="")
|
||||
os: Mapped[str] = mapped_column(String(40), default="")
|
||||
device_type: Mapped[str] = mapped_column(String(20), default="") # mobile/tablet/pc/bot
|
||||
ip: Mapped[str] = mapped_column(String(45), default="") # surova IP (IPv4/IPv6), "" ak nezname
|
||||
country: Mapped[str] = mapped_column(String(2), default="") # ISO kod z GeoIP, "" ak nerozlusene
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, server_default=func.now()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user