me-shaon/laravel-request-analytics

Simple request data analytics package for Laravel projects


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Simple request data analytics package for Laravel projects.

Laravel request analytics

Installation

You can install the package via Composer:

composer require me-shaon/laravel-request-analytics

You can publish and run the migrations with:

php artisan vendor:publish --tag="request-analytics-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="request-analytics-config"

This is the contents of the published config file:

return [
    'route' => [
        'name' => 'request.analytics',
        'pathname' => env('REQUEST_ANALYTICS_PATHNAME', 'analytics'),
    ],

    'capture' => [
        'web' => true,
        'api' => true,
    ],

    'queue' => [
        'enabled' => env('REQUEST_ANALYTICS_QUEUE_ENABLED', true),
    ],

    'ignore-paths' => [

    ],
    
    'pruning' => [
        'enabled' => env('REQUEST_ANALYTICS_PRUNING_ENABLED', true),
        'days' => env('REQUEST_ANALYTICS_PRUNING_DAYS', 90),
    ],
];

Data Purning

You can delete your data from your database automatically.

If you are using Laravel 11+ then you may use model:prune command. Add this to your routes/console.php

use Illuminate\Support\Facades\Schedule;
 
Schedule::command('model:prune', [
            '--model' => 'MeShaon\RequestAnalytics\Models\RequestAnalytics',
        ])->daily();

Or try this bootstarp/app.php

use Illuminate\Console\Scheduling\Schedule;
->withSchedule(function (Schedule $schedule) {
     $schedule->command('model:prune', [
            '--model' => 'MeShaon\RequestAnalytics\Models\RequestAnalytics',
        ])->daily();
    })

If you are using Laravel 10 or below then you may use model:prune command. You may define all of your scheduled tasks in the schedule method of your application's App\Console\Kernel class

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    protected function schedule(Schedule $schedule): void
    {
        $schedule->command('model:prune', [
            '--model' => 'MeShaon\RequestAnalytics\Models\RequestAnalytics',
        ])->daily();
    }
}

You can publish the assets with this command:

php artisan vendor:publish --tag="request-analytics-assets"

Optionally, you can publish the views using

php artisan vendor:publish --tag="request-analytics-views"

Usage

$requestAnalytics = new MeShaon\RequestAnalytics();
echo $requestAnalytics->echoPhrase('Hello, MeShaon!');

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.