openvibers/openvibe.report Commits

Traffic: each site's people counted twice, by the server log and in the browser

OP OpenVibers committed 6 h ago · d69b3a1bec · 4 files, +58 −4

Plan AD.40 step 4 ("one people number"). The sites table on /traffic and /api/v1/traffic gain "Opened in a browser"
(browser_pages): the pages Network's page beacon saw a browser run on that site over the same days (report_metric_days
pageviews by site, matched to the host through report_dimensions). The server log's People counts anything that asks
like a browser; this counts pages a browser actually ran, so the two side by side show headless and disguised
fetchers. A site the beacon never saw shows a dash (null), not a zero. Report's tables get 4- and 6-column grids (the
Right now table was 4 columns on a 5-column grid). Test: traffic-browser; traffic and traffic-now unchanged.

Changes

ddiff --git a/public/css/app.css b/public/css/app.css
iindex 74dfe75..c8f2358 100644
---- a/public/css/app.css
++++ b/public/css/app.css
@@@ -103,6 +103,8 @@ html, body { margin: 0; background: var(--bg-primary, #0a0f1c); color: var(--tex
.rp-table { display: grid; border: 1px solid var(--border, #1f2d47); border-radius: 16px; overflow: hidden; background: var(--bg-card, #0f1729); }
.rp-tr { display: grid; grid-template-columns: minmax(0, 1.4fr) repeat(4, minmax(0, 1fr)); gap: 12px; align-items: center; padding: 11px 16px; border-top: 1px solid var(--border, #1f2d47); font-variant-numeric: tabular-nums; }
.rp-table.is-3 .rp-tr { grid-template-columns: minmax(0, 2fr) repeat(2, minmax(0, 1fr)); }
++.rp-table.is-4 .rp-tr { grid-template-columns: minmax(0, 1.4fr) repeat(3, minmax(0, 1fr)); }
++.rp-table.is-6 .rp-tr { grid-template-columns: minmax(0, 1.4fr) repeat(5, minmax(0, 1fr)); }
.rp-tr:first-child { border-top: 0; }
.rp-th { font-size: .75rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--text-muted, #7386a3); background: color-mix(in srgb, var(--room-accent) 5%, transparent); }
.rp-site { display: flex; flex-direction: column; min-width: 0; }
ddiff --git a/server/traffic/query.js b/server/traffic/query.js
iindex fde7bf0..efe2f96 100644
---- a/server/traffic/query.js
++++ b/server/traffic/query.js
@@@ -102,6 +102,16 @@ async function summary(store, { days = 7 } = {}) {
q(`SELECT path, agent, who, SUM(requests) AS requests FROM report_traffic_days WHERE ${SINCE} AND kind = 'file' AND who <> 'person'
GROUP BY path, agent, who ORDER BY SUM(requests) DESC LIMIT 600`, D),
]);
++ // People counted in the browser (plan AD.40 step 4, "one people number"): the pages Network's page beacon saw opened
++ // on each site (report_metric_days pageviews by site, the site's host from report_dimensions). The server log counts
++ // anything that asks like a browser; this counts pages a browser actually ran. Missing (no beacon there) is null.
++ const browser = new Map();
++ try {
++ const rows = await q(`SELECT d.doc->>'host' AS host, SUM(m.value) AS opened FROM report_metric_days m
++ JOIN report_dimensions d ON d.kind = 'site' AND d.id = m.scope_id
++ WHERE m.metric = 'pageviews' AND m.scope = 'site' AND ${SINCE} GROUP BY 1`, D);
++ for (const r of rows) if (r.host) browser.set(String(r.host).toLowerCase(), num(r.opened));
++ } catch { /* no analytics tables here: the column stays empty */ }
const W = whoTotals(daily);
const topReaders = new Map();
for (const r of readers) {
@@@ -117,7 +127,8 @@ async function summary(store, { days = 7 } = {}) {
kinds: kinds.map((k) => ({ kind: k.kind, requests: num(k.requests), people: num(k.people) })).sort((a, b) => b.requests - a.requests),
bots: bots.map((b) => ({ agent: b.agent, who: b.who, sites: num(b.sites), files: num(b.files), verified_yes: num(b.verified_yes), verified_no: num(b.verified_no), ...counts(b) })),
files: files.map((f) => ({ path: f.path, sites: num(f.sites), people: num(f.people), readers: topReaders.get(f.path) || [], ...counts(f) })),
-- sites: sites.map((s) => ({ host: s.host, requests: num(s.requests), people: num(s.people), people_pages: num(s.people_pages), bots: num(s.requests) - num(s.people), ai: num(s.ai), files: num(s.files) })),
++ sites: sites.map((s) => ({ host: s.host, requests: num(s.requests), people: num(s.people), people_pages: num(s.people_pages), bots: num(s.requests) - num(s.people), ai: num(s.ai), files: num(s.files),
++ browser_pages: browser.has(s.host) ? browser.get(s.host) : null })),
};
}
ddiff --git a/server/views/traffic.js b/server/views/traffic.js
iindex 034f880..f454b58 100644
---- a/server/views/traffic.js
++++ b/server/views/traffic.js
@@@ -109,7 +109,7 @@ function rightNow(now) {
+ `<span role="cell" data-l="Site"><a href="${esc(siteHref(b.host))}">${esc(b.host)}</a></span>`
+ `<span role="cell" data-l="A minute">${fmt(b.rpm)}${b.heavy ? ' <span class="tf-flag is-bad">Heavy</span>' : ''}</span>`
+ `<span role="cell" data-l="Not answered">${problems(b) || '<span class="tf-muted">—</span>'}</span></div>`);
-- return `${intro}<div class="rp-table" role="table" aria-label="Bots right now"><div class="rp-tr rp-th" role="row"><span role="columnheader">Bot</span><span role="columnheader">Site</span><span role="columnheader">A minute</span><span role="columnheader">Not answered</span></div>${rows.join('')}</div>`;
++ return `${intro}<div class="rp-table is-4" role="table" aria-label="Bots right now"><div class="rp-tr rp-th" role="row"><span role="columnheader">Bot</span><span role="columnheader">Site</span><span role="columnheader">A minute</span><span role="columnheader">Not answered</span></div>${rows.join('')}</div>`;
}
const readerChips = (readers) => (readers || []).slice(0, 4).map((r) => `<a class="tf-chip" href="${esc(botHref(r.agent))}">${esc(r.agent || 'Unnamed')} <b>${fmt(r.requests)}</b></a>`).join('');
@@@ -129,9 +129,10 @@ function overview({ data: d = null, days = 7, now = [] } = {}) {
+ `<span role="cell" data-l="Read most by" class="tf-chips">${readerChips(f.readers) || '<span class="tf-muted">—</span>'}</span>`
+ `<span role="cell" data-l="Last read">${f.last_at ? whenTag(f.last_at) : '—'}</span></div>`))
: '<p class="rp-fine">No file for machines was asked for in this window.</p>';
-- const sites = folded('<div class="rp-table" role="table" aria-label="Sites">', `<div class="rp-tr rp-th" role="row"><span role="columnheader">Site</span><span role="columnheader">Requests</span><span role="columnheader">People</span><span role="columnheader">Bots</span><span role="columnheader">AI</span></div>`,
++ const sites = folded('<div class="rp-table is-6" role="table" aria-label="Sites">', `<div class="rp-tr rp-th" role="row"><span role="columnheader">Site</span><span role="columnheader">Requests</span><span role="columnheader">People</span><span role="columnheader">Opened in a browser</span><span role="columnheader">Bots</span><span role="columnheader">AI</span></div>`,
d.sites.map((s) => `<div class="rp-tr" role="row"><span role="cell" class="rp-site"><a href="${esc(siteHref(s.host))}">${esc(s.host)}</a><small>${exact(s.people_pages)} pages opened by people</small></span>`
+ `<span role="cell" data-l="Requests">${exact(s.requests)}</span><span role="cell" data-l="People">${exact(s.people)}</span>`
++ + `<span role="cell" data-l="Opened in a browser">${s.browser_pages != null ? exact(s.browser_pages) : '<span class="tf-muted">—</span>'}</span>`
+ `<span role="cell" data-l="Bots">${exact(s.bots)} <span class="tf-muted">${share(s.bots, s.requests)}</span></span><span role="cell" data-l="AI">${exact(s.ai)}</span></div>`));
const kinds = d.kinds.map((k) => `<li><b>${esc(KIND[k.kind] || k.kind)}</b> ${exact(k.requests)} <span class="tf-muted">(${share(k.people, k.requests)} people)</span></li>`).join('');
const body = `${head}
@@@ -142,7 +143,7 @@ ${arrivals(d)}
<section aria-labelledby="tf-bots-h"><h2 id="tf-bots-h">${glyph('robot')}Bots</h2><p class="rp-fine">Every bot and program that asked for something, most requests first. Search engines that publish how to check are checked: "not really" counts requests that use a crawler's name from somewhere else.</p>${botsTable(d.bots)}</section>
<section aria-labelledby="tf-files-h"><h2 id="tf-files-h">${glyph('file')}Files for machines</h2><p class="rp-fine">What sites publish for search engines and AI: llms.txt and llms-full.txt, robots.txt, sitemaps, agent cards, the OpenAPI documents and each page's Markdown twin.</p>${files}</section>
<section aria-labelledby="tf-sites-h"><h2 id="tf-sites-h">${glyph('globe')}Every site</h2>${sites}</section>
--<section aria-labelledby="tf-how-h"><h2 id="tf-how-h">${glyph('info')}How this is counted</h2><ul class="tf-kinds">${kinds}</ul><p class="rp-fine">Counted on the server from every request the sites answered, so bots that never run a page's script are here too. A request is a person when a browser asks and nothing in it says bot; who a bot is comes from its user agent. Days and hours are counted in UTC; each time is shown in your own zone. No address and no person is kept: a page is counted by its section ("/c/*"), and a link's code or a share token never is. The same numbers: <a href="/api/v1/traffic?days=${esc(days)}"><code>/api/v1/traffic</code></a>.</p></section>`;
++<section aria-labelledby="tf-how-h"><h2 id="tf-how-h">${glyph('info')}How this is counted</h2><ul class="tf-kinds">${kinds}</ul><p class="rp-fine">Counted on the server from every request the sites answered, so bots that never run a page's script are here too. A request is a person when a browser asks and nothing in it says bot; who a bot is comes from its user agent. "Opened in a browser" is the other count: pages a browser actually ran, from the sites' own page beacon (a bot that only fetches never counts there; a site without the beacon shows —). Days and hours are counted in UTC; each time is shown in your own zone. No address and no person is kept: a page is counted by its section ("/c/*"), and a link's code or a share token never is. The same numbers: <a href="/api/v1/traffic?days=${esc(days)}"><code>/api/v1/traffic</code></a>.</p></section>`;
return layout({ title: 'Who visits OpenVibe', description: 'People and bots on every OpenVibe site: search engines, AI crawlers and assistants, link previews, and the files sites publish for machines.', body, active: '/traffic', path: `/traffic${days === 7 ? '' : `?days=${days}`}` });
}
ddiff --git a/test/traffic-browser.test.js b/test/traffic-browser.test.js
nnew file mode 100644
iindex 0000000..e46174a
---- /dev/null
++++ b/test/traffic-browser.test.js
@@@ -0,0 +1,40 @@
++'use strict';
++/**
++ * One people number (plan AD.40 step 4): beside the server log's "People" (anything that asks like a browser), each
++ * site on /traffic shows "Opened in a browser", the pages Network's page beacon saw a browser run there
++ * (report_metric_days pageviews by site, matched to the host through report_dimensions). A site the beacon never saw
++ * shows a dash, not a zero.
++ */
++const assert = require('assert');
++const { boot, check, done } = require('./helpers/boot');
++
++(async () => {
++ const t = await boot({ db: true });
++ try {
++ await check('the site row carries both counts; the API answers the same; a site without the beacon shows a dash', async () => {
++ const db = t.ctx.store.db;
++ const today = new Date().toISOString().slice(0, 10);
++ const row = (host, who, requests) => db.prepare(`INSERT INTO report_traffic_days (day, host, who, agent, verified, kind, path, requests, ok, redirects, missing, refused, errors, bytes, ms)
++ VALUES (?::date, ?, ?, ?, '', 'page', '/', ?, ?, 0, 0, 0, 0, 0, 0)`).run(today, host, who, who === 'person' ? '' : 'GPTBot', requests, requests);
++ await row('openvibe.help', 'person', 40);
++ await row('openvibe.help', 'ai_crawler', 25);
++ await row('openvibe.zone', 'person', 3);
++ await db.prepare(`INSERT INTO report_dimensions (kind, id, doc, updated_at) VALUES ('site', 'help', ?::jsonb, now())`)
++ .run(JSON.stringify({ id: 'help', host: 'openvibe.help', name: 'OpenVibe.Help' }));
++ await db.prepare(`INSERT INTO report_metric_days (metric, scope, scope_id, day, value, unit, source, updated_at) VALUES ('pageviews', 'site', 'help', ?::date, 31, 'count', 'beacon', now())`).run(today);
++ const api = (await t.get('/api/v1/traffic?days=7')).json();
++ const help = api.sites.find((s) => s.host === 'openvibe.help');
++ const zone = api.sites.find((s) => s.host === 'openvibe.zone');
++ assert.deepStrictEqual([help.people, help.browser_pages], [40, 31], 'the log says 40 people, the browser ran 31 pages');
++ assert.strictEqual(zone.browser_pages, null, 'no beacon there: null, not 0');
++ const page = await t.get('/traffic');
++ assert.match(page.text, /<span role="columnheader">Opened in a browser<\/span>/);
++ assert.match(page.text, /openvibe\.help<\/a>[\s\S]*?data-l="People">40<\/span><span role="cell" data-l="Opened in a browser">31<\/span>/);
++ assert.match(page.text, /openvibe\.zone<\/a>[\s\S]*?data-l="Opened in a browser"><span class="tf-muted">—<\/span>/);
++ assert.match(page.text, /class="rp-table is-6" role="table" aria-label="Sites"/, 'six columns get their own grid');
++ });
++ } finally {
++ await t.close();
++ }
++ done();
++})();