Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Metrics Laravel Package

directorytree/metrics

A simple, elegant way to record and query metrics in Laravel. Track page views, API calls, signups, and other countable events, with support for values, categories, dates, models, and custom attributes.

View on GitHub
Deep Wiki
Context7

Record metrics in your Laravel application

Frequently asked questions about Metrics
How do I install and set up DirectoryTree/Metrics in a Laravel 9+ project?
Run `composer require directorytree/metrics`, publish the migrations with `php artisan vendor:publish --tag=metrics-migrations`, and execute `php artisan migrate`. Optionally publish the config file with `--tag=metrics-config` for customization.
What Laravel versions and PHP versions does DirectoryTree/Metrics support?
The package requires PHP 8.1 or higher and Laravel 9.0 or newer. It follows Laravel’s conventions and integrates with Eloquent, Facades, and Artisan commands seamlessly.
Can I track hourly metrics or only daily aggregates with this package?
Yes, DirectoryTree/Metrics supports both hourly and daily metrics. Hourly metrics are stored as separate rows, while daily metrics aggregate data. Use `recordHourly()` for granular time-based tracking.
How do I associate metrics with Eloquent models (e.g., tracking user actions)?
Use the `HasMetrics` trait on your Eloquent model. This enables model-scoped metrics, allowing you to track actions like `user->recordMetric('login')` directly from the model instance.
Does DirectoryTree/Metrics support custom attributes for segmentation (e.g., tracking by country or device)?
Yes, you can attach custom attributes like `source`, `country`, or `device` to metrics. These are stored as JSON in the database and can be queried dynamically using Laravel’s query builder.
How do I enable Redis buffering for high-volume metric collection?
Publish the config file (`php artisan vendor:publish --tag=metrics-config`) and set `driver` to `redis` in the configuration. Metrics will buffer in Redis until committed via `php artisan metrics:commit`.
What are the performance implications of hourly metrics in large-scale applications?
Hourly metrics create 24x more rows than daily metrics, which can impact storage and query performance. Optimize with database indexing (e.g., composite index on `name`, `category`, `date`) and monitor Redis TTL settings for buffering.
Can I extend the metrics table schema or create custom metric models?
Yes, you can customize the schema by publishing and modifying migrations. For custom models, extend the base `Metric` model and bind a custom repository via the service provider’s `extend` method.
How do I test metrics recording and querying in PHPUnit?
Use Laravel’s `fake()` helper to mock the `Metrics` facade or `HasMetrics` trait. Wrap tests in transactions to avoid persisting fake data, and verify queries with `expectsQueries()` or database assertions.
What alternatives exist for Laravel metrics if I need real-time aggregations or dashboards?
For real-time analytics, consider packages like `spatie/laravel-analytics` or `laravel-ignition` for debugging. For dashboards, integrate with third-party tools like Grafana or Mixpanel, or use Laravel Scout for search-based metrics.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
vento/laravel-airbrake
wfeller/laravel-batch
maco-studios/mage-os-installer
busarm/armie
siberfx/laravel-logger
kfteam1991/dcat-admin
dashed/dashed-laposta
dashed/dashed-ecommerce-montaportal
dashed/dashed-ecommerce-etsy
neohq/string-blade-compiler
log1x/acf-composer
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core
nodisrupt/laravel-agent
sierratecnologia/media-manager