feat: add city and region tracking to analytics
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useParams, useRouter } from 'next/navigation'
|
||||
import { getSite, type Site } from '@/lib/api/sites'
|
||||
import { getStats, getRealtime, getDailyStats, getTopPages, getTopReferrers, getCountries } from '@/lib/api/stats'
|
||||
import { getStats, getRealtime, getDailyStats, getTopPages, getTopReferrers, getCountries, getCities, getRegions } from '@/lib/api/stats'
|
||||
import { formatNumber, getDateRange } from '@/lib/utils/format'
|
||||
import { toast } from 'sonner'
|
||||
import LoadingOverlay from '@/components/LoadingOverlay'
|
||||
@@ -12,6 +12,8 @@ import RealtimeVisitors from '@/components/dashboard/RealtimeVisitors'
|
||||
import TopPages from '@/components/dashboard/TopPages'
|
||||
import TopReferrers from '@/components/dashboard/TopReferrers'
|
||||
import Countries from '@/components/dashboard/Countries'
|
||||
import Cities from '@/components/dashboard/Cities'
|
||||
import Regions from '@/components/dashboard/Regions'
|
||||
import Chart from '@/components/dashboard/Chart'
|
||||
|
||||
export default function SiteDashboardPage() {
|
||||
@@ -27,6 +29,8 @@ export default function SiteDashboardPage() {
|
||||
const [topPages, setTopPages] = useState<any[]>([])
|
||||
const [topReferrers, setTopReferrers] = useState<any[]>([])
|
||||
const [countries, setCountries] = useState<any[]>([])
|
||||
const [cities, setCities] = useState<any[]>([])
|
||||
const [regions, setRegions] = useState<any[]>([])
|
||||
const [dateRange, setDateRange] = useState(getDateRange(30))
|
||||
|
||||
useEffect(() => {
|
||||
@@ -40,7 +44,7 @@ export default function SiteDashboardPage() {
|
||||
const loadData = async () => {
|
||||
try {
|
||||
setLoading(true)
|
||||
const [siteData, statsData, realtimeData, dailyData, pagesData, referrersData, countriesData] = await Promise.all([
|
||||
const [siteData, statsData, realtimeData, dailyData, pagesData, referrersData, countriesData, citiesData, regionsData] = await Promise.all([
|
||||
getSite(siteId),
|
||||
getStats(siteId, dateRange.start, dateRange.end),
|
||||
getRealtime(siteId),
|
||||
@@ -48,6 +52,8 @@ export default function SiteDashboardPage() {
|
||||
getTopPages(siteId, dateRange.start, dateRange.end, 10),
|
||||
getTopReferrers(siteId, dateRange.start, dateRange.end, 10),
|
||||
getCountries(siteId, dateRange.start, dateRange.end, 10),
|
||||
getCities(siteId, dateRange.start, dateRange.end, 10),
|
||||
getRegions(siteId, dateRange.start, dateRange.end, 10),
|
||||
])
|
||||
setSite(siteData)
|
||||
setStats(statsData || { pageviews: 0, visitors: 0 })
|
||||
@@ -56,6 +62,8 @@ export default function SiteDashboardPage() {
|
||||
setTopPages(Array.isArray(pagesData) ? pagesData : [])
|
||||
setTopReferrers(Array.isArray(referrersData) ? referrersData : [])
|
||||
setCountries(Array.isArray(countriesData) ? countriesData : [])
|
||||
setCities(Array.isArray(citiesData) ? citiesData : [])
|
||||
setRegions(Array.isArray(regionsData) ? regionsData : [])
|
||||
} catch (error: any) {
|
||||
toast.error('Failed to load data: ' + (error.message || 'Unknown error'))
|
||||
} finally {
|
||||
@@ -131,10 +139,15 @@ export default function SiteDashboardPage() {
|
||||
<TopPages pages={topPages} />
|
||||
</div>
|
||||
|
||||
<div className="grid gap-6 lg:grid-cols-2">
|
||||
<div className="grid gap-6 lg:grid-cols-2 mb-8">
|
||||
<TopReferrers referrers={topReferrers} />
|
||||
<Countries countries={countries} />
|
||||
</div>
|
||||
|
||||
<div className="grid gap-6 lg:grid-cols-2">
|
||||
<Cities cities={cities} />
|
||||
<Regions regions={regions} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user