A lightweight, self-hosted analytics package for Laravel.
composer require mccomaschris/marco-analytics
After installing the package, you can publish the configuration file to customize tracking settings:
php artisan vendor:publish --tag=config
This will create a config file at:
config/marco-analytics.php
return [
// Enable or disable IP tracking
'track_ip' => true,
// File extensions to exclude from tracking
'ignored_extensions' => [
'js', 'css', 'png', 'jpg', 'jpeg', 'gif', 'svg', 'webp', 'ico', 'woff', 'woff2', 'ttf', 'eot', 'otf'
],
// URL paths to exclude from tracking
'ignored_paths' => [
'admin/*', // Ignore all admin routes
'login', // Ignore login page
'register', // Ignore registration page
'password/*', // Ignore password reset pages
'api/*', // Ignore all API requests
'debugbar/*', // Ignore Laravel Debugbar
],
];
'ignored_paths' => [
'checkout', // Ignore checkout page
'profile/*', // Ignore all profile-related routes
],
After making changes, clear the config cache to apply them:
php artisan config:clear
This package includes an Artisan command to purge old analytics data from the database.
By default, this command removes analytics records older than 30 days:
php artisan analytics:purge
You can also specify a custom number of days:
php artisan analytics:purge 60
This would delete all analytics records older than 60 days.
To automatically delete old analytics records every day, add this to your app/Console/Kernel.php
:
protected function schedule(Schedule $schedule)
{
$schedule->command('analytics:purge')->daily();
}
This will run the cleanup automatically every day.