phase 4
This commit is contained in:
@@ -75,16 +75,16 @@ Individual report pages accessible from the dashboard sidebar.
|
|||||||
|
|
||||||
Allow users to define goals and track conversion rates.
|
Allow users to define goals and track conversion rates.
|
||||||
|
|
||||||
- [ ] Build `GoalController` CRUD (create, edit, delete goals per website)
|
- [x] Build `GoalController` CRUD (create, edit, delete goals per website)
|
||||||
- [ ] Support goal types:
|
- [x] Support goal types:
|
||||||
- **URL destination** — session visited a specific path
|
- **URL destination** — session visited a specific path
|
||||||
- **Event match** — a specific event name/category was fired
|
- **Event match** — a specific event name/category was fired
|
||||||
- **Duration** — session lasted longer than N seconds
|
- **Duration** — session lasted longer than N seconds
|
||||||
- **Pages per session** — session hit N+ page views
|
- **Pages per session** — session hit N+ page views
|
||||||
- [ ] Create a `GoalEvaluationService` that checks incoming data against active goals and records `GoalConversion` entries
|
- [x] Create a `GoalEvaluationService` that checks incoming data against active goals and records `GoalConversion` entries
|
||||||
- [ ] Hook goal evaluation into `CollectController` after recording page view / event
|
- [x] Hook goal evaluation into `CollectController` after recording page view / event
|
||||||
- [ ] Build a **Conversions report** — goal completion count, conversion rate (completions / sessions), goal value totals
|
- [x] Build a **Conversions report** — goal completion count, conversion rate (completions / sessions), goal value totals
|
||||||
- [ ] Add goal completion sparklines to the main dashboard
|
- [x] Add goal completion sparklines to the main dashboard
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use App\Models\Event;
|
|||||||
use App\Models\PageView;
|
use App\Models\PageView;
|
||||||
use App\Models\Visitor;
|
use App\Models\Visitor;
|
||||||
use App\Models\Website;
|
use App\Models\Website;
|
||||||
|
use App\Services\GoalEvaluationService;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
@@ -120,6 +121,10 @@ class CollectController extends Controller
|
|||||||
'is_bounce' => $session->pageViews()->count() <= 1,
|
'is_bounce' => $session->pageViews()->count() <= 1,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$session->refresh();
|
||||||
|
|
||||||
|
app(GoalEvaluationService::class)->evaluate($website, $visitor, $session, $payload, $now);
|
||||||
|
|
||||||
return response()->json(['ok' => true]);
|
return response()->json(['ok' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,12 @@ class DashboardController extends Controller
|
|||||||
$metrics = $service->summary();
|
$metrics = $service->summary();
|
||||||
$chartData = $service->visitorsOverTime();
|
$chartData = $service->visitorsOverTime();
|
||||||
$activeVisitors = AnalyticsQueryService::activeVisitors($website);
|
$activeVisitors = AnalyticsQueryService::activeVisitors($website);
|
||||||
|
$goalConversions = $service->conversionsReport();
|
||||||
|
$goalChartData = $service->goalCompletionsOverTime();
|
||||||
|
|
||||||
return view('dashboard.show', compact(
|
return view('dashboard.show', compact(
|
||||||
'website', 'metrics', 'chartData', 'activeVisitors', 'from', 'to',
|
'website', 'metrics', 'chartData', 'activeVisitors',
|
||||||
|
'goalConversions', 'goalChartData', 'from', 'to',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Requests\StoreGoalRequest;
|
||||||
|
use App\Http\Requests\UpdateGoalRequest;
|
||||||
|
use App\Models\Goal;
|
||||||
|
use App\Models\Website;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
class GoalController extends Controller
|
||||||
|
{
|
||||||
|
public function index(Website $website): View
|
||||||
|
{
|
||||||
|
$this->authorize('view', $website);
|
||||||
|
|
||||||
|
$goals = $website->goals()->latest()->get();
|
||||||
|
|
||||||
|
return view('goals.index', compact('website', 'goals'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(Website $website): View
|
||||||
|
{
|
||||||
|
$this->authorize('view', $website);
|
||||||
|
|
||||||
|
return view('goals.create', compact('website'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(StoreGoalRequest $request, Website $website): RedirectResponse
|
||||||
|
{
|
||||||
|
$this->authorize('view', $website);
|
||||||
|
|
||||||
|
$data = $request->validated();
|
||||||
|
$data['is_active'] = $request->boolean('is_active', true);
|
||||||
|
|
||||||
|
$website->goals()->create($data);
|
||||||
|
|
||||||
|
return redirect()
|
||||||
|
->route('goals.index', $website)
|
||||||
|
->with('success', 'Goal created successfully.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(Website $website, Goal $goal): View
|
||||||
|
{
|
||||||
|
$this->authorize('view', $website);
|
||||||
|
abort_unless($goal->website_id === $website->id, 404);
|
||||||
|
|
||||||
|
return view('goals.edit', compact('website', 'goal'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(UpdateGoalRequest $request, Website $website, Goal $goal): RedirectResponse
|
||||||
|
{
|
||||||
|
$this->authorize('view', $website);
|
||||||
|
abort_unless($goal->website_id === $website->id, 404);
|
||||||
|
|
||||||
|
$data = $request->validated();
|
||||||
|
$data['is_active'] = $request->boolean('is_active', true);
|
||||||
|
|
||||||
|
$goal->update($data);
|
||||||
|
|
||||||
|
return redirect()
|
||||||
|
->route('goals.index', $website)
|
||||||
|
->with('success', 'Goal updated successfully.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(Website $website, Goal $goal): RedirectResponse
|
||||||
|
{
|
||||||
|
$this->authorize('view', $website);
|
||||||
|
abort_unless($goal->website_id === $website->id, 404);
|
||||||
|
|
||||||
|
$goal->delete();
|
||||||
|
|
||||||
|
return redirect()
|
||||||
|
->route('goals.index', $website)
|
||||||
|
->with('success', 'Goal deleted successfully.');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -193,4 +193,22 @@ class ReportController extends Controller
|
|||||||
'trending' => $service->eventTrending($eventName),
|
'trending' => $service->eventTrending($eventName),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- Conversions ----
|
||||||
|
|
||||||
|
public function conversions(Request $request, Website $website): View
|
||||||
|
{
|
||||||
|
$this->authorize('view', $website);
|
||||||
|
[$from, $to] = $this->parseDateRange($request);
|
||||||
|
$service = AnalyticsQueryService::for($website, $from, $to);
|
||||||
|
|
||||||
|
return view('reports.conversions', [
|
||||||
|
'website' => $website,
|
||||||
|
'from' => $from,
|
||||||
|
'to' => $to,
|
||||||
|
'goals' => $service->conversionsReport(),
|
||||||
|
'chartData' => $service->goalCompletionsOverTime(),
|
||||||
|
'totalSessions' => $service->totalSessions(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class StoreGoalRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => ['required', 'string', 'max:255'],
|
||||||
|
'type' => ['required', Rule::in(['url_destination', 'event_match', 'duration', 'pages_per_session'])],
|
||||||
|
'default_value' => ['nullable', 'numeric', 'min:0'],
|
||||||
|
'is_active' => ['sometimes', 'boolean'],
|
||||||
|
|
||||||
|
'conditions.path' => ['required_if:type,url_destination', 'nullable', 'string', 'max:2048'],
|
||||||
|
'conditions.match_type' => ['required_if:type,url_destination', 'nullable', Rule::in(['exact', 'starts_with', 'contains', 'regex'])],
|
||||||
|
|
||||||
|
'conditions.event_name' => ['required_if:type,event_match', 'nullable', 'string', 'max:255'],
|
||||||
|
'conditions.event_category' => ['nullable', 'string', 'max:255'],
|
||||||
|
|
||||||
|
'conditions.seconds' => ['required_if:type,duration', 'nullable', 'integer', 'min:1'],
|
||||||
|
|
||||||
|
'conditions.page_count' => ['required_if:type,pages_per_session', 'nullable', 'integer', 'min:1'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class UpdateGoalRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => ['required', 'string', 'max:255'],
|
||||||
|
'type' => ['required', Rule::in(['url_destination', 'event_match', 'duration', 'pages_per_session'])],
|
||||||
|
'default_value' => ['nullable', 'numeric', 'min:0'],
|
||||||
|
'is_active' => ['sometimes', 'boolean'],
|
||||||
|
|
||||||
|
'conditions.path' => ['required_if:type,url_destination', 'nullable', 'string', 'max:2048'],
|
||||||
|
'conditions.match_type' => ['required_if:type,url_destination', 'nullable', Rule::in(['exact', 'starts_with', 'contains', 'regex'])],
|
||||||
|
|
||||||
|
'conditions.event_name' => ['required_if:type,event_match', 'nullable', 'string', 'max:255'],
|
||||||
|
'conditions.event_category' => ['nullable', 'string', 'max:255'],
|
||||||
|
|
||||||
|
'conditions.seconds' => ['required_if:type,duration', 'nullable', 'integer', 'min:1'],
|
||||||
|
|
||||||
|
'conditions.page_count' => ['required_if:type,pages_per_session', 'nullable', 'integer', 'min:1'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -432,6 +432,67 @@ class AnalyticsQueryService
|
|||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- Conversions ----
|
||||||
|
|
||||||
|
public function conversionsReport(): Collection
|
||||||
|
{
|
||||||
|
$goals = \App\Models\Goal::where('website_id', $this->website->id)->get();
|
||||||
|
$totalSessions = $this->totalSessions();
|
||||||
|
|
||||||
|
return $goals->map(function ($goal) use ($totalSessions) {
|
||||||
|
$completions = \App\Models\GoalConversion::where('goal_id', $goal->id)
|
||||||
|
->whereBetween('converted_at', [$this->from, $this->to])
|
||||||
|
->count();
|
||||||
|
|
||||||
|
$totalValue = \App\Models\GoalConversion::where('goal_id', $goal->id)
|
||||||
|
->whereBetween('converted_at', [$this->from, $this->to])
|
||||||
|
->sum('value');
|
||||||
|
|
||||||
|
return (object) [
|
||||||
|
'id' => $goal->id,
|
||||||
|
'name' => $goal->name,
|
||||||
|
'type' => $goal->type,
|
||||||
|
'is_active' => $goal->is_active,
|
||||||
|
'completions' => $completions,
|
||||||
|
'conversion_rate' => $totalSessions > 0 ? round(($completions / $totalSessions) * 100, 2) : 0,
|
||||||
|
'total_value' => $totalValue,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function goalCompletionsOverTime(): Collection
|
||||||
|
{
|
||||||
|
$days = $this->from->diffInDays($this->to);
|
||||||
|
$groupFormat = $days <= 2 ? '%Y-%m-%d %H:00' : '%Y-%m-%d';
|
||||||
|
$carbonFormat = $days <= 2 ? 'Y-m-d H:00' : 'Y-m-d';
|
||||||
|
|
||||||
|
$data = \App\Models\GoalConversion::where('website_id', $this->website->id)
|
||||||
|
->whereBetween('converted_at', [$this->from, $this->to])
|
||||||
|
->select(
|
||||||
|
DB::raw("strftime('{$groupFormat}', converted_at) as period"),
|
||||||
|
DB::raw('COUNT(*) as completions'),
|
||||||
|
)
|
||||||
|
->groupBy('period')
|
||||||
|
->orderBy('period')
|
||||||
|
->get()
|
||||||
|
->keyBy('period');
|
||||||
|
|
||||||
|
$periods = collect();
|
||||||
|
$cursor = $this->from->copy();
|
||||||
|
$increment = $days <= 2 ? 'addHour' : 'addDay';
|
||||||
|
|
||||||
|
while ($cursor->lte($this->to)) {
|
||||||
|
$key = $cursor->format($carbonFormat);
|
||||||
|
$periods->push([
|
||||||
|
'period' => $key,
|
||||||
|
'completions' => $data->get($key)?->completions ?? 0,
|
||||||
|
]);
|
||||||
|
$cursor->$increment();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $periods;
|
||||||
|
}
|
||||||
|
|
||||||
// ---- Real-Time ----
|
// ---- Real-Time ----
|
||||||
|
|
||||||
public static function activeVisitors(Website $website, int $minutes = 5): int
|
public static function activeVisitors(Website $website, int $minutes = 5): int
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Models\AnalyticsSession;
|
||||||
|
use App\Models\Goal;
|
||||||
|
use App\Models\GoalConversion;
|
||||||
|
use App\Models\Visitor;
|
||||||
|
use App\Models\Website;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
class GoalEvaluationService
|
||||||
|
{
|
||||||
|
public function evaluate(
|
||||||
|
Website $website,
|
||||||
|
Visitor $visitor,
|
||||||
|
AnalyticsSession $session,
|
||||||
|
array $payload,
|
||||||
|
Carbon $now,
|
||||||
|
): void {
|
||||||
|
$goals = $website->goals()->where('is_active', true)->get();
|
||||||
|
|
||||||
|
foreach ($goals as $goal) {
|
||||||
|
if ($this->alreadyConverted($goal, $session)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->matches($goal, $session, $payload)) {
|
||||||
|
GoalConversion::create([
|
||||||
|
'goal_id' => $goal->id,
|
||||||
|
'website_id' => $website->id,
|
||||||
|
'visitor_id' => $visitor->id,
|
||||||
|
'analytics_session_id' => $session->id,
|
||||||
|
'value' => $goal->default_value,
|
||||||
|
'converted_at' => $now,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function alreadyConverted(Goal $goal, AnalyticsSession $session): bool
|
||||||
|
{
|
||||||
|
return GoalConversion::where('goal_id', $goal->id)
|
||||||
|
->where('analytics_session_id', $session->id)
|
||||||
|
->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function matches(Goal $goal, AnalyticsSession $session, array $payload): bool
|
||||||
|
{
|
||||||
|
return match ($goal->type) {
|
||||||
|
'url_destination' => $this->matchesUrlDestination($goal, $payload),
|
||||||
|
'event_match' => $this->matchesEvent($goal, $payload),
|
||||||
|
'duration' => $this->matchesDuration($goal, $session),
|
||||||
|
'pages_per_session' => $this->matchesPagesPerSession($goal, $session),
|
||||||
|
default => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private function matchesUrlDestination(Goal $goal, array $payload): bool
|
||||||
|
{
|
||||||
|
$conditions = $goal->conditions;
|
||||||
|
$path = $payload['path'] ?? '';
|
||||||
|
$targetPath = $conditions['path'] ?? '';
|
||||||
|
$matchType = $conditions['match_type'] ?? 'exact';
|
||||||
|
|
||||||
|
if (! $path || ! $targetPath) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return match ($matchType) {
|
||||||
|
'exact' => $path === $targetPath,
|
||||||
|
'starts_with' => str_starts_with($path, $targetPath),
|
||||||
|
'contains' => str_contains($path, $targetPath),
|
||||||
|
'regex' => (bool) @preg_match($targetPath, $path),
|
||||||
|
default => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private function matchesEvent(Goal $goal, array $payload): bool
|
||||||
|
{
|
||||||
|
if (($payload['type'] ?? '') !== 'event') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$conditions = $goal->conditions;
|
||||||
|
$eventName = $conditions['event_name'] ?? '';
|
||||||
|
|
||||||
|
if (! $eventName || ($payload['event_name'] ?? '') !== $eventName) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$requiredCategory = $conditions['event_category'] ?? null;
|
||||||
|
if ($requiredCategory && ($payload['event_category'] ?? '') !== $requiredCategory) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function matchesDuration(Goal $goal, AnalyticsSession $session): bool
|
||||||
|
{
|
||||||
|
$requiredSeconds = $goal->conditions['seconds'] ?? 0;
|
||||||
|
|
||||||
|
return $session->duration >= $requiredSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function matchesPagesPerSession(Goal $goal, AnalyticsSession $session): bool
|
||||||
|
{
|
||||||
|
$requiredPages = $goal->conditions['page_count'] ?? 0;
|
||||||
|
|
||||||
|
return $session->pages_count >= $requiredPages;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,6 +53,11 @@
|
|||||||
<h4 class="px-3 text-xs font-semibold text-gray-400 uppercase tracking-wider mb-1">Events</h4>
|
<h4 class="px-3 text-xs font-semibold text-gray-400 uppercase tracking-wider mb-1">Events</h4>
|
||||||
<a href="{{ route('reports.events', [$website] + $q) }}" class="block rounded-md px-3 py-1.5 text-sm {{ $active('reports.events') }}">Overview</a>
|
<a href="{{ route('reports.events', [$website] + $q) }}" class="block rounded-md px-3 py-1.5 text-sm {{ $active('reports.events') }}">Overview</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h4 class="px-3 text-xs font-semibold text-gray-400 uppercase tracking-wider mb-1">Conversions</h4>
|
||||||
|
<a href="{{ route('reports.conversions', [$website] + $q) }}" class="block rounded-md px-3 py-1.5 text-sm {{ $active('reports.conversions') }}">Goals</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
|||||||
@@ -92,6 +92,44 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{-- Goal Completions --}}
|
||||||
|
@if ($goalConversions->isNotEmpty())
|
||||||
|
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
|
||||||
|
<div class="flex items-center justify-between mb-4">
|
||||||
|
<h3 class="text-base font-semibold text-gray-900">Goal Completions</h3>
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<a href="{{ route('reports.conversions', [$website] + request()->only(['range', 'from', 'to'])) }}" class="text-sm text-indigo-600 hover:text-indigo-800">View report</a>
|
||||||
|
<a href="{{ route('goals.index', $website) }}" class="text-sm text-gray-500 hover:text-gray-700">Manage goals</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||||
|
@foreach ($goalConversions->where('is_active', true)->take(6) as $goal)
|
||||||
|
<div class="rounded-lg border border-gray-200 p-4">
|
||||||
|
<div class="flex items-center justify-between mb-1">
|
||||||
|
<span class="text-sm font-medium text-gray-900 truncate">{{ $goal->name }}</span>
|
||||||
|
<span class="text-xs text-gray-500">{{ $goal->conversion_rate }}%</span>
|
||||||
|
</div>
|
||||||
|
<div class="text-2xl font-bold text-gray-900">{{ number_format($goal->completions) }}</div>
|
||||||
|
@if ($goal->total_value)
|
||||||
|
<div class="text-xs text-gray-500 mt-0.5">${{ number_format($goal->total_value, 2) }} value</div>
|
||||||
|
@endif
|
||||||
|
<div class="mt-2 w-full bg-gray-100 rounded-full h-1.5">
|
||||||
|
<div class="bg-emerald-500 h-1.5 rounded-full" style="width: {{ min($goal->conversion_rate, 100) }}%"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- Sparkline chart --}}
|
||||||
|
@if ($goalChartData->sum('completions') > 0)
|
||||||
|
<div class="mt-4" style="height: 120px;">
|
||||||
|
<canvas id="goal-sparkline"></canvas>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
{{-- Quick Report Links --}}
|
{{-- Quick Report Links --}}
|
||||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
|
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
|
||||||
<h3 class="text-base font-semibold text-gray-900 mb-4">Reports</h3>
|
<h3 class="text-base font-semibold text-gray-900 mb-4">Reports</h3>
|
||||||
@@ -123,9 +161,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h4 class="text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2">Events</h4>
|
<h4 class="text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2">Events & Conversions</h4>
|
||||||
<div class="space-y-1">
|
<div class="space-y-1">
|
||||||
<a href="{{ route('reports.events', [$website] + $q) }}" class="block text-sm text-indigo-600 hover:text-indigo-800">Events Overview</a>
|
<a href="{{ route('reports.events', [$website] + $q) }}" class="block text-sm text-indigo-600 hover:text-indigo-800">Events Overview</a>
|
||||||
|
<a href="{{ route('reports.conversions', [$website] + $q) }}" class="block text-sm text-indigo-600 hover:text-indigo-800">Conversions</a>
|
||||||
|
<a href="{{ route('goals.index', $website) }}" class="block text-sm text-indigo-600 hover:text-indigo-800">Manage Goals</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -218,6 +258,36 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Goal sparkline
|
||||||
|
const goalCanvas = document.getElementById('goal-sparkline');
|
||||||
|
if (goalCanvas) {
|
||||||
|
const goalRaw = @json($goalChartData);
|
||||||
|
new Chart(goalCanvas, {
|
||||||
|
type: 'line',
|
||||||
|
data: {
|
||||||
|
labels: goalRaw.map(d => d.period),
|
||||||
|
datasets: [{
|
||||||
|
data: goalRaw.map(d => d.completions),
|
||||||
|
borderColor: 'rgb(16, 185, 129)',
|
||||||
|
backgroundColor: 'rgba(16, 185, 129, 0.1)',
|
||||||
|
fill: true,
|
||||||
|
tension: 0.3,
|
||||||
|
pointRadius: 0,
|
||||||
|
borderWidth: 2,
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
plugins: { legend: { display: false }, tooltip: { enabled: false } },
|
||||||
|
scales: {
|
||||||
|
x: { display: false },
|
||||||
|
y: { display: false, beginAtZero: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function realtimeWidget(url) {
|
function realtimeWidget(url) {
|
||||||
return {
|
return {
|
||||||
count: {{ $activeVisitors }},
|
count: {{ $activeVisitors }},
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
@php
|
||||||
|
$goalType = old('type', $goal->type ?? '');
|
||||||
|
$conditions = old('conditions', $goal->conditions ?? []);
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
<div x-data="{ goalType: '{{ $goalType }}' }" class="space-y-6">
|
||||||
|
<div>
|
||||||
|
<x-input-label for="name" value="Goal Name" />
|
||||||
|
<x-text-input id="name" name="name" type="text" class="mt-1 block w-full" :value="old('name', $goal->name ?? '')" required autofocus placeholder="e.g. Completed Signup" />
|
||||||
|
<x-input-error class="mt-2" :messages="$errors->get('name')" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<x-input-label for="type" value="Goal Type" />
|
||||||
|
<select id="type" name="type" x-model="goalType" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500" required>
|
||||||
|
<option value="">Select a type...</option>
|
||||||
|
<option value="url_destination">URL Destination</option>
|
||||||
|
<option value="event_match">Event Match</option>
|
||||||
|
<option value="duration">Session Duration</option>
|
||||||
|
<option value="pages_per_session">Pages per Session</option>
|
||||||
|
</select>
|
||||||
|
<x-input-error class="mt-2" :messages="$errors->get('type')" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- URL Destination fields --}}
|
||||||
|
<div x-show="goalType === 'url_destination'" x-cloak class="rounded-lg border border-gray-200 p-4 space-y-4">
|
||||||
|
<h4 class="text-sm font-medium text-gray-700">URL Destination Conditions</h4>
|
||||||
|
<div>
|
||||||
|
<x-input-label for="conditions_path" value="Path" />
|
||||||
|
<x-text-input id="conditions_path" name="conditions[path]" type="text" class="mt-1 block w-full" :value="$conditions['path'] ?? ''" placeholder="/thank-you" />
|
||||||
|
<x-input-error class="mt-2" :messages="$errors->get('conditions.path')" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<x-input-label for="conditions_match_type" value="Match Type" />
|
||||||
|
<select id="conditions_match_type" name="conditions[match_type]" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
|
||||||
|
<option value="exact" @selected(($conditions['match_type'] ?? '') === 'exact')>Exact match</option>
|
||||||
|
<option value="starts_with" @selected(($conditions['match_type'] ?? '') === 'starts_with')>Starts with</option>
|
||||||
|
<option value="contains" @selected(($conditions['match_type'] ?? '') === 'contains')>Contains</option>
|
||||||
|
<option value="regex" @selected(($conditions['match_type'] ?? '') === 'regex')>Regex</option>
|
||||||
|
</select>
|
||||||
|
<x-input-error class="mt-2" :messages="$errors->get('conditions.match_type')" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- Event Match fields --}}
|
||||||
|
<div x-show="goalType === 'event_match'" x-cloak class="rounded-lg border border-gray-200 p-4 space-y-4">
|
||||||
|
<h4 class="text-sm font-medium text-gray-700">Event Match Conditions</h4>
|
||||||
|
<div>
|
||||||
|
<x-input-label for="conditions_event_name" value="Event Name" />
|
||||||
|
<x-text-input id="conditions_event_name" name="conditions[event_name]" type="text" class="mt-1 block w-full" :value="$conditions['event_name'] ?? ''" placeholder="signup" />
|
||||||
|
<x-input-error class="mt-2" :messages="$errors->get('conditions.event_name')" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<x-input-label for="conditions_event_category" value="Event Category (optional)" />
|
||||||
|
<x-text-input id="conditions_event_category" name="conditions[event_category]" type="text" class="mt-1 block w-full" :value="$conditions['event_category'] ?? ''" placeholder="conversion" />
|
||||||
|
<x-input-error class="mt-2" :messages="$errors->get('conditions.event_category')" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- Duration fields --}}
|
||||||
|
<div x-show="goalType === 'duration'" x-cloak class="rounded-lg border border-gray-200 p-4 space-y-4">
|
||||||
|
<h4 class="text-sm font-medium text-gray-700">Duration Condition</h4>
|
||||||
|
<div>
|
||||||
|
<x-input-label for="conditions_seconds" value="Minimum seconds on site" />
|
||||||
|
<x-text-input id="conditions_seconds" name="conditions[seconds]" type="number" class="mt-1 block w-full" :value="$conditions['seconds'] ?? ''" min="1" placeholder="180" />
|
||||||
|
<p class="mt-1 text-xs text-gray-500">Goal completes when a session lasts at least this many seconds.</p>
|
||||||
|
<x-input-error class="mt-2" :messages="$errors->get('conditions.seconds')" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- Pages per Session fields --}}
|
||||||
|
<div x-show="goalType === 'pages_per_session'" x-cloak class="rounded-lg border border-gray-200 p-4 space-y-4">
|
||||||
|
<h4 class="text-sm font-medium text-gray-700">Pages per Session Condition</h4>
|
||||||
|
<div>
|
||||||
|
<x-input-label for="conditions_page_count" value="Minimum pages viewed" />
|
||||||
|
<x-text-input id="conditions_page_count" name="conditions[page_count]" type="number" class="mt-1 block w-full" :value="$conditions['page_count'] ?? ''" min="1" placeholder="5" />
|
||||||
|
<p class="mt-1 text-xs text-gray-500">Goal completes when a session views at least this many pages.</p>
|
||||||
|
<x-input-error class="mt-2" :messages="$errors->get('conditions.page_count')" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<x-input-label for="default_value" value="Goal Value (optional)" />
|
||||||
|
<x-text-input id="default_value" name="default_value" type="number" step="0.01" class="mt-1 block w-full" :value="old('default_value', $goal->default_value ?? '')" placeholder="0.00" />
|
||||||
|
<p class="mt-1 text-xs text-gray-500">Monetary value assigned to each conversion.</p>
|
||||||
|
<x-input-error class="mt-2" :messages="$errors->get('default_value')" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="is_active" class="inline-flex items-center">
|
||||||
|
<input id="is_active" type="checkbox" name="is_active" value="1" class="rounded border-gray-300 text-indigo-600 shadow-sm focus:ring-indigo-500" {{ old('is_active', $goal->is_active ?? true) ? 'checked' : '' }}>
|
||||||
|
<span class="ms-2 text-sm text-gray-600">Active</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<x-app-layout>
|
||||||
|
<x-slot name="header">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<a href="{{ route('goals.index', $website) }}" class="text-gray-400 hover:text-gray-600">
|
||||||
|
<svg class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 19.5 8.25 12l7.5-7.5" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
<h2 class="font-semibold text-xl text-gray-800 leading-tight">Create Goal</h2>
|
||||||
|
<span class="text-sm text-gray-400">{{ $website->domain }}</span>
|
||||||
|
</div>
|
||||||
|
</x-slot>
|
||||||
|
|
||||||
|
<div class="py-12">
|
||||||
|
<div class="max-w-2xl mx-auto sm:px-6 lg:px-8">
|
||||||
|
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
|
||||||
|
<form method="POST" action="{{ route('goals.store', $website) }}">
|
||||||
|
@csrf
|
||||||
|
@include('goals._form', ['goal' => null])
|
||||||
|
|
||||||
|
<div class="mt-6 flex items-center gap-4">
|
||||||
|
<x-primary-button>Create Goal</x-primary-button>
|
||||||
|
<a href="{{ route('goals.index', $website) }}" class="text-sm text-gray-600 hover:text-gray-900">Cancel</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</x-app-layout>
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<x-app-layout>
|
||||||
|
<x-slot name="header">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<a href="{{ route('goals.index', $website) }}" class="text-gray-400 hover:text-gray-600">
|
||||||
|
<svg class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 19.5 8.25 12l7.5-7.5" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
<h2 class="font-semibold text-xl text-gray-800 leading-tight">Edit Goal: {{ $goal->name }}</h2>
|
||||||
|
<span class="text-sm text-gray-400">{{ $website->domain }}</span>
|
||||||
|
</div>
|
||||||
|
</x-slot>
|
||||||
|
|
||||||
|
<div class="py-12">
|
||||||
|
<div class="max-w-2xl mx-auto sm:px-6 lg:px-8">
|
||||||
|
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
|
||||||
|
<form method="POST" action="{{ route('goals.update', [$website, $goal]) }}">
|
||||||
|
@csrf
|
||||||
|
@method('PUT')
|
||||||
|
@include('goals._form', ['goal' => $goal])
|
||||||
|
|
||||||
|
<div class="mt-6 flex items-center gap-4">
|
||||||
|
<x-primary-button>Save Changes</x-primary-button>
|
||||||
|
<a href="{{ route('goals.index', $website) }}" class="text-sm text-gray-600 hover:text-gray-900">Cancel</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</x-app-layout>
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
<x-app-layout>
|
||||||
|
<x-slot name="header">
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<a href="{{ route('dashboard.show', $website) }}" class="text-gray-400 hover:text-gray-600">
|
||||||
|
<svg class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 19.5 8.25 12l7.5-7.5" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
<h2 class="font-semibold text-xl text-gray-800 leading-tight">Goals</h2>
|
||||||
|
<span class="text-sm text-gray-400">{{ $website->domain }}</span>
|
||||||
|
</div>
|
||||||
|
<a href="{{ route('goals.create', $website) }}" class="inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 transition">
|
||||||
|
Add Goal
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</x-slot>
|
||||||
|
|
||||||
|
<div class="py-12">
|
||||||
|
<div class="max-w-4xl mx-auto sm:px-6 lg:px-8">
|
||||||
|
@if (session('success'))
|
||||||
|
<div class="mb-4 rounded-md bg-green-50 p-4">
|
||||||
|
<p class="text-sm font-medium text-green-800">{{ session('success') }}</p>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if ($goals->isEmpty())
|
||||||
|
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||||
|
<div class="p-12 text-center">
|
||||||
|
<svg class="mx-auto h-12 w-12 text-gray-400" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M3 3v1.5M3 21v-6m0 0 2.77-.693a9 9 0 0 1 6.208.682l.108.054a9 9 0 0 0 6.086.71l3.114-.732a48.524 48.524 0 0 1-.005-10.499l-3.11.732a9 9 0 0 1-6.085-.711l-.108-.054a9 9 0 0 0-6.208-.682L3 4.5M3 15V4.5" />
|
||||||
|
</svg>
|
||||||
|
<h3 class="mt-2 text-sm font-semibold text-gray-900">No goals</h3>
|
||||||
|
<p class="mt-1 text-sm text-gray-500">Create goals to track conversions on your website.</p>
|
||||||
|
<div class="mt-6">
|
||||||
|
<a href="{{ route('goals.create', $website) }}" class="inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700">
|
||||||
|
Add Goal
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@else
|
||||||
|
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||||
|
<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">Name</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-left 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>
|
||||||
|
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="divide-y divide-gray-200">
|
||||||
|
@php
|
||||||
|
$typeLabels = [
|
||||||
|
'url_destination' => 'URL Destination',
|
||||||
|
'event_match' => 'Event Match',
|
||||||
|
'duration' => 'Duration',
|
||||||
|
'pages_per_session' => 'Pages / Session',
|
||||||
|
];
|
||||||
|
@endphp
|
||||||
|
@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-500">{{ $goal->default_value ? number_format($goal->default_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>
|
||||||
|
<td class="px-6 py-4 text-right text-sm space-x-3">
|
||||||
|
<a href="{{ route('goals.edit', [$website, $goal]) }}" class="text-indigo-600 hover:text-indigo-800">Edit</a>
|
||||||
|
<form method="POST" action="{{ route('goals.destroy', [$website, $goal]) }}" class="inline" onsubmit="return confirm('Delete this goal?')">
|
||||||
|
@csrf
|
||||||
|
@method('DELETE')
|
||||||
|
<button type="submit" class="text-red-600 hover:text-red-800">Delete</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</x-app-layout>
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
<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>
|
||||||
@@ -38,6 +38,18 @@ Route::middleware(['auth', 'verified'])->group(function () {
|
|||||||
|
|
||||||
Route::get('events', [ReportController::class, 'events'])->name('events');
|
Route::get('events', [ReportController::class, 'events'])->name('events');
|
||||||
Route::get('events/{eventName}', [ReportController::class, 'eventDetail'])->name('event-detail');
|
Route::get('events/{eventName}', [ReportController::class, 'eventDetail'])->name('event-detail');
|
||||||
|
|
||||||
|
Route::get('conversions', [ReportController::class, 'conversions'])->name('conversions');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Goals
|
||||||
|
Route::prefix('websites/{website}/goals')->name('goals.')->group(function () {
|
||||||
|
Route::get('/', [\App\Http\Controllers\GoalController::class, 'index'])->name('index');
|
||||||
|
Route::get('create', [\App\Http\Controllers\GoalController::class, 'create'])->name('create');
|
||||||
|
Route::post('/', [\App\Http\Controllers\GoalController::class, 'store'])->name('store');
|
||||||
|
Route::get('{goal}/edit', [\App\Http\Controllers\GoalController::class, 'edit'])->name('edit');
|
||||||
|
Route::put('{goal}', [\App\Http\Controllers\GoalController::class, 'update'])->name('update');
|
||||||
|
Route::delete('{goal}', [\App\Http\Controllers\GoalController::class, 'destroy'])->name('destroy');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user