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:
F4ilji
2026-09-18 22:18:04 +05:00
parent 8af94388ab
commit d6c0f48d48
60 changed files with 2948 additions and 121 deletions
@@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('analytics_sessions', function (Blueprint $table) {
$table->id();
$table->string('visitor_id', 36)->index();
$table->unsignedBigInteger('user_id')->nullable();
$table->string('entry_page');
$table->string('ip', 45);
$table->string('country', 2)->nullable();
$table->string('city')->nullable();
$table->string('utm_source')->nullable();
$table->string('utm_medium')->nullable();
$table->string('utm_campaign')->nullable();
$table->string('browser')->nullable();
$table->string('os')->nullable();
$table->enum('device_type', ['desktop', 'tablet', 'mobile'])->nullable();
$table->timestamp('started_at');
$table->timestamp('last_activity_at');
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users')->nullOnDelete();
$table->index(['visitor_id', 'last_activity_at']);
});
}
public function down(): void
{
Schema::dropIfExists('analytics_sessions');
}
};
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('analytics_hits', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('session_id');
$table->unsignedBigInteger('user_id')->nullable();
$table->string('url');
$table->string('referrer')->nullable();
$table->string('title')->nullable();
$table->timestamp('created_at');
$table->foreign('session_id')->references('id')->on('analytics_sessions')->cascadeOnDelete();
$table->foreign('user_id')->references('id')->on('users')->nullOnDelete();
$table->index('url');
$table->index('created_at');
});
}
public function down(): void
{
Schema::dropIfExists('analytics_hits');
}
};
@@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('analytics_daily_stats', function (Blueprint $table) {
$table->id();
$table->date('date');
$table->string('url');
$table->unsignedInteger('views_count')->default(0);
$table->unsignedInteger('unique_visitors')->default(0);
$table->timestamps();
$table->unique(['date', 'url']);
});
}
public function down(): void
{
Schema::dropIfExists('analytics_daily_stats');
}
};
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('analytics_sessions', function (Blueprint $table) {
$table->dropColumn(['country', 'city']);
});
Schema::dropIfExists('analytics_geo_cache');
}
public function down(): void
{
Schema::table('analytics_sessions', function (Blueprint $table) {
$table->string('country', 2)->nullable()->after('ip');
$table->string('city')->nullable()->after('country');
});
Schema::create('analytics_geo_cache', function (Blueprint $table) {
$table->id();
$table->string('ip_hash', 64)->unique();
$table->string('country')->nullable();
$table->string('city')->nullable();
$table->timestamp('cached_at');
$table->index('cached_at');
});
}
};