From 79da7502cda122db78cb075c3d5bb1cded77c4e6 Mon Sep 17 00:00:00 2001 From: boban Date: Sat, 16 May 2026 08:04:08 +0200 Subject: [PATCH] feat(analytics): live dashboard with Reverb WebSocket, click event broadcasting Overwrites the Analytics Index stub with a full Livewire component that loads today's click count from the clicks table (workspace_id is a direct column) and listens for live updates via Echo/Reverb using the #[On('echo:workspace.{workspaceId}.analytics,click.recorded')] attribute. Creates the corresponding blade view with a today-counter card and a live recent-clicks feed (last 10 entries). Co-Authored-By: Claude Sonnet 4.6 --- app/Livewire/Pages/Analytics/Index.php | 29 +++++++++++++++++-- .../livewire/pages/analytics/index.blade.php | 25 ++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 resources/views/livewire/pages/analytics/index.blade.php diff --git a/app/Livewire/Pages/Analytics/Index.php b/app/Livewire/Pages/Analytics/Index.php index 959cd60..f9fbc82 100644 --- a/app/Livewire/Pages/Analytics/Index.php +++ b/app/Livewire/Pages/Analytics/Index.php @@ -2,13 +2,38 @@ namespace App\Livewire\Pages\Analytics; +use App\Domains\Analytics\Models\Click; use Livewire\Component; +use Livewire\Attributes\On; class Index extends Component { + public array $recentClicks = []; + public int $totalToday = 0; + + public function mount(): void + { + $workspace = app('current_workspace'); + + $this->totalToday = Click::where('workspace_id', $workspace->id) + ->whereDate('clicked_at', today()) + ->count(); + } + + #[On('echo:workspace.{workspaceId}.analytics,click.recorded')] + public function handleNewClick(array $data): void + { + array_unshift($this->recentClicks, $data); + $this->recentClicks = array_slice($this->recentClicks, 0, 10); + $this->totalToday++; + } + public function render(): \Illuminate\View\View { - return view('livewire.pages.coming-soon') - ->layout('layouts.nimuli-app', ['title' => 'Analytics']); + $workspace = app('current_workspace'); + + return view('livewire.pages.analytics.index', [ + 'workspace' => $workspace, + ])->layout('layouts.nimuli-app', ['title' => 'Analytics']); } } diff --git a/resources/views/livewire/pages/analytics/index.blade.php b/resources/views/livewire/pages/analytics/index.blade.php new file mode 100644 index 0000000..710e017 --- /dev/null +++ b/resources/views/livewire/pages/analytics/index.blade.php @@ -0,0 +1,25 @@ +
+

Analytics

+ +
+
+
Today
+
{{ $totalToday }}
+
+
+ + @if(count($recentClicks) > 0) +
+
Recent clicks
+
+ @foreach($recentClicks as $click) +
+ {{ $click['clicked_at'] ?? '' }} + {{ $click['country'] ?? '—' }} + {{ $click['device'] ?? '—' }} +
+ @endforeach +
+
+ @endif +