laravel-analytics maintained by itmosoft
Laravel Analytics
Application event tracking and time-based metric aggregation for Laravel applications.
Requirements
- PHP 8.3+
- Laravel 12 or 13
Installation
composer require itmosoft/laravel-analytics
php artisan vendor:publish --tag=itmosoft-analytics-config
php artisan migrate
Track events
use ItmoSoft\Analytics\AnalyticsManager;
$analytics = app(AnalyticsManager::class);
$analytics->track(
name: 'order.placed',
actor: auth()->user(),
subject: $order,
properties: ['total' => 125.00, 'currency' => 'USD'],
source: 'checkout',
);
Actor and subject are optional polymorphic Eloquent models. Events can also be anonymous:
$analytics->track('landing_page.viewed', properties: ['campaign' => 'spring']);
Query metrics
$total = $analytics->count(
'order.placed',
from: now()->startOfMonth(),
to: now()->endOfMonth(),
);
$byName = $analytics->countByName(
from: now()->startOfMonth(),
to: now()->endOfMonth(),
);
$daily = $analytics->countByDay(
'order.placed',
from: now()->startOfMonth(),
to: now()->endOfMonth(),
);
countByName returns a collection keyed by event name. countByDay returns a collection keyed
by YYYY-MM-DD.
Data model
Each event stores its name, optional actor and subject, JSON properties, optional source, and occurrence timestamp. Occurrence time is separate from database creation time.
Responsibilities and limitations
- Validate and authorize event tracking at your application boundary.
- Avoid putting secrets, payment credentials, or sensitive personal data in event properties.
- This package stores raw events and calculates basic counts at query time.
- It does not provide dashboards, precomputed rollups, unique-user metrics, funnels, attribution, retention cohorts, exports, or a retention scheduler.
- Database timezone conventions should be consistent across event writers and reports.
Testing
composer install
composer test
License
MIT. See LICENSE.