update viewers page
This commit is contained in:
+60
-1
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user