Capture website traffic.
This package isn't on Packagist. Add it as a repository to the composer.json
file:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/AdrianBav/traffic"
}
]
Next, require the package using composer:
composer require adrianbav/traffic
Most configuration can be done via the environment variables. However, to publish the config, run the vendor publish command:
php artisan vendor:publish --provider="AdrianBav\Traffic\TrafficServiceProvider"
To create the necessary tables, run the migrate command:
php artisan traffic:migrate
This packages provides a middleware which can be added as a global middleware or as a single route.
To record visits:
use AdrianBav\Traffic\Middlewares\RecordVisits;
// in `app/Http/Kernel.php`
protected $middleware = [
// ...
RecordVisits::class
];
// in a routes file
Route::post('/article', function () {
// ...
})->middleware(RecordVisits::class);
To get a visit count for the specified site:
use AdrianBav\Traffic\Facades\Traffic;
$blogVisitCount = Traffic::visits('blog_site_slug');
To get a robot visit count for the specified site:
use AdrianBav\Traffic\Facades\Traffic;
$bioRobotVisitCount = Traffic::robots('bio_site_slug');