meemalabs/analytics-laravel
publicClone
Push over the same URL. A password will not work: create a token under access tokens and use it in place of one.
- config
- src
- tests
- .gitignore 104 B
- CLAUDE.md 1.0 KB
- composer.json 1.0 KB
- phpunit.xml 528 B
- README.md 2.2 KB
Analytics Laravel
A Laravel log driver that sends errors and log entries to your ts-analytics server. Works like Flare or Bugsnag — configure it once and Laravel's exception handler automatically reports errors through the logging pipeline.
Installation
composer require meemalabs/analytics-laravelThe service provider is auto-discovered by Laravel.
Configuration
Publish the config file:
php artisan vendor:publish --tag=analytics-configAdd these to your .env:
ANALYTICS_TOKEN=ak_your_api_key
ANALYTICS_SITE_ID=my-siteAdd the analytics channel to your config/logging.php:
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['daily', 'analytics'],
],
'analytics' => [
'driver' => 'analytics',
'level' => 'error',
],
],That's it. Exceptions and error-level log entries are now sent to your analytics server automatically.
Config Reference
All options in config/analytics.php:
| Key | Env Var | Default | Description |
|---|---|---|---|
token | ANALYTICS_TOKEN | '' | API key (must start with ak_) |
site_id | ANALYTICS_SITE_ID | '' | Site identifier |
environment | ANALYTICS_ENVIRONMENT | APP_ENV | Environment name in reports |
enabled | ANALYTICS_ENABLED | true | Kill switch to disable reporting |
level | ANALYTICS_LOG_LEVEL | error | Minimum log level to report |
How It Works
- The package registers an
analyticsMonolog log driver viaLog::extend() - When Laravel logs an error (or an exception is thrown), the log record reaches the
AnalyticsLogHandler - If the log context contains a
Throwable, a full error report is built with class name, message, stack trace, file, and line - Otherwise, a message-level report is built from the log message
- The report is sent via HTTP POST to the analytics endpoint (
/errors/collect) with theX-Analytics-Tokenheader - The HTTP call uses a 5-second timeout and silently catches failures — logging never crashes the app
Requirements
- PHP 8.2+
- Laravel 11+
License
MIT