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
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Analytics\Commands;
|
||||
|
||||
use App\Containers\Analytics\Models\AnalyticsDailyStat;
|
||||
use App\Containers\Analytics\Models\AnalyticsHit;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AggregateAnalyticsCommand extends \Illuminate\Console\Command
|
||||
{
|
||||
protected $signature = 'analytics:aggregate {--days=1 : Days back to aggregate}';
|
||||
|
||||
protected $description = 'Aggregate analytics hits into daily stats';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$days = (int) $this->option('days');
|
||||
$date = now()->subDays($days)->toDateString();
|
||||
|
||||
$stats = AnalyticsHit::selectRaw('
|
||||
DATE(created_at) as hit_date,
|
||||
url,
|
||||
COUNT(*) as views_count,
|
||||
COUNT(DISTINCT session_id) as unique_visitors
|
||||
')
|
||||
->whereDate('created_at', $date)
|
||||
->groupBy(DB::raw('DATE(created_at)'), 'url')
|
||||
->get();
|
||||
|
||||
$inserted = 0;
|
||||
|
||||
foreach ($stats as $row) {
|
||||
AnalyticsDailyStat::updateOrCreate(
|
||||
['date' => $row->hit_date, 'url' => $row->url],
|
||||
[
|
||||
'views_count' => $row->views_count,
|
||||
'unique_visitors' => $row->unique_visitors,
|
||||
]
|
||||
);
|
||||
$inserted++;
|
||||
}
|
||||
|
||||
$this->info("Aggregated {$inserted} daily stat rows for {$date}");
|
||||
|
||||
return static::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user