laravel-traffic-metrics maintained by stounhandj
HtmlDom-Laravel
A package for Laravel 6, 7, 8 to metrics unique page views using kafka
Installation
$ composer require stounhandj/laravel-traffic-metrics
Or
{
"require": {
"stounhandj/laravel-traffic-metrics": "^0.1.0"
}
}
Setup
- Use following:
php artisan vendor:publish --tag=traffic-metrics
php artisan vendor:publish --tag=laravel-kafka-config
According to the standard, a unique visit is considered to be a user's visit to the page once every 1 minute. This can be changed in the configuration. 2. Run migrations
php artisan migrate
- Set up a connection to kafka: In config/kafka.php setup brokers. More information here
- Add provider in config/app.php:
StounhandJ\LaravelTrafficMetrics\TrafficMetricsProvider::class,
- Add Middleware in Kernel.php:
'metrics' => \StounhandJ\LaravelTrafficMetrics\Middleware\MetricsMiddleware::class,
Usage
- Use Middleware:
Route::get('/p/{product:id}', [ProductController::class, "index"])
->middleware("metrics")
->name("product.details");
- Put the handler on permanent execution:
php artisan metrics:check
- Getting metrics
Metrics::findByUri("/welcome")->getViews()