Changeset bb82e7f in Klonkt for src/services


Ignore:
Timestamp:
06/20/2026 12:29:15 PM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
bc83cc8
Parents:
92bad27
Message:

feat(stats): bot filter + clear labels (visitor-days ≠ unique visitors)

  • recordPageview/recordPostView now skip known bots/crawlers + empty-UA scripts (BOT_RE) → less inflated views/visitor-days.
  • Label "Bezoekers (Nd)" → "Visitor-days (Nd)" (it is the sum of daily uniques, not unique persons). Chart legend + tooltip updated accordingly. Expandable "What do these numbers mean?" explanation added.

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/services/StatsService.js

    r92bad27 rbb82e7f  
    4545}
    4646
     47// Bekende bots/crawlers + link-preview-fetchers + scripts overslaan, zodat ze de
     48// weergaven/bezoeker-dagen niet opblazen. Geen UA = vrijwel altijd geautomatiseerd.
     49const BOT_RE = /bot|crawl|spider|slurp|mediapartners|bingpreview|facebookexternalhit|whatsapp|telegram|discord|twitter|linkedin|embedly|pinterest|redditbot|applebot|petalbot|yandex|baidu|duckduckbot|semrush|ahrefs|mj12|dotbot|uptimerobot|pingdom|statuscake|headless|lighthouse|gptbot|claude|ccbot|perplexity|bytespider|amazonbot|googleother|google-read-aloud|python-requests|scrapy|curl|wget|axios|node-fetch|go-http|java\/|okhttp|libwww|httpclient/i;
     50function isBot(req) {
     51  const ua = (req && req.headers && req.headers['user-agent']) || '';
     52  if (!ua) return true;          // lege UA = script/bot
     53  return BOT_RE.test(ua);
     54}
     55
    4756// Lazy prepares — tabellen bestaan pas ná initializeDatabase(); dit module wordt
    4857// geïmporteerd vóór die call.
     
    8190
    8291export function recordPageview(siteId, req) {
    83   if (!siteId || isOperator(req)) return;
     92  if (!siteId || isOperator(req) || isBot(req)) return;
    8493  try {
    8594    const d = today();
     
    91100
    92101export function recordPostView(post, req) {
    93   if (!post || !post.id || isOperator(req)) return;
     102  if (!post || !post.id || isOperator(req) || isBot(req)) return;
    94103  try {
    95104    stmts().bumpPost.run(post.id);
Note: See TracChangeset for help on using the changeset viewer.