stounhandj/laravel-traffic-metrics

v0.1 2022-05-30 06:22 UTC

This package is auto-updated.

Last update: 2024-10-29 06:25:30 UTC


README

Total Downloads Latest Stable Version License

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

  1. 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
  1. Set up a connection to kafka: In config/kafka.php setup brokers. More information here
  2. Add provider in config/app.php:
StounhandJ\LaravelTrafficMetrics\TrafficMetricsProvider::class,
  1. Add Middleware in Kernel.php:
'metrics' => \StounhandJ\LaravelTrafficMetrics\Middleware\MetricsMiddleware::class,

Usage

  1. Use Middleware:
Route::get('/p/{product:id}', [ProductController::class, "index"])
    ->middleware("metrics")
    ->name("product.details");
  1. Put the handler on permanent execution:
php artisan metrics:check
  1. Getting metrics
Metrics::findByUri("/welcome")->getViews()