114 lines
6.3 KiB
PHP
114 lines
6.3 KiB
PHP
<x-report-layout :website="$website" :from="$from" :to="$to" title="Conversions">
|
|
|
|
<div class="space-y-6">
|
|
{{-- Summary Cards --}}
|
|
@php
|
|
$totalCompletions = $goals->sum('completions');
|
|
$totalValue = $goals->sum('total_value');
|
|
$overallRate = $totalSessions > 0 ? round(($totalCompletions / $totalSessions) * 100, 2) : 0;
|
|
@endphp
|
|
<div class="grid gap-4 sm:grid-cols-3">
|
|
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-5">
|
|
<dt class="text-sm font-medium text-gray-500">Total Completions</dt>
|
|
<dd class="mt-1 text-2xl font-bold text-gray-900">{{ number_format($totalCompletions) }}</dd>
|
|
</div>
|
|
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-5">
|
|
<dt class="text-sm font-medium text-gray-500">Overall Conversion Rate</dt>
|
|
<dd class="mt-1 text-2xl font-bold text-gray-900">{{ $overallRate }}%</dd>
|
|
</div>
|
|
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-5">
|
|
<dt class="text-sm font-medium text-gray-500">Total Goal Value</dt>
|
|
<dd class="mt-1 text-2xl font-bold text-gray-900">${{ number_format($totalValue, 2) }}</dd>
|
|
</div>
|
|
</div>
|
|
|
|
{{-- Completions Chart --}}
|
|
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
|
|
<h3 class="text-base font-semibold text-gray-900 mb-4">Goal Completions Over Time</h3>
|
|
<div style="height: 240px;">
|
|
<canvas id="conversions-chart"></canvas>
|
|
</div>
|
|
</div>
|
|
|
|
{{-- Per-Goal Table --}}
|
|
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
|
@if ($goals->isEmpty())
|
|
<div class="px-6 py-12 text-center text-sm text-gray-500">
|
|
No goals configured.
|
|
<a href="{{ route('goals.create', $website) }}" class="text-indigo-600 hover:text-indigo-800">Create one</a>.
|
|
</div>
|
|
@else
|
|
@php
|
|
$typeLabels = [
|
|
'url_destination' => 'URL Destination',
|
|
'event_match' => 'Event Match',
|
|
'duration' => 'Duration',
|
|
'pages_per_session' => 'Pages / Session',
|
|
];
|
|
@endphp
|
|
<div class="overflow-x-auto">
|
|
<table class="min-w-full divide-y divide-gray-200">
|
|
<thead class="bg-gray-50">
|
|
<tr>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Goal</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Type</th>
|
|
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Completions</th>
|
|
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Conversion Rate</th>
|
|
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Value</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-gray-200">
|
|
@foreach ($goals as $goal)
|
|
<tr>
|
|
<td class="px-6 py-4 text-sm font-medium text-gray-900">{{ $goal->name }}</td>
|
|
<td class="px-6 py-4 text-sm text-gray-500">{{ $typeLabels[$goal->type] ?? $goal->type }}</td>
|
|
<td class="px-6 py-4 text-sm text-gray-900 text-right">{{ number_format($goal->completions) }}</td>
|
|
<td class="px-6 py-4 text-sm text-gray-900 text-right">{{ $goal->conversion_rate }}%</td>
|
|
<td class="px-6 py-4 text-sm text-gray-900 text-right">{{ $goal->total_value ? '$' . number_format($goal->total_value, 2) : '—' }}</td>
|
|
<td class="px-6 py-4">
|
|
<span class="inline-flex items-center rounded-full px-2 py-1 text-xs font-medium {{ $goal->is_active ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-600' }}">
|
|
{{ $goal->is_active ? 'Active' : 'Inactive' }}
|
|
</span>
|
|
</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
@endif
|
|
</div>
|
|
</div>
|
|
|
|
<x-slot name="scripts">
|
|
<script src="https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js"></script>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
const raw = @json($chartData);
|
|
new Chart(document.getElementById('conversions-chart'), {
|
|
type: 'bar',
|
|
data: {
|
|
labels: raw.map(d => d.period),
|
|
datasets: [{
|
|
label: 'Completions',
|
|
data: raw.map(d => d.completions),
|
|
backgroundColor: 'rgba(16, 185, 129, 0.7)',
|
|
borderRadius: 4,
|
|
}],
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
maintainAspectRatio: false,
|
|
plugins: { legend: { display: false } },
|
|
scales: {
|
|
x: { grid: { display: false }, ticks: { maxTicksLimit: 12, font: { size: 11 }, color: '#9ca3af' } },
|
|
y: { beginAtZero: true, grid: { color: 'rgba(0,0,0,0.04)' }, ticks: { precision: 0, font: { size: 11 }, color: '#9ca3af' } },
|
|
},
|
|
},
|
|
});
|
|
});
|
|
</script>
|
|
</x-slot>
|
|
|
|
</x-report-layout>
|