Files
ntspi-app/app/Containers/Analytics/Tasks/GetDevicesTask.php
T
F4ilji d6c0f48d48 feat(analytics): add site analytics with grouped navigation sections
- Add Analytics container: models, tasks, jobs, controllers, routes, services
- Add analytics config with section groups (structure, institute, content, services)
- Add database tables: analytics_sessions, analytics_hits, analytics_daily_stats
- Add frontend: Analytics page, section detail, chart, overview, navigation components
- Add consent banner and JS tracking service (sendBeacon + Inertia listener)
- Add permission sync for view_analytics, view_any_analytic
- Fix trailing slash URL matching in GetNavigationSectionsTask
- Fix event propagation on expand arrows in navigation sections
- Fix RecordVisitJob to not depend on dropped analytics_geo_cache table
- Replace plain text views/visitors with badge-style icons
- Group navigation sections by category with separate blocks
- Add config-driven non-CMS sections (faculties, divisions, DPO, journals)
- Remove Events, TV, Sveden from analytics sections
2026-09-18 22:18:04 +05:00

57 lines
1.4 KiB
PHP

<?php
namespace App\Containers\Analytics\Tasks;
use App\Containers\Analytics\Models\AnalyticsSession;
use Illuminate\Support\Carbon;
class GetDevicesTask
{
public function run(int $days = 30): array
{
$from = Carbon::now()->subDays($days)->startOfDay();
$devices = AnalyticsSession::where('started_at', '>=', $from)
->selectRaw('
device_type,
COUNT(*) as count
')
->groupBy('device_type')
->get()
->pluck('count', 'device_type')
->toArray();
$browsers = AnalyticsSession::where('started_at', '>=', $from)
->whereNotNull('browser')
->selectRaw('
browser,
COUNT(*) as count
')
->groupBy('browser')
->orderByDesc('count')
->limit(10)
->get()
->pluck('count', 'browser')
->toArray();
$oses = AnalyticsSession::where('started_at', '>=', $from)
->whereNotNull('os')
->selectRaw('
os,
COUNT(*) as count
')
->groupBy('os')
->orderByDesc('count')
->limit(10)
->get()
->pluck('count', 'os')
->toArray();
return [
'devices' => $devices,
'browsers' => $browsers,
'oses' => $oses,
];
}
}