defixit/anonlytics-lib-php
PHP library for anonymous analytics (Anonlytics). Collect lightweight, privacy-first event data without cookies or personal identifiers, and send it to an Anonlytics server/API from your PHP apps and services.
Use Case Alignment:
readonly modifier and type declarations reduce runtime errors, improving reliability for production-grade tracking.ServiceProvider, Facade), the refactored Tracker class (with constructor property promotion) makes it easier to integrate via dependency injection. The updated README with "modern usage examples" suggests better compatibility with contemporary PHP/Laravel practices.Laravel Compatibility:
Exception class) and readonly properties align with Laravel’s modern PHP practices, reducing boilerplate in integrations.Architectural Constraints:
User, Order) to anonlytics events.Core Features:
JSON_THROW_ON_ERROR, and cURL resource checks reduce flaky API calls.readonly) and updated README lower the barrier to adoption.New Risks:
Tracker instantiation patterns.Dependencies:
illuminate/http) integration.| Risk Area | Severity | Mitigation |
|---|---|---|
| PHP 8.3 Breaking Change | High | Audit Laravel/PHP version compatibility; plan upgrade or isolation (e.g., Docker). |
| Constructor Refactor | Medium | Update integration code to use new Tracker instantiation (e.g., $tracker = new Tracker($token)). |
| Queue Integration Gaps | Medium | Implement custom queue worker for async event processing. |
| Error Handling Improvements | Low | Leverage new timeouts/validations to reduce flaky failures. |
| Lack of Laravel DX | Medium | Build a wrapper ServiceProvider with Laravel-specific helpers (e.g., anonlytics()->trackEvent($event)). |
| Testing Overhead | Low | Use added PHPUnit/PHPStan dependencies to enforce quality in CI. |
Tracker instantiations? (Constructor changes may break legacy code.)anonlytics:track Artisan command or Scout driver.)Tracker instantiations for constructor changes.composer require defixit/anonlytics-lib-php:^2.0.// Before (may break)
$tracker = new \Defixit\AnonlyticsLib\Tracker();
$tracker->setToken($token);
// After (recommended)
$tracker = new \Defixit\AnonlyticsLib\Tracker($token);
public function register()
{
$this->app->singleton(\Defixit\AnonlyticsLib\Tracker::class, function ($app) {
return new \Defixit\AnonlyticsLib\Tracker(config('anonlytics.token'));
});
}
TrackEventJob to offload events asynchronously.
use Defixit\AnonlyticsLib\Tracker;
class TrackEventJob implements ShouldQueue
{
public function handle(Tracker $tracker)
{
$tracker->track('user.signed_up', ['email' => $user->email]);
}
}
Tracker:
public function handle($request, Closure $next)
{
app(Tracker::class)->track('page.view', ['url' => $request->url()]);
return $next($request);
}
anonlytics API failures.curl, json, and openssl extensions are enabled (for HTTPS geoip calls).failed_jobs table for retries.| Phase | Tasks |
|---|---|
| Pre-Migration | Audit PHP/Laravel versions; back up existing analytics data. |
| Dependency Update | Update composer.json to ^2.0; resolve version conflicts. |
| Constructor Refactor | Update all Tracker instantiations to use new syntax. |
| Service Provider | Create Laravel abstraction for Tracker. |
| Queue Integration | Implement TrackEventJob for async processing. |
| Middleware/Events | Bind tracking to routes or Laravel events. |
| Testing | Write PHPUnit tests for new error handling; test timeout scenarios. |
| Rollout | Phase tracking in production (e.g., feature flags for critical events). |
How can I help you explore Laravel packages today?