update viewers page

This commit is contained in:
2026-05-16 07:53:16 +01:00
parent fddddadd48
commit 68b44ea8da
2 changed files with 86 additions and 3 deletions
+60 -1
View File
@@ -777,6 +777,65 @@ function viewerDashboard() {
order by date asc
`).all(thirtyDaysSince)
const activityLocationRows = db.prepare(`
select
date(occurred_at) as date,
country,
city,
region,
timezone,
count(distinct visitor_id) as visitors
from viewer_events
where occurred_at >= ?
and (
country != ''
or city != ''
or region != ''
or (timezone != '' and timezone != 'Not shared')
)
group by date(occurred_at), country, city, region, timezone
order by date asc, visitors desc
`).all(thirtyDaysSince)
const locationsByDate = new Map()
for (const row of activityLocationRows) {
const label = [row.city, row.region, row.country || row.timezone]
.filter(Boolean)
.join(', ')
if (!label) continue
const current = locationsByDate.get(row.date) || []
if (current.length < 4) current.push({ label, visitors: row.visitors || 0 })
locationsByDate.set(row.date, current)
}
const activityClientRows = db.prepare(`
select
date(occurred_at) as date,
browser,
os,
device,
count(distinct visitor_id) as visitors,
count(*) as events
from viewer_events
where occurred_at >= ?
group by date(occurred_at), browser, os, device
order by date asc, visitors desc, events desc
`).all(thirtyDaysSince)
const clientsByDate = new Map()
for (const row of activityClientRows) {
const label = `${row.browser} on ${row.os}${row.device ? ` (${row.device})` : ''}`
const current = clientsByDate.get(row.date) || []
if (current.length < 4) current.push({ label, visitors: row.visitors || 0, events: row.events || 0 })
clientsByDate.set(row.date, current)
}
const activityWithLocations = activity30d.map((row) => ({
...row,
client_labels: clientsByDate.get(row.date) || [],
location_labels: locationsByDate.get(row.date) || [],
}))
const countries = db.prepare(`
select
country,
@@ -841,7 +900,7 @@ function viewerDashboard() {
top_pages: topPages,
clients,
clients_30d: clients30d,
activity_30d: activity30d,
activity_30d: activityWithLocations,
countries,
locations,
totals: {