PHPackages                             panchodp/laravel-page-monitor - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. panchodp/laravel-page-monitor

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

panchodp/laravel-page-monitor
=============================

Monitor page visits in your Laravel application. Each visit is stored in the database with information about the user (authenticated or guest), device type, IP address, and timestamp.

v1.3.1(3w ago)016↓100%MITPHPPHP ^8.4CI passing

Since May 4Pushed 3w agoCompare

[ Source](https://github.com/PanchoDP/laravel-page-monitor)[ Packagist](https://packagist.org/packages/panchodp/laravel-page-monitor)[ RSS](/packages/panchodp-laravel-page-monitor/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (2)Dependencies (6)Versions (9)Used By (0)

 [![Logo for Laravel Page Monitor](art/monitor.webp)](art/monitor.webp)

[![PHP](https://camo.githubusercontent.com/80c4564163cef31b2a66baaeb95a5bf4a418bcb5242a5ae707b94c2f4811e742/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e342532422d626c7565)](https://camo.githubusercontent.com/80c4564163cef31b2a66baaeb95a5bf4a418bcb5242a5ae707b94c2f4811e742/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e342532422d626c7565)[![Total Downloads](https://camo.githubusercontent.com/7efe7903adcc9ae3f04cdb921deb5e60021b4ed454f8d6ecd39293cebd584b97/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70616e63686f64702f6c61726176656c2d706167652d6d6f6e69746f723f)](https://camo.githubusercontent.com/7efe7903adcc9ae3f04cdb921deb5e60021b4ed454f8d6ecd39293cebd584b97/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70616e63686f64702f6c61726176656c2d706167652d6d6f6e69746f723f)[![Latest Stable Version](https://camo.githubusercontent.com/b7143816094bf97e95f6eea72066f0e0c75e6e50982c92caf255c2f856df38c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70616e63686f64702f6c61726176656c2d706167652d6d6f6e69746f722e7376673f)](https://packagist.org/packages/panchodp/laravel-page-monitor)[![License](https://camo.githubusercontent.com/5caa455d8debc46fb23abbadb45a733a937f3910a73fc875c2f7820468e1bb54/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e)](https://packagist.org/packages/panchodp/laravel-page-monitor)[![Tests](https://github.com/PanchoDP/laravel-page-monitor/actions/workflows/tests.yml/badge.svg)](https://github.com/PanchoDP/laravel-page-monitor/actions/workflows/tests.yml)

Laravel Page Monitor
====================

[](#laravel-page-monitor)

Monitor page visits in your Laravel application. Each visit is stored in the database with information about the user (authenticated or guest), device type, IP address, and timestamp.

Compatibility
-------------

[](#compatibility)

LaravelPHPPackage13.x8.4+^1.x12.x8.4+^1.x11.x8.4+^1.xInstallation
------------

[](#installation)

```
composer require panchodp/laravel-page-monitor
```

### Publish everything at once

[](#publish-everything-at-once)

```
php artisan vendor:publish --provider="Panchodp\LaravelPageMonitor\LaravelPageMonitorServiceProvider"
```

Or publish each piece individually:

```
# Migration
php artisan vendor:publish --provider="Panchodp\LaravelPageMonitor\LaravelPageMonitorServiceProvider" --tag="laravel-page-monitor-migrations"

# Configuration
php artisan vendor:publish --provider="Panchodp\LaravelPageMonitor\LaravelPageMonitorServiceProvider" --tag="laravel-page-monitor-config"

# Views
php artisan vendor:publish --provider="Panchodp\LaravelPageMonitor\LaravelPageMonitorServiceProvider" --tag="laravel-page-monitor-views"

# Assets (CSS/JS)
php artisan vendor:publish --provider="Panchodp\LaravelPageMonitor\LaravelPageMonitorServiceProvider" --tag="laravel-page-monitor-assets"
```

Then run the migration:

```
php artisan migrate
```

This creates the `page_visits` table with the following columns:

ColumnDescription`id`Auto-increment primary key`page`Route name or full URL`user_id`Authenticated user ID, `null` for guests`session_id`Session identifier`ip_address`Visitor IP (supports IPv4 and IPv6)`device_type``mobile`, `tablet`, or `desktop``user_agent`Raw User-Agent string`visited_at`Visit timestampConfiguration
-------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --provider="Panchodp\LaravelPageMonitor\LaravelPageMonitorServiceProvider" --tag="laravel-page-monitor-config"
```

This creates `config/laravel_page_monitor.php`:

```
return [
    'enabled'         => env('MONITOR_ENABLED', true),
    'user_model'      => env('PAGE_MONITOR_USER_MODEL', 'App\Models\User'),
    'middleware'      => ['web', 'auth'],
    'track_all'       => env('MONITOR_TRACK_ALL', false),
    'track_guests'    => env('MONITOR_TRACK_GUESTS', true),
    'excluded_routes' => [],
    'pruning' => [
        'retention_days' => env('MONITOR_RETENTION_DAYS', 30),
        'max_records'    => env('MONITOR_MAX_RECORDS', 10000),
    ],
    'per_page' => env('MONITOR_PER_PAGE', 50),
];
```

- `enabled`: Enable or disable the monitor globally. Defaults to `true`.
- `user_model`: The Eloquent model used to associate authenticated visits. Change this if your application uses a custom User model.
- `middleware`: Middleware applied to the `/page-monitor` dashboard route. Defaults to `['web', 'auth']`.
- `track_all`: When `true`, all routes in the `web` middleware group are tracked automatically — no need to add `visits-count` to each route manually. The `/page-monitor` dashboard is always excluded. Defaults to `false`.
- `track_guests`: When `false`, only visits from authenticated users are recorded. Guest visits are silently ignored. Defaults to `true`.
- `excluded_routes`: Route names that should never be tracked. Supports wildcards. Livewire update requests are always excluded automatically regardless of this list. Defaults to `[]`.
- `pruning`: Controls automatic cleanup of old records (see [Artisan Commands](#artisan-commands)).
- `per_page`: Number of records shown per page in the dashboard. Defaults to `50`.

```
// Use a custom user model
'user_model' => 'App\Models\Admin',

// or via .env
PAGE_MONITOR_USER_MODEL=App\Models\Admin
```

Usage
-----

[](#usage)

### 1. Track pages

[](#1-track-pages)

**Option A — Track all pages automatically**

Set `track_all` to `true` in the config (or via `.env`) and every route in the `web` group is tracked with zero additional setup:

```
MONITOR_TRACK_ALL=true
```

**Option B — Track specific routes manually**

Add the `visits-count` middleware only to the routes you want to monitor:

```
// Single route
Route::get('/home', HomeController::class)->middleware('visits-count');

// Route group
Route::middleware('visits-count')->group(function () {
    Route::get('/home', HomeController::class);
    Route::get('/about', AboutController::class);
});
```

### 2. View the dashboard

[](#2-view-the-dashboard)

Navigate to `/page-monitor` to see all recorded visits with page, user, device type, IP address, and timestamp.

The dashboard requires authentication by default (`auth` middleware). To restrict access further, define the `view-page-monitor` gate in your `AppServiceProvider`:

```
use Illuminate\Support\Facades\Gate;

Gate::define('view-page-monitor', fn ($user) => $user->isAdmin());
```

You can also replace the middleware entirely via the config:

```
// config/laravel_page_monitor.php
'middleware' => ['web', 'auth', 'role:admin'],
```

Facade
------

[](#facade)

You can query visit data anywhere in your application using the Facade:

```
use Panchodp\LaravelPageMonitor\Facades\LaravelPageMonitor;

// Pages grouped and sorted by most visited first
$ranking = LaravelPageMonitor::ranking();

// Pages grouped and sorted alphabetically A → Z
$byName = LaravelPageMonitor::byNameOrder(desc: false);

// Pages grouped and sorted alphabetically Z → A
$byNameDesc = LaravelPageMonitor::byNameOrder(desc: true);
```

Each method returns an `Illuminate\Database\Eloquent\Collection` where each item contains `page`, `visits` (total count), and `last_visit`.

You can also query the `PageVisit` model directly for full control:

```
use Panchodp\LaravelPageMonitor\Models\PageVisit;

// All visits for a specific page
PageVisit::where('page', 'home')->get();

// Visits by authenticated users only
PageVisit::whereNotNull('user_id')->with('user')->get();

// Visits from mobile devices today
PageVisit::where('device_type', 'mobile')
    ->whereDate('visited_at', today())
    ->get();
```

Artisan Commands
----------------

[](#artisan-commands)

### Prune old records

[](#prune-old-records)

```
php artisan pagemonitor:prune
```

Deletes records based on the `pruning` config. Add it to your schedule for automatic cleanup:

```
// routes/console.php
Schedule::command('pagemonitor:prune')->daily();
```

You can tune the limits in the config (or disable them with `null`):

```
'pruning' => [
    'retention_days' => 30,    // delete visits older than 30 days
    'max_records'    => 10000, // keep at most 10,000 records
],
```

### Reset all visit records

[](#reset-all-visit-records)

```
php artisan pagemonitor:reboot-count
```

Deletes all recorded visits from the database.

Contributing
------------

[](#contributing)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License
-------

[](#license)

[MIT](https://github.com/PanchoDP/laravel-page-monitor/blob/master/LICENSE.md)

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance94

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

8

Last Release

27d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fbd7042f63f458531364245f5985884dea96cc46d2b7844d5dd8c0bcad61f8e8?d=identicon)[Francisco de Pablo](/maintainers/Francisco%20de%20Pablo)

---

Top Contributors

[![PanchoDP](https://avatars.githubusercontent.com/u/68023592?v=4)](https://github.com/PanchoDP "PanchoDP (16 commits)")

---

Tags

phplaraveltrackingpagesanalyticsmonitorvisits

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/panchodp-laravel-page-monitor/health.svg)

```
[![Health](https://phpackages.com/badges/panchodp-laravel-page-monitor/health.svg)](https://phpackages.com/packages/panchodp-laravel-page-monitor)
```

###  Alternatives

[bugsnag/bugsnag-laravel

Official Bugsnag notifier for Laravel applications.

90335.7M37](/packages/bugsnag-bugsnag-laravel)[treblle/treblle-laravel

Runtime Intelligence Platform

135220.1k](/packages/treblle-treblle-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
