@extends('admin.layout') @section('title', 'Analytics — ' . $video->title) @section('page_title', 'Video Analytics') @php function flagEmoji(string $code): string { $chars = ''; foreach (str_split(strtoupper($code)) as $c) { $chars .= mb_chr(0x1F1E6 + ord($c) - ord('A')); } return $chars; } @endphp @section('content') Back to Videos
@if($video->thumbnail) {{ $video->title }} @else @endif
{{ $video->title }}
by {{ $video->user->name }}
{{ $video->created_at->format('M d, Y') }} {{ $video->formatted_duration ?? '—' }} {{ ucfirst($video->type) }} @php $statusColors = ['ready'=>'#4caf50','processing'=>'#ff9800','pending'=>'#888','failed'=>'#f44336']; $sc = $statusColors[$video->status] ?? '#888'; @endphp {{ ucfirst($video->status) }} {{ ucfirst($video->visibility) }}
Watch Edit
{{ number_format($totalViews) }}
Total Views
all watch events
{{ number_format($totalUniqueViewers) }}
Unique Viewers
each person once
{{ number_format($totalLikes) }}
Likes
{{ number_format($totalComments) }}
Comments
{{ number_format($authViewers) }}
Logged-in
{{ number_format($guestViewers) }}
Guests
View Events – Last 30 Days (total plays, not unique)
Viewers by Country (unique viewers)
@php $maxCountry = $viewsByCountry->first()->total ?? 1; @endphp @forelse($viewsByCountry as $i => $row)
{{ $i + 1 }} {{ flagEmoji($row->country) }} {{ $row->country_name ?? $row->country }}
{{ number_format($row->total) }}
@empty
No country data yet — views are still being collected.
@endforelse
Country Distribution
@if($viewsByCountry->isNotEmpty())
@else
Chart will appear once geo data is collected.
@endif
Age Groups (unique viewers)
@php $totalAge = array_sum($ageGroups); @endphp @if($totalAge > 0)
@foreach($ageGroups as $label => $count) @if($count > 0)
{{ number_format($count) }}
{{ $label }}
@endif @endforeach
@else
Age data requires users to set their birthday in profile settings.
@endif
Gender Split (unique viewers)
@php $genderTotal = array_sum($genderCounts); @endphp @if($genderTotal > 0)
@php $genderIcons = ['Male' => 'bi-gender-male', 'Female' => 'bi-gender-female', 'Prefer not to say' => 'bi-dash-circle']; $genderColors = ['Male' => '#2196f3', 'Female' => '#e91e63', 'Prefer not to say' => '#888']; @endphp @foreach($genderCounts as $label => $count) @if($count > 0)
{{ $label }} {{ number_format($count) }} {{ round(($count / $genderTotal) * 100) }}%
@endif @endforeach
Based on {{ number_format($genderTotal) }} logged-in viewer{{ $genderTotal !== 1 ? 's' : '' }} who set their gender.
@else

No gender data yet. Viewers can set their gender in profile settings.

@endif
Recent View Events (last 20 individual plays)
@if($recentViews->isNotEmpty())
@foreach($recentViews as $view) @endforeach
Viewer Country IP Address Type Watched At
@if($view->viewer_avatar) @else @endif
{{ $view->viewer_name ?? 'Guest' }}
@if($view->country) {{ flagEmoji($view->country) }} {{ $view->country_name ?? $view->country }} @else Unknown @endif {{ $view->ip_address ?? '—' }} @if($view->user_id) Logged in @else Guest @endif {{ \Carbon\Carbon::parse($view->watched_at)->diffForHumans() }}
{{ \Carbon\Carbon::parse($view->watched_at)->format('M d, Y H:i') }}
@else
No views recorded yet.
@endif
@endsection @section('scripts') @endsection