PHPackages                             nmehroj/route-usage-tracker - 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. nmehroj/route-usage-tracker

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

nmehroj/route-usage-tracker
===========================

Laravel Route Usage Tracker Package with Vue.js 3 Dashboard and Inertia.js Support

v1.0.2(5mo ago)07MITPHPPHP &gt;=8.1

Since Nov 12Pushed 5mo agoCompare

[ Source](https://github.com/N-Mehroj/RouteUsageTracker)[ Packagist](https://packagist.org/packages/nmehroj/route-usage-tracker)[ Docs](https://github.com/N-Mehroj/RouteUsageTracker)[ RSS](/packages/nmehroj-route-usage-tracker/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (7)Used By (0)

Laravel Route Usage Tracker
===========================

[](#laravel-route-usage-tracker)

[![Latest Version](https://camo.githubusercontent.com/09cd17e1c2b3be0066986fabdd0537333f574f383d2d5538e43da94d5052b76e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d322e302e322d2d626574612d6f72616e6765)](https://github.com/N-Mehroj/RouteUsageTracker)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![Laravel](https://camo.githubusercontent.com/63dbf63d6029d95a2ac536e9a771260a73e2066598641113544e8e2e3755f320/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d392532422d7265642e737667)](https://laravel.com)[![Vue.js](https://camo.githubusercontent.com/c54f793d61da0289fe7390a88b604999ecfe6de39dd4ac7fd14df3a8f1fe2779/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5675652e6a732d332d677265656e2e737667)](https://vuejs.org)[![Inertia.js](https://camo.githubusercontent.com/eeb6ea26cc6eee6304ce22396dd75ae7b1adbde090c5010c4986bd46850a380b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f496e65727469612e6a732d537570706f727465642d707572706c652e737667)](https://inertiajs.com)

A Laravel package for automatically tracking and analyzing route usage statistics with a beautiful Vue.js 3 dashboard and Inertia.js support.

> **🚨 Beta Release Notice**: Version 2.0.0-beta introduces major new features including Vue.js 3 dashboard and Inertia.js support. While stable for testing, please use with caution in production environments.

Description
-----------

[](#description)

This package allows you to track how routes are being used in your Laravel applications. It automatically records how many times each route has been accessed, when it was first and last used, and provides comprehensive statistics for performance analysis.

Features
--------

[](#features)

### 🎯 **Core Tracking Features**

[](#-core-tracking-features)

- ✅ **Zero Configuration** - Works immediately after installation
- 🚀 **Automatic Tracking** - Global middleware auto-registered
- 📊 **Rich Statistics** - Usage count, timestamps, route types and more
- 🎯 **Smart Filtering** - Configurable ignored routes and methods
- 💻 **Artisan Commands** - Powerful CLI for viewing statistics
- 🎨 **Facade Support** - Easy programmatic access

### 🎨 **Dashboard Features (Beta)**

[](#-dashboard-features-beta)

- 📱 **Vue.js 3 Dashboard** - Modern, reactive user interface
- ⚡ **Inertia.js Support** - Seamless SPA experience
- 🌙 **Dark/Light Theme** - Automatic theme switching
- 📈 **Interactive Charts** - Beautiful Chart.js visualizations
- 🔍 **Advanced Filtering** - Real-time search and filters
- 💾 **CSV Export** - Export usage data for analysis
- 📊 **Real-time Updates** - Live statistics and charts
- 🎛️ **One Command Setup** - Install everything with single command

4. **Build assets:**

```
npm run dev  # or npm run build
```

5. **Visit your dashboard (automatically available):**

```
http://your-app.com/route-usage-dashboard

```

> **📝 Note**: The dashboard route `/route-usage-dashboard` is automatically registered by the package. No need to manually add routes!

Quick Start Example
-------------------

[](#quick-start-example)

```
# 1. Install the package
composer require nmehroj/route-usage-tracker

# 2. That's it! Visit some pages in your app, then check stats:
php artisan route:usage
```

Usage
-----

[](#usage)

### Middleware Registration (Optional)

[](#middleware-registration-optional)

The package automatically registers a global middleware, but you can also manually control it by adding it to specific route groups in `app/Http/Kernel.php`:

```
// For global tracking (already done automatically)
protected $middleware = [
    // ...
    \NMehroj\RouteUsageTracker\Middleware\TrackRouteUsage::class,
];

// Or for specific route groups only
protected $middlewareGroups = [
    'web' => [
        // ...
        \NMehroj\RouteUsageTracker\Middleware\TrackRouteUsage::class,
    ],

    'api' => [
        // ...
        \NMehroj\RouteUsageTracker\Middleware\TrackRouteUsage::class,
    ],
];
```

### Automatic Route Tracking

[](#automatic-route-tracking)

All routes are automatically tracked out of the box. For each route request, the following information is stored:

- Route name
- URL path
- HTTP method (GET, POST, PUT, DELETE, etc.)
- Usage count
- First and last usage timestamps

### Viewing Statistics

[](#viewing-statistics)

#### Via Artisan Command

[](#via-artisan-command)

```
# View all route statistics
php artisan route:usage

# View top 10 most used routes
php artisan route:usage --top=10

# View statistics for a specific date range
php artisan route:usage --from="2023-01-01" --to="2023-12-31"

# Filter by HTTP method
php artisan route:usage --method=POST

# Filter by route type (web, api, admin, dashboard, auth, assets)
php artisan route:usage --type=api

# Combine all parameters
php artisan route:usage --top=5 --method=GET --type=web --from="2024-01-01"
```

#### Via Code

[](#via-code)

##### Using the Model Directly

[](#using-the-model-directly)

```
use NMehroj\RouteUsageTracker\Models\RouteUsage;

// Get all route statistics
$stats = RouteUsage::all();

// Get top 10 most used routes
$topRoutes = RouteUsage::orderBy('usage_count', 'desc')->take(10)->get();

// Get specific route information
$routeStats = RouteUsage::where('route_name', 'home')->first();
```

##### Using the Facade (Recommended)

[](#using-the-facade-recommended)

```
use NMehroj\RouteUsageTracker\Facades\RouteUsageTracker;

// Get all route statistics
$stats = RouteUsageTracker::all();

// Get top 10 most used routes
$topRoutes = RouteUsageTracker::orderBy('usage_count', 'desc')->take(10)->get();

// Get specific route information
$routeStats = RouteUsageTracker::where('route_name', 'home')->first();

// Use helper methods
$topRoutes = RouteUsageTracker::getTopRoutes(10);
$getStats = RouteUsageTracker::getRoutesByMethod('GET');
$apiRoutes = RouteUsageTracker::getRoutesByType('api');
$summary = RouteUsageTracker::getStatsSummary();
```

Dashboard with Inertia.js &amp; Vue.js
--------------------------------------

[](#dashboard-with-inertiajs--vuejs)

The package includes a modern, reactive Vue.js 3 dashboard built with Inertia.js for visualizing route usage statistics, similar to Laravel Nightwatch.

### Inertia.js Dashboard Installation

[](#inertiajs-dashboard-installation)

#### 🚀 One-Command Setup (Recommended)

[](#-one-command-setup-recommended)

```
php artisan route-usage-tracker:setup
```

This single command will:

- ✅ Run database migrations
- ✅ Install all required NPM packages (Vue.js 3, Inertia.js, Chart.js, Heroicons, VueUse)
- ✅ Publish dashboard assets
- ✅ Create example configuration files (vite.config.js, app.js)
- ✅ Display next steps

**Available Options:**

```
# Skip NPM package installation
php artisan route-usage-tracker:setup --skip-npm

# Skip database migrations
php artisan route-usage-tracker:setup --skip-migration

# Force reinstall packages
php artisan route-usage-tracker:setup --force

# Skip both NPM and migrations
php artisan route-usage-tracker:setup --skip-npm --skip-migration
```

#### Manual Installation (Alternative)

[](#manual-installation-alternative)

1. **Ensure Inertia.js is set up in your Laravel application:**

Follow the [Inertia.js Laravel installation guide](https://inertiajs.com/server-side-setup) if not already installed.

2. **Publish dashboard assets:**

```
php artisan route-usage-tracker:publish-dashboard
```

3. **Install required dependencies:**

```
npm install vue@^3.3.0 @inertiajs/vue3 chart.js @heroicons/vue @vueuse/core
```

4. **Update your `resources/js/app.js` for Inertia.js:**

```
import './bootstrap'
import '../css/app.css'

import { createApp, h } from 'vue'
import { createInertiaApp } from '@inertiajs/vue3'
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'

const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel'

createInertiaApp({
    title: (title) => `${title} - ${appName}`,
    resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
    setup({ el, App, props, plugin }) {
        return createApp({ render: () => h(App, props) })
            .use(plugin)
            .mount(el)
    },
    progress: {
        color: '#4F46E5',
    },
})
```

5. **Update your `vite.config.js`:**

```
import { defineConfig } from 'vite'
import laravel from 'laravel-vite-plugin'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/css/app.css',
                'resources/js/app.js',
            ],
            refresh: true,
        }),
        vue({
            template: {
                transformAssetUrls: {
                    base: null,
                    includeAbsolute: false,
                },
            },
        }),
    ],
    resolve: {
        alias: {
            '@': '/resources/js',
        },
    },
})
```

6. **Build assets:**

```
npm run build
# or for development
npm run dev
```

> **🎉 Automatic Route Registration**: The dashboard route `/route-usage-dashboard` is automatically registered by the package. No manual route configuration needed!

### Dashboard Features

[](#dashboard-features)

- 📊 **Real-time Statistics**: Live route usage metrics and charts
- 🎨 **Dark/Light Theme**: Automatic theme switching with system preference
- 📈 **Interactive Charts**: Beautiful Chart.js visualizations for usage trends
- 🔍 **Advanced Filtering**: Filter by route type, method, date range, and search
- 📱 **Responsive Design**: Works perfectly on desktop, tablet, and mobile
- 💾 **Export Functionality**: Export route data as CSV for further analysis
- ⚡ **Fast &amp; Lightweight**: Built with Vue.js 3 Composition API for optimal performance

### Dashboard Usage

[](#dashboard-usage)

1. **Visit the dashboard:**

```
http://your-app.com/route-usage-dashboard

```

2. **Available dashboard endpoints:**

- `/route-usage-tracker/dashboard` - Main dashboard view
- `/route-usage-tracker/api/summary` - Statistics summary
- `/route-usage-tracker/api/routes` - Routes with filtering
- `/route-usage-tracker/api/daily-usage` - Daily usage charts
- `/route-usage-tracker/api/type-stats` - Route type statistics
- `/route-usage-tracker/api/top-routes` - Most used routes
- `/route-usage-tracker/api/recent-activity` - Recent route activity
- `/route-usage-tracker/api/export` - Export data as CSV

3. **Dashboard API parameters:**

```
// Filter routes
fetch('/route-usage-tracker/api/routes?type=api&method=GET&search=user&limit=50')

// Get daily usage for last 7 days
fetch('/route-usage-tracker/api/daily-usage?days=7')

// Get top 5 routes by type
fetch('/route-usage-tracker/api/top-routes?limit=5&type=web')

// Export filtered data
fetch('/route-usage-tracker/api/export?type=api&from=2024-01-01&to=2024-12-31')
```

Database Structure
------------------

[](#database-structure)

The `route_usage` table has the following columns:

ColumnTypeDescriptionidbigintPrimary keyroute\_namevarchar(255)Route nameroute\_pathvarchar(500)URL pathmethodvarchar(10)HTTP methodroute\_typevarchar(50)Route type (web, api, admin, dashboard, auth, assets)usage\_countbigintUsage countfirst\_used\_attimestampFirst usage timestamplast\_used\_attimestampLast usage timestampcreated\_attimestampCreated timestampupdated\_attimestampUpdated timestampConfiguration
-------------

[](#configuration)

### Customizing Tracked Routes

[](#customizing-tracked-routes)

The package automatically ignores common development and debugging routes. To customize which routes are tracked:

Publish the config file first:

```
php artisan vendor:publish --provider="NMehroj\RouteUsageTracker\RouteUsageTrackerServiceProvider" --tag="route-usage-tracker-config"
```

Then edit `config/route-usage-tracker.php` to add ignored routes:

```
'ignored_routes' => [
    'telescope.*',
    'horizon.*',
    'debugbar.*',
    'admin.*',        // Ignore all admin routes
    'api/internal/*', // Ignore internal API routes
],
```

Practical Examples
------------------

[](#practical-examples)

### 1. Dashboard Analytics

[](#1-dashboard-analytics)

```
use NMehroj\RouteUsageTracker\Models\RouteUsage;

class DashboardController extends Controller
{
    public function index()
    {
        $popularRoutes = RouteUsage::orderBy('usage_count', 'desc')
            ->take(5)
            ->get();

        return view('dashboard', compact('popularRoutes'));
    }
}
```

### 2. Weekly Usage Report

[](#2-weekly-usage-report)

```
use NMehroj\RouteUsageTracker\Models\RouteUsage;

// Get current week's statistics
$weeklyStats = RouteUsage::whereBetween('last_used_at', [
    now()->startOfWeek(),
    now()->endOfWeek()
])->orderBy('usage_count', 'desc')->get();

// Generate report
foreach ($weeklyStats as $stat) {
    echo "{$stat->route_name} ({$stat->method}): {$stat->usage_count} hits\n";
}
```

### 3. API Usage Analytics

[](#3-api-usage-analytics)

```
use NMehroj\RouteUsageTracker\Models\RouteUsage;

// Track API endpoint usage
$apiRoutes = RouteUsage::where('route_path', 'like', 'api/%')
    ->orderBy('usage_count', 'desc')
    ->get();

// Find underused endpoints
$underused = RouteUsage::where('usage_count', '', now()->subMonth())
    ->get();
```

Advanced Configuration
----------------------

[](#advanced-configuration)

### Publishing Configuration

[](#publishing-configuration)

To customize the package behavior, publish the configuration file:

```
php artisan vendor:publish --provider="NMehroj\RouteUsageTracker\RouteUsageTrackerServiceProvider" --tag="route-usage-tracker-config"
```

Then edit `config/route-usage-tracker.php`:

```
return [
    // Enable or disable route tracking
    'enabled' => env('ROUTE_USAGE_TRACKER_ENABLED', true),

    // Routes that will not be tracked (supports wildcards)
    'ignored_routes' => [
        'telescope.*',
        'horizon.*',
        'debugbar.*',
        '_debugbar/*',
        'livewire.*',
    ],

    // HTTP methods that will not be tracked
    'ignored_methods' => ['HEAD', 'OPTIONS'],

    // Database settings
    'database_connection' => env('ROUTE_USAGE_TRACKER_DB_CONNECTION', null),
    'table_name' => env('ROUTE_USAGE_TRACKER_TABLE', 'route_usage'),

    // Auto cleanup old data
    'auto_cleanup' => [
        'enabled' => env('ROUTE_USAGE_TRACKER_AUTO_CLEANUP', false),
        'days' => env('ROUTE_USAGE_TRACKER_CLEANUP_DAYS', 365),
    ],
];
```

Environment Variables
---------------------

[](#environment-variables)

You can add these variables to your `.env` file:

```
# Control route tracking
ROUTE_USAGE_TRACKER_ENABLED=true

# Auto cleanup settings
ROUTE_USAGE_TRACKER_AUTO_CLEANUP=false
ROUTE_USAGE_TRACKER_CLEANUP_DAYS=365
```

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Laravel 10.0 or 11.0

Testing
-------

[](#testing)

To test the package:

```
# Install composer dependencies
composer install

# Run tests
composer test

# Or using PHPUnit directly
vendor/bin/phpunit

# Run tests with coverage
composer test-coverage
```

Performance Considerations
--------------------------

[](#performance-considerations)

- The package uses efficient database queries with proper indexing
- Middleware has minimal overhead (&lt; 1ms per request)
- Automatic cleanup can be configured to prevent database bloat
- Uses Laravel's built-in caching where possible

Troubleshooting
---------------

[](#troubleshooting)

### Routes Not Being Tracked

[](#routes-not-being-tracked)

1. Ensure the package is properly installed: `composer show nmehroj/route-usage-tracker`
2. Check if middleware is registered: `php artisan route:list --middleware`
3. Verify database migration ran: Check for `route_usage` table
4. Check configuration: `config('route-usage-tracker.enabled')`

### Performance Issues

[](#performance-issues)

1. Enable auto-cleanup to remove old data
2. Add database indexes if tracking high-volume routes
3. Consider excluding non-essential routes via configuration

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

[](#contributing)

We welcome contributions! To contribute:

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

Support
-------

[](#support)

- 📖 **Documentation**: This README
- 🐛 **Bug Reports**: [GitHub Issues](https://github.com/N-Mehroj/RouteUsageTracker/issues)
- 💡 **Feature Requests**: [GitHub Issues](https://github.com/N-Mehroj/RouteUsageTracker/issues)
- ❓ **Questions**: [GitHub Discussions](https://github.com/N-Mehroj/RouteUsageTracker/discussions)

Author
------

[](#author)

**Nmehroj** - [GitHub](https://github.com/N-Mehroj)

---

Made with ❤️ for the Laravel community

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance74

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

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 ~0 days

Total

6

Last Release

178d ago

Major Versions

v1.0.2 → 2.0.0-beta2025-11-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/1cf1ef9f5ec5a46f2a227961980c45128c8bd60fc2ffffcd104a5c83a068f5d0?d=identicon)[N-Mehroj](/maintainers/N-Mehroj)

---

Top Contributors

[![N-Mehroj](https://avatars.githubusercontent.com/u/72346597?v=4)](https://github.com/N-Mehroj "N-Mehroj (17 commits)")

---

Tags

middlewarelaravelmonitoringtrackinganalyticsroutestatisticsusage

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nmehroj-route-usage-tracker/health.svg)

```
[![Health](https://phpackages.com/badges/nmehroj-route-usage-tracker/health.svg)](https://phpackages.com/packages/nmehroj-route-usage-tracker)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M529](/packages/laravel-passport)[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[yadahan/laravel-authentication-log

Laravel Authentication Log provides authentication logger and notification for Laravel.

416632.8k5](/packages/yadahan-laravel-authentication-log)[inspector-apm/inspector-laravel

Code Execution Monitoring, built for developers.

2332.0M2](/packages/inspector-apm-inspector-laravel)

PHPackages © 2026

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