itmosoft / laravel-analytics
Application event tracking and time-based metric aggregation for Laravel applications.
v1.0.0
2026-11-17 10:36 UTC
Requires
- php: ^8.3
- illuminate/contracts: ^12.0|^13.0
- illuminate/database: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^10.0|^11.0
- phpunit/phpunit: ^11.5|^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
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.