- Introduction
- Installation
- Usage
- Contributors
- Security
- Changelog
- License
- Star History
- Conclusion
- Donate
Welcome to the world of enhanced user monitoring with the groundbreaking Laravel User Monitoring
package! Developed by the brilliant minds at Binafy
, this innovative open-source solution is designed to empower Laravel developers and website administrators with invaluable insights into user activities.
Tracking user behavior and interactions is now made effortless, allowing you to gain a deeper understanding of your users' engagement, preferences, and pain points. With its seamless integration into Laravel projects, this package opens up a realm of possibilities, enabling you to optimize user experiences, detect bottlenecks, and make data-driven decisions for your platform's success.
Experience real-time monitoring like never before, as you access comprehensive analytics and visualize user interactions with ease. Rest assured, your users' data is handled securely, respecting privacy while giving you the tools to improve your application's performance and user satisfaction.
Whether you are building a new project or looking to enhance an existing one, "Laravel User Monitoring" is the missing piece to elevate your web applications to new heights. So, why wait? Dive into the world of intelligent user monitoring and witness the transformation of your Laravel-powered application today!
You can install the package with Composer.
composer require binafy/laravel-user-monitoring
If you want to publish a config file you can use this command:
php artisan vendor:publish --tag="laravel-user-monitoring-config"
If you want to publish the migrations you can use this command:
php artisan vendor:publish --tag="laravel-user-monitoring-migrations"
If you want to publish the views you can use this command:
php artisan vendor:publish --tag="laravel-user-monitoring-views"
If you want to publish the middleware you can use this command:
php artisan vendor:publish --tag="laravel-user-monitoring-middlewares"
If you want to publish the routes you can use this command:
php artisan vendor:publish --tag="laravel-user-monitoring-routes"
For convenience, you can use this command to publish config, migration, and ... files:
php artisan vendor:publish --provider="Binafy\LaravelUserMonitoring\Providers\LaravelUserMonitoringServiceProvider"
After publishing, run the php artisan migrate
command.
The Laravel-User-Monitoring
, needs to use middleware, traits, etc ... and it's not hard, enjoys :)
If you want to customize the routes, you can publish the route file with this command:
php artisan vendor:publish --tag="laravel-user-monitoring-routes"
After, you can go to the routes/user-monitoring.php
file and customize the routes.
Also, if you want to change the route file name, you can go to the config file and change the file_path
:
/*
* Main configuration settings for the package.
*/
'config' => [
'routes' => [
/*
* Path to the route file that handles user monitoring routes.
*/
'file_path' => 'routes/user-monitoring.php',
],
],
You can config your user with the user-monitoring.php
configuration file:
'user' => [
/*
* Specify the fully qualified class name of the user model.
*/
'model' => 'App\Models\User',
/*
* Name of the foreign key column linking user data to other models.
*/
'foreign_key' => 'user_id',
/*
* Name of the table storing user data.
*/
'table' => 'users',
/*
* Defines the authentication guards used for verifying the user.
* Multiple guards can be specified for flexible authentication strategies.
* Ensure these guards are configured correctly in the 'guards' section of the auth.php config file.
*/
'guards' => ['web'],
/*
* Specify the type of foreign key being used (e.g., 'id', 'uuid', 'ulid').
* For non-standard IDs, make sure to add the relevant traits to your models.
*/
'foreign_key_type' => 'id', // Options: uuid, ulid, id
/*
* Attribute of the user model used to display the user's name.
* If you wish to use a different attribute (e.g., username), change this value accordingly.
*/
'display_attribute' => 'name',
],
model
: If your user model exists in another place, you can change it to the correct namespace.foreign_key
: You can set the user foreign_key name, likecustomer_id
.table
: You can write your users table name if is not `users.guards
: The guards are used to authenticate.foreign_key_type
: The foreign key type (uuid-ulid-id).display_attribute
: The special attribute of the user that you want to show in views.
If you are using uuid
or ulid
, you can change foreign_key_type
to your correct foreign key type:
'user' => [
...
/*
* Specify the type of foreign key being used (e.g., 'id', 'uuid', 'ulid').
* For non-standard IDs, make sure to add the relevant traits to your models.
*/
'foreign_key_type' => 'id', // Options: uuid, ulid, id
],
NOTE: You must write
uuid
orulid
orid
.
When you want to monitor all views of your application, you must follow below:
-
Publish the Migrations
-
Use
VisitMonitoringMiddleware
in Kernel.php, you can go to theApp/Http
folder and open theKernel.php
file and addVisitMonitoringMiddleware
into your middleware for example:
protected $middlewareGroups = [
'web' => [
...
\Binafy\LaravelUserMonitoring\Middlewares\VisitMonitoringMiddleware::class,
],
'api' => [
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
After, you can see all pages monitoring :)
If you want to disable monitoring for specific pages you can go to user-monitoring.php
that exists in the config
folder and add pages into the visit_monitoring
key:
'visit_monitoring' => [
/*
* List of pages that should be excluded from visit monitoring.
* Add route names or URL paths to this array if you want to exclude certain pages.
*/
'except_pages' => [
'user-monitoring/visits-monitoring',
'user-monitoring/actions-monitoring',
'user-monitoring/authentications-monitoring',
],
],
You may delete records by specific days, Laravel-User-Monitoring also supports this 🤩.
First, you need to go to the user-monitoring
config file and highlight the days that you want to delete:
'visit_monitoring' => [
...
/*
* Set the number of days after which visit records should be automatically deleted.
* Set to 0 to disable automatic deletion.
*
* To enable automatic deletion, configure Laravel's task scheduling as outlined here:
* https://laravel.com/docs/scheduling
*/
'delete_days' => 0,
],
After, you need to use Task Scheduling to fire-related command, so go to app/Console/Kernel.php
and do like this:
<?php
namespace App\Console;
...
use Binafy\LaravelUserMonitoring\Commands\RemoveVisitMonitoringRecordsCommand;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*/
protected function schedule(Schedule $schedule): void
{
$schedule->command(RemoveVisitMonitoringRecordsCommand::class)->hourly();
}
}
You can change hourly
to minute
or second
, for more information you can read Schedule Frequency Options.
Maybe you want to turn off visit monitoring for some or always, you can use configuration to turn it off:
'visit_monitoring' => [
...
/*
* Enable or disable the visit monitoring feature.
* Set false to disable tracking of user visits.
*/
'turn_on' => true,
...
]
The Laravel-User-Monitoring
also has amazing views that you can use very easily, just need to go to the /user-monitoring/visits-monitoring
URL, and enjoy:
Maybe you may disable record visits for Ajax
requests, you can use config to disable it:
'visit_monitoring' => [
...
/*
* Enable or disable monitoring for AJAX requests.
* Set to false if you do not wish to track AJAX-based page loads.
*/
'ajax_requests' => true,
...
],
When set to false, Ajax requests will not be recorded.
If you want to monitor your model actions, you can use the Actionable
trait in your model:
<?php
namespace App\Models;
use Binafy\LaravelUserMonitoring\Traits\Actionable;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
use Actionable;
}
Now when a product is read, created, updated, or deleted, you can see which users doing that.
If you want to disable some actions like created, you can use the config file:
'action_monitoring' => [
...
/*
* Enable or disable monitoring of specific actions (e.g., store, update, delete).
* Set to true to monitor actions or false to disable.
*/
'on_store' => true,
'on_update' => true,
'on_destroy' => true,
'on_read' => true,
'on_restore' => false,
'on_replicate' => false,
],
Laravel-User-Monitoring
also has amazing views that you can use very easily, just need to go to the /user-monitoring/actions-monitoring
URL, and enjoy:
Have you ever thought about monitoring the entry and exit of users of your application? Now you can :)
If you want to monitor users when logging in or logout of your application, you need to migrate the migrations to the config file and change true for monitoring authentication.
'authentication_monitoring' => [
...
/*
* Enable or disable monitoring of user login and logout events.
* Set to true to track these actions, or false to disable.
*/
'on_login' => true,
'on_logout' => true,
],
If you are using Reverse Proxy (Nginx or Cloudflare), you can use config to get real IP from a specific header like X-Real-IP
or X-Forwarded-For
:
'action_monitoring' => [
...
/*
* If your application is behind a reverse proxy (e.g., Nginx or Cloudflare),
* enable this setting to fetch the real client IP from the proxy headers.
*/
'use_reverse_proxy_ip' => false,
/*
* The header used by reverse proxies to forward the real client IP.
* Common values are 'X-Forwarded-For' or 'X-Real-IP'.
*/
'real_ip_header' => 'X-Forwarded-For',
],
Laravel-User-Monitoring
also has amazing views that you can use very easily, need to go to the /user-monitoring/authentications-monitoring
URL, and enjoy:
If you want to use Laravel-User-Monitoring
for big projects, you have lots of ways, but I want to give some tips and ideas to help you:
If you have an idea for this section you can create PRs or issues to help us.
- You can use this package with Cache
- You can make a separate DB and connect to your project to separate monitoring and application.
Thanks to all the people who contributed. Contributors.
If you discover any security-related issues, please email binafy23@gmail.com
instead of using the issue tracker.
The changelog can be found in the CHANGELOG.md
file of the GitHub repository. It lists the changes, bug fixes, and improvements made to each Laravel User Monitoring package version.
The MIT License (MIT). Please see License File for more information.
Congratulations! You have successfully installed and integrated the Laravel User Monitoring package into your Laravel application. By effectively logging and analyzing user activity, you can gain valuable insights that can help you improve your application's user experience and performance. If you have any questions or need any more help, please refer to the documentation or ask for help from the package's GitHub repository. Happy monitoring!
If this package is helpful for you, you can buy a coffee for me :) ❤️
- Iraninan Gateway: https://daramet.com/milwad_khosravi
- Paypal Gateway: SOON
- MetaMask Address:
0xf208a562c5a93DEf8450b656c3dbc1d0a53BDE58