feat: display screen resolution, content stats, and advanced metrics on dashboard
This commit is contained in:
91
components/dashboard/ContentStats.tsx
Normal file
91
components/dashboard/ContentStats.tsx
Normal file
@@ -0,0 +1,91 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { formatNumber } from '@/lib/utils/format'
|
||||
import { TopPage } from '@/lib/api/stats'
|
||||
|
||||
interface ContentStatsProps {
|
||||
topPages: TopPage[]
|
||||
entryPages: TopPage[]
|
||||
exitPages: TopPage[]
|
||||
}
|
||||
|
||||
type Tab = 'top_pages' | 'entry_pages' | 'exit_pages'
|
||||
|
||||
export default function ContentStats({ topPages, entryPages, exitPages }: ContentStatsProps) {
|
||||
const [activeTab, setActiveTab] = useState<Tab>('top_pages')
|
||||
|
||||
const renderContent = () => {
|
||||
let data: TopPage[] = []
|
||||
|
||||
if (activeTab === 'top_pages') {
|
||||
data = topPages
|
||||
} else if (activeTab === 'entry_pages') {
|
||||
data = entryPages
|
||||
} else if (activeTab === 'exit_pages') {
|
||||
data = exitPages
|
||||
}
|
||||
|
||||
if (!data || data.length === 0) {
|
||||
return <p className="text-neutral-600 dark:text-neutral-400">No data available</p>
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
{data.map((page, index) => (
|
||||
<div key={index} className="flex items-center justify-between">
|
||||
<div className="flex-1 truncate text-neutral-900 dark:text-white">
|
||||
{page.path}
|
||||
</div>
|
||||
<div className="text-sm font-semibold text-neutral-600 dark:text-neutral-400 ml-4">
|
||||
{formatNumber(page.pageviews)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-white dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-800 rounded-xl p-6 h-full">
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h3 className="text-lg font-semibold text-neutral-900 dark:text-white">
|
||||
Content
|
||||
</h3>
|
||||
<div className="flex p-1 bg-neutral-100 dark:bg-neutral-800 rounded-lg">
|
||||
<button
|
||||
onClick={() => setActiveTab('top_pages')}
|
||||
className={`px-3 py-1 text-xs font-medium rounded-md transition-colors ${
|
||||
activeTab === 'top_pages'
|
||||
? 'bg-white dark:bg-neutral-700 text-neutral-900 dark:text-white shadow-sm'
|
||||
: 'text-neutral-600 dark:text-neutral-400 hover:text-neutral-900 dark:hover:text-white'
|
||||
}`}
|
||||
>
|
||||
Top Pages
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setActiveTab('entry_pages')}
|
||||
className={`px-3 py-1 text-xs font-medium rounded-md transition-colors ${
|
||||
activeTab === 'entry_pages'
|
||||
? 'bg-white dark:bg-neutral-700 text-neutral-900 dark:text-white shadow-sm'
|
||||
: 'text-neutral-600 dark:text-neutral-400 hover:text-neutral-900 dark:hover:text-white'
|
||||
}`}
|
||||
>
|
||||
Entry
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setActiveTab('exit_pages')}
|
||||
className={`px-3 py-1 text-xs font-medium rounded-md transition-colors ${
|
||||
activeTab === 'exit_pages'
|
||||
? 'bg-white dark:bg-neutral-700 text-neutral-900 dark:text-white shadow-sm'
|
||||
: 'text-neutral-600 dark:text-neutral-400 hover:text-neutral-900 dark:hover:text-white'
|
||||
}`}
|
||||
>
|
||||
Exit
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{renderContent()}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -8,11 +8,12 @@ import WorldMap from './WorldMap'
|
||||
interface LocationProps {
|
||||
countries: Array<{ country: string; pageviews: number }>
|
||||
cities: Array<{ city: string; country: string; pageviews: number }>
|
||||
regions: Array<{ region: string; country: string; pageviews: number }>
|
||||
}
|
||||
|
||||
type Tab = 'map' | 'countries' | 'cities'
|
||||
type Tab = 'map' | 'countries' | 'regions' | 'cities'
|
||||
|
||||
export default function Locations({ countries, cities }: LocationProps) {
|
||||
export default function Locations({ countries, cities, regions }: LocationProps) {
|
||||
const [activeTab, setActiveTab] = useState<Tab>('map')
|
||||
|
||||
const getFlagComponent = (countryCode: string) => {
|
||||
@@ -62,6 +63,27 @@ export default function Locations({ countries, cities }: LocationProps) {
|
||||
)
|
||||
}
|
||||
|
||||
if (activeTab === 'regions') {
|
||||
if (!regions || regions.length === 0) {
|
||||
return <p className="text-neutral-600 dark:text-neutral-400">No data available</p>
|
||||
}
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
{regions.map((region, index) => (
|
||||
<div key={index} className="flex items-center justify-between">
|
||||
<div className="flex-1 truncate text-neutral-900 dark:text-white flex items-center gap-3">
|
||||
<span className="shrink-0">{getFlagComponent(region.country)}</span>
|
||||
<span className="truncate">{region.region === 'Unknown' ? 'Unknown' : region.region}</span>
|
||||
</div>
|
||||
<div className="text-sm font-semibold text-neutral-600 dark:text-neutral-400 ml-4">
|
||||
{formatNumber(region.pageviews)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (activeTab === 'cities') {
|
||||
if (!cities || cities.length === 0) {
|
||||
return <p className="text-neutral-600 dark:text-neutral-400">No data available</p>
|
||||
@@ -111,6 +133,16 @@ export default function Locations({ countries, cities }: LocationProps) {
|
||||
>
|
||||
Countries
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setActiveTab('regions')}
|
||||
className={`px-3 py-1 text-xs font-medium rounded-md transition-colors ${
|
||||
activeTab === 'regions'
|
||||
? 'bg-white dark:bg-neutral-700 text-neutral-900 dark:text-white shadow-sm'
|
||||
: 'text-neutral-600 dark:text-neutral-400 hover:text-neutral-900 dark:hover:text-white'
|
||||
}`}
|
||||
>
|
||||
Regions
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setActiveTab('cities')}
|
||||
className={`px-3 py-1 text-xs font-medium rounded-md transition-colors ${
|
||||
@@ -7,11 +7,12 @@ interface TechSpecsProps {
|
||||
browsers: Array<{ browser: string; pageviews: number }>
|
||||
os: Array<{ os: string; pageviews: number }>
|
||||
devices: Array<{ device: string; pageviews: number }>
|
||||
screenResolutions: Array<{ screen_resolution: string; pageviews: number }>
|
||||
}
|
||||
|
||||
type Tab = 'browsers' | 'os' | 'devices'
|
||||
type Tab = 'browsers' | 'os' | 'devices' | 'screens'
|
||||
|
||||
export default function TechSpecs({ browsers, os, devices }: TechSpecsProps) {
|
||||
export default function TechSpecs({ browsers, os, devices, screenResolutions }: TechSpecsProps) {
|
||||
const [activeTab, setActiveTab] = useState<Tab>('browsers')
|
||||
|
||||
const renderContent = () => {
|
||||
@@ -23,6 +24,8 @@ export default function TechSpecs({ browsers, os, devices }: TechSpecsProps) {
|
||||
data = os.map(o => ({ name: o.os, pageviews: o.pageviews }))
|
||||
} else if (activeTab === 'devices') {
|
||||
data = devices.map(d => ({ name: d.device, pageviews: d.pageviews }))
|
||||
} else if (activeTab === 'screens') {
|
||||
data = screenResolutions.map(s => ({ name: s.screen_resolution, pageviews: s.pageviews }))
|
||||
}
|
||||
|
||||
if (!data || data.length === 0) {
|
||||
@@ -82,6 +85,16 @@ export default function TechSpecs({ browsers, os, devices }: TechSpecsProps) {
|
||||
>
|
||||
Devices
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setActiveTab('screens')}
|
||||
className={`px-3 py-1 text-xs font-medium rounded-md transition-colors ${
|
||||
activeTab === 'screens'
|
||||
? 'bg-white dark:bg-neutral-700 text-neutral-900 dark:text-white shadow-sm'
|
||||
: 'text-neutral-600 dark:text-neutral-400 hover:text-neutral-900 dark:hover:text-white'
|
||||
}`}
|
||||
>
|
||||
Screens
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{renderContent()}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import { formatNumber } from '@/lib/utils/format'
|
||||
|
||||
interface TopPagesProps {
|
||||
pages: Array<{ path: string; pageviews: number }>
|
||||
}
|
||||
|
||||
export default function TopPages({ pages }: TopPagesProps) {
|
||||
if (!pages || pages.length === 0) {
|
||||
return (
|
||||
<div className="bg-white dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-800 rounded-xl p-6">
|
||||
<h3 className="text-lg font-semibold mb-4 text-neutral-900 dark:text-white">
|
||||
Top Pages
|
||||
</h3>
|
||||
<p className="text-neutral-600 dark:text-neutral-400">No data available</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-white dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-800 rounded-xl p-6">
|
||||
<h3 className="text-lg font-semibold mb-4 text-neutral-900 dark:text-white">
|
||||
Top Pages
|
||||
</h3>
|
||||
<div className="space-y-3">
|
||||
{pages.map((page, index) => (
|
||||
<div key={index} className="flex items-center justify-between">
|
||||
<div className="flex-1 truncate text-neutral-900 dark:text-white">
|
||||
{page.path}
|
||||
</div>
|
||||
<div className="text-sm font-semibold text-neutral-600 dark:text-neutral-400 ml-4">
|
||||
{formatNumber(page.pageviews)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user