PHPackages                             binafy/laravel-user-monitoring - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. binafy/laravel-user-monitoring

ActiveLibrary[Framework](/categories/framework)

binafy/laravel-user-monitoring
==============================

Monitor your user and all activity on your application

v1.2.5(8mo ago)57425.7k↓39%44[1 PRs](https://github.com/binafy/laravel-user-monitoring/pulls)MITPHPPHP ^8.0CI passing

Since Jul 23Pushed 1mo ago9 watchersCompare

[ Source](https://github.com/binafy/laravel-user-monitoring)[ Packagist](https://packagist.org/packages/binafy/laravel-user-monitoring)[ Docs](https://github.com/binafy/laravel-user-monitoring)[ RSS](/packages/binafy-laravel-user-monitoring/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (23)Used By (0)

Laravel User Monitoring
-----------------------

[](#laravel-user-monitoring)

[![laravel-user-monitoring-banner](https://camo.githubusercontent.com/bd40d637b568762099448a5a129566c6baf3a38f3adf2bf1a817ebdcb916ea84/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c253230557365722532304d6f6e69746f72696e672e706e673f7468656d653d6461726b267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d62696e6166792532466c61726176656c2d757365722d6d6f6e69746f72696e67267061747465726e3d766f6c63616e6f4c616d70267374796c653d7374796c655f31266465736372697074696f6e3d4d6f6e69746f722b796f75722b757365722b616e642b616c6c2b61637469766974792b6f6e2b796f75722b6170706c69636174696f6e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)](https://camo.githubusercontent.com/bd40d637b568762099448a5a129566c6baf3a38f3adf2bf1a817ebdcb916ea84/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c253230557365722532304d6f6e69746f72696e672e706e673f7468656d653d6461726b267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d62696e6166792532466c61726176656c2d757365722d6d6f6e69746f72696e67267061747465726e3d766f6c63616e6f4c616d70267374796c653d7374796c655f31266465736372697074696f6e3d4d6f6e69746f722b796f75722b757365722b616e642b616c6c2b61637469766974792b6f6e2b796f75722b6170706c69636174696f6e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)

[![PHP Version Require](https://camo.githubusercontent.com/946ef18b8d5f034212a4ae455218b5f5332c9f7a93d809fbfff38428572fa9c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f62696e6166792f6c61726176656c2d757365722d6d6f6e69746f72696e672f706870)](https://packagist.org/packages/binafy/laravel-user-monitoring)[![Latest Stable Version](https://camo.githubusercontent.com/aed808368979bbcabe4492c06cea801101d3a7244eb897a8320a27f4b6b51ac5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62696e6166792f6c61726176656c2d757365722d6d6f6e69746f72696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/binafy/laravel-user-monitoring)[![Total Downloads](https://camo.githubusercontent.com/d7af9ba66a933f8384fcd92a78e00a957d1da4e7570f0b7346084b7792b59a31/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62696e6166792f6c61726176656c2d757365722d6d6f6e69746f72696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/binafy/laravel-user-monitoring)[![License](https://camo.githubusercontent.com/cbdacdeaf1d5ae298225ebd6d4dba88bd790fb3c3c097fede56d184930d45a95/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f62696e6166792f6c61726176656c2d757365722d6d6f6e69746f72696e67)](https://packagist.org/packages/binafy/laravel-user-monitoring)[![Passed Tests](https://github.com/binafy/laravel-user-monitoring/actions/workflows/tests.yml/badge.svg)](https://github.com/binafy/laravel-user-monitoring/actions/workflows/tests.yml)[![Ask DeepWiki](https://camo.githubusercontent.com/0f5ae213ac378635adeb5d7f13cef055ad2f7d9a47b36de7b1c67dbe09f609ca/68747470733a2f2f6465657077696b692e636f6d2f62616467652e737667)](https://deepwiki.com/binafy/laravel-user-monitoring)

- [Introduction](#introduction)
- [Installation](#installation)
- [Usage](#usage)
    - [Configuration](#configuration)
        - [Routes Configuration](#routes-configuration)
    - [User Configuration](#user-configuration)
        - [Foreign Key Type (UUID, ULID, ID)](#foreign-key-type-uuid-ulid-id)
    - [Visit Monitoring](#visit-monitoring)
        - [Delete Visit Monitoring Records By Specific Days](#delete-visit-monitoring-records-by-specific-days)
        - [Turn ON-OFF](#turn-on-off)
        - [Views](#visit-monitoring-views)
        - [Ajax Requests](#ajax-requests)
        - [Visit Monitoring Guest Mode](#visit-monitoring-guest-mode)
        - [Visit Monitoring Custom Conditions](#visit-monitoring-custom-conditions)
    - [Action Monitoring](#action-monitoring)
        - [Views](#action-monitoring-views)
        - [Reverse Proxy Config](#action-monitoring-reverse-proxy-config)
        - [Action Monitoring Guest Mode](#action-monitoring-guest-mode)
        - [Action Monitoring Custom Conditions](#action-monitoring-custom-conditions)
    - [Authentication Monitoring](#authentication-monitoring)
        - [Views](#authentication-monitoring-views)
    - [How to use in big projects](#how-to-use-in-big-projects)
- [Contributors](#contributors)
- [Security](#security)
- [Changelog](#changelog)
- [License](#license)
- [Star History](#start-history)
- [Conclusion](#conclusion)
- [Donate](#donate)

Introduction
------------

[](#introduction)

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 better understand 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. Please don't worry, 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!

[AI Documentation](https://deepwiki.com/binafy/laravel-user-monitoring)

Installation
------------

[](#installation)

- `PHP >= 8.0`
- `Laravel >= 9.0`

You can install the package with Composer:

```
composer require binafy/laravel-user-monitoring
```

Publish
-------

[](#publish)

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.

Usage
-----

[](#usage)

The `Laravel-User-Monitoring` needs to use middleware, traits, etc, and it's not hard, enjoys :)

Configuration
-------------

[](#configuration)

Routes Configuration
--------------------

[](#routes-configuration)

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 that, 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',
    ],
],
```

User Configuration
------------------

[](#user-configuration)

You can configure 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, like `customer_id`.
- `table`: You can write your users table name if it 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.

### Foreign Key Type (UUID, ULID, ID)

[](#foreign-key-type-uuid-ulid-id)

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` or `ulid` or `id`.

Visit Monitoring
----------------

[](#visit-monitoring)

When you want to monitor all views of your application, you must follow below:

1. Publish the [Migrations](#publish)
2. Use `VisitMonitoringMiddleware` in Kernel.php. You can go to the `App/Http` folder and open the `Kernel.php` file and add `VisitMonitoringMiddleware` into your middleware, for example:

```
use Binafy\LaravelUserMonitoring\Middlewares\VisitMonitoringMiddleware;

// Laravel 11.x or less
protected $middlewareGroups = [
    'web' => [
        ...
        VisitMonitoringMiddleware::class,
    ],

    'api' => [...],
];

// Laravel 12.x
->withMiddleware(function (Middleware $middleware): void {
  $middleware->appendToGroup('web', [VisitMonitoringMiddleware::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',
    ],
],
```

### Delete Visit Monitoring Records By Specific Days

[](#delete-visit-monitoring-records-by-specific-days)

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](https://laravel.com/docs/scheduling) to fire-related command, so go to `app/Console/Kernel.php` and do like this:

```
