update viewers page

This commit is contained in:
2026-05-16 08:12:02 +01:00
parent 97d7e02285
commit 752b5f9eb8
2 changed files with 130 additions and 68 deletions
+51 -1
View File
@@ -758,8 +758,18 @@ function viewerDashboard() {
limit 12
`).all(daySince)
const topPages30d = db.prepare(`
select page_path, page_title, count(*) as views
from viewer_events
where event_type = 'page_view'
and occurred_at >= ?
group by page_path, page_title
order by views desc, page_path asc
limit 12
`).all(thirtyDaysSince)
const clients = db.prepare(`
select browser, os, device, count(*) as events
select browser, os, device, count(*) as events, count(distinct visitor_id) as visitors
from viewer_events
where occurred_at >= ?
group by browser, os, device
@@ -932,6 +942,23 @@ function viewerDashboard() {
location_labels: locationsByDate.get(row.date) || [],
}))
const countries24h = db.prepare(`
select
country,
avg(latitude) as latitude,
avg(longitude) as longitude,
count(*) as events,
count(distinct visitor_id) as visitors
from viewer_events
where occurred_at >= ?
and country != ''
and latitude is not null
and longitude is not null
group by country
order by visitors desc, events desc
limit 80
`).all(daySince)
const countries = db.prepare(`
select
country,
@@ -949,6 +976,26 @@ function viewerDashboard() {
limit 80
`).all(thirtyDaysSince)
const locations24h = db.prepare(`
select
country,
region,
city,
latitude,
longitude,
timezone,
language,
count(*) as events,
count(distinct visitor_id) as visitors
from viewer_events
where occurred_at >= ?
and latitude is not null
and longitude is not null
group by country, region, city, latitude, longitude, timezone, language
order by visitors desc, events desc
limit 32
`).all(daySince)
const locations = db.prepare(`
select
country,
@@ -995,11 +1042,14 @@ function viewerDashboard() {
active,
active_pages: activePages,
top_pages: topPages,
top_pages_30d: topPages30d,
clients,
clients_30d: clients30d,
activity_24h: activity24hWithLabels,
activity_30d: activityWithLocations,
countries_24h: countries24h,
countries,
locations_24h: locations24h,
locations,
totals: {
active_now: active.length,