From 4dbd251c803584d892049d2a2b40bf2bea4c1b97 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 19:39:22 +0530 Subject: [PATCH] Showcase: filter zero-second bot sessions on every page, show total engaged hours The /api/traffic bot filter only caught 0-second homepage sessions, so a bot that loaded /showcase/ ~11,000 times on Nov 20-22 (0.4 engaged hours total) counted as visitors and squashed the visitors-per-day chart. Sessions whose views all had 0 engaged seconds are now dropped on any page when they're a first visit or have no referrer. Saved day summaries carry a version and are redone (4 a request, newest first) so past days pick up the new rule. The avg engaged time tile becomes total engaged hours. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016ZY4Ga2jzFB4HXTkDdJZCT --- e63334287a3deaa3/news-es.js | 3 +++ e63334287a3deaa3/news.js | 4 ++++ functions/api/traffic.js | 32 ++++++++++++++++++++++---------- showcase/index.html | 3 +-- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/e63334287a3deaa3/news-es.js b/e63334287a3deaa3/news-es.js index 2bce84dc..523f5161 100644 --- a/e63334287a3deaa3/news-es.js +++ b/e63334287a3deaa3/news-es.js @@ -6,6 +6,9 @@ (function () { if (!window.BackRoomLang) return; BackRoomLang.add({ + "Showcase traffic chart fixed": "Arreglado el gráfico de visitas de la vitrina", + "The visitors-per-day chart on the showcase page is readable again: a bot that loaded the page about 11,000 times in three days no longer counts as visitors.": "El gráfico de visitantes por día de la página de vitrina se puede leer otra vez: un bot que cargó la página unas 11.000 veces en tres días ya no cuenta como visitante.", + "The showcase now shows total engaged hours instead of the average engaged time.": "La vitrina ahora muestra el total de horas de uso activo en vez del tiempo medio.", "Putterby fixes": "Arreglos en Putterby", "Sliding gates no longer squash your ball through the rail and cost you an out-of-bounds stroke while you wait to putt.": "Las compuertas que se deslizan ya no empujan tu bola a través de la baranda ni te cuestan un golpe por salirte mientras esperas para tirar.", "On the daily hole, Card now shows the daily hole instead of an empty nine-hole card, and your result can't be closed by accident.": "En el hoyo del día, el botón Card ahora muestra el hoyo del día en vez de una tarjeta de nueve hoyos vacía, y tu resultado ya no se cierra por accidente.", diff --git a/e63334287a3deaa3/news.js b/e63334287a3deaa3/news.js index 12ed156e..7e469b79 100644 --- a/e63334287a3deaa3/news.js +++ b/e63334287a3deaa3/news.js @@ -85,6 +85,10 @@ */ (function () { var NEWS = [ + {date: '2026-11-25', version: '1.51.2', title: 'Showcase traffic chart fixed', kind: 'fix', + items: [ + 'The visitors-per-day chart on the showcase page is readable again: a bot that loaded the page about 11,000 times in three days no longer counts as visitors.', + 'The showcase now shows total engaged hours instead of the average engaged time.']}, {date: '2026-11-25', version: '1.51.1', title: 'Putterby fixes', kind: 'fix', tags: ['Putterby'], items: [ 'Sliding gates no longer squash your ball through the rail and cost you an out-of-bounds stroke while you wait to putt.', diff --git a/functions/api/traffic.js b/functions/api/traffic.js index ba52f8d7..f80308b7 100644 --- a/functions/api/traffic.js +++ b/functions/api/traffic.js @@ -7,11 +7,17 @@ // traffic_days/_latest the last answer; reused for 30 minutes, so most requests cost one read // Only this function (the service account) reads or writes traffic_days; the site's pages can't reach it. // -// Bot traffic: a session made only of 0-second homepage views with no referrer is left out (a burst of 3,158 such -// hits on 2026-10-28 was a bot). The homepage itself is left out of the top pages list. +// Bot traffic: a session whose every view had 0 engaged seconds is left out if it was a first visit or came with no +// referrer, on any page. Bots load a page for under 5 seconds with fresh storage, so they look exactly like that: a +// burst of 3,158 such homepage hits on 2026-10-28, and about 11,000 /showcase/ "visitors" on 2026-11-20..22 with 0.4 +// engaged hours between them, which flattened the showcase chart. The homepage is left out of the top pages list. +// +// VER: bump it whenever summarize() changes, so saved day summaries are worked out again with the new rules. At most +// REDO_MAX old days are redone per request (each costs that day's pageview reads); until they're all redone, the +// answer isn't saved to _latest, so the next requests carry on where this one stopped. import { cors, json, googleToken, DOCS, FS } from '../_lib.js'; -const DAYS = 30, FRESH_MS = 30 * 60 * 1000, DAY_MS = 86400000; +const DAYS = 30, FRESH_MS = 30 * 60 * 1000, DAY_MS = 86400000, VER = 2, REDO_MAX = 4; const NAMES = { 'rumble-karts': 'Rumble Karts', 'backrooms-1v1': 'Backrooms 1v1', 'hype-cycle': 'Hype Cycle Exchange', 'games': 'Web Development Projects page', 'productivity': 'Productivity page', 'phone-games': 'Phone games page', 'back-room': 'Back Room page' }; const label = k => NAMES[k] || k.split('-').map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(' '); @@ -34,20 +40,26 @@ export async function onRequestGet({ request, env }) { export async function traffic(env, fetchFn, now) { const auth = { Authorization: 'Bearer ' + await googleToken(env, fetchFn) }; const latest = await getDoc(fetchFn, auth, 'traffic_days/_latest'); - if (latest && now - latest.at < FRESH_MS) return latest.out; + if (latest && latest.ver === VER && now - latest.at < FRESH_MS) return latest.out; const today = dayKey(now), start = Date.parse(today) - (DAYS - 1) * DAY_MS; const keys = []; for (let i = 0; i < DAYS; i++) keys.push(dayKey(start + i * DAY_MS)); const past = keys.slice(0, -1), saved = await getDocs(fetchFn, auth, past.map(k => 'traffic_days/' + k)); const days = [], writes = []; - for (const k of past) { + let redone = 0, behind = false; + for (const k of past.slice().reverse()) { // newest first, so recent days are redone first let d = saved[k]; - if (!d) { d = summarize(await pageviews(fetchFn, auth, Date.parse(k), Date.parse(k) + DAY_MS)); writes.push(['traffic_days/' + k, d]); } - days.push(d); + const stale = d && d.ver !== VER; + if (!d || (stale && redone < REDO_MAX)) { + if (stale) redone++; + d = summarize(await pageviews(fetchFn, auth, Date.parse(k), Date.parse(k) + DAY_MS)); + writes.push(['traffic_days/' + k, d]); + } else if (stale) behind = true; + days.unshift(d); } days.push(summarize(await pageviews(fetchFn, auth, Date.parse(today), Date.parse(today) + DAY_MS))); const out = combine(days, today); - writes.push(['traffic_days/_latest', { at: now, out }]); + if (!behind) writes.push(['traffic_days/_latest', { at: now, ver: VER, out }]); await putDocs(fetchFn, auth, writes); return out; } @@ -56,9 +68,9 @@ export async function traffic(env, fetchFn, now) { export function summarize(rows) { const bySid = {}; for (const r of rows) (bySid[r.sid] = bySid[r.sid] || []).push(r); - const day = { pv: 0, dur: 0, s: 0, v: {}, sites: {} }; + const day = { ver: VER, pv: 0, dur: 0, s: 0, v: {}, sites: {} }; for (const sess of Object.values(bySid)) { - if (sess.every(r => r.site === 'home' && !r.dur && !r.ref)) continue; // bot-like: see the note at the top + if (sess.every(r => !r.dur) && (sess.some(r => r.nv) || sess.every(r => !r.ref))) continue; // bot-like: see the note at the top day.s++; const vid = sess[0].vid, v = day.v[vid] || (day.v[vid] = [0, 0, 0]); v[2]++; diff --git a/showcase/index.html b/showcase/index.html index a4f43ac4..e983215f 100644 --- a/showcase/index.html +++ b/showcase/index.html @@ -181,13 +181,12 @@

Hard problems I solved

['tiles','daily','sites'].forEach(id=>{document.getElementById(id).innerHTML=''}); const dash=document.getElementById('dash'); const n=v=>Number(v).toLocaleString('en-US'); - const dur=s=>s<60?s+'s':Math.floor(s/60)+'m '+(s%60)+'s'; const pct=(a,b)=>b?Math.round(100*a/b)+'%':'—'; const mk=(tag,cls,text)=>{const e=document.createElement(tag);if(cls)e.className=cls;if(text!=null)e.textContent=text;return e}; const tiles=[ ['Unique visitors',d&&n(d.visitors)], ['Pageviews',d&&n(d.pageviews)], - ['Avg engaged time',d&&dur(d.avgEngagedSec)], + ['Total engaged hours',d&&n(d.engagedHours)], ['Sessions',d&&n(d.sessions)], ['Returning visitors',d&&pct(d.returning,d.visitors)], ['On a phone',d&&pct(d.mobile,d.visitors)]