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 +