PHPackages                             drsoft28/visitor-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. [Framework](/categories/framework)
4. /
5. drsoft28/visitor-tracker

ActiveLibrary[Framework](/categories/framework)

drsoft28/visitor-tracker
========================

v2.2.4(1y ago)023[1 issues](https://github.com/drsoft28/laravel-visitor-tracker/issues)MITPHP

Since Apr 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/drsoft28/laravel-visitor-tracker)[ Packagist](https://packagist.org/packages/drsoft28/visitor-tracker)[ RSS](/packages/drsoft28-visitor-tracker/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (16)Used By (0)

Laravel Visitor Tracker - Full User Guide
=========================================

[](#laravel-visitor-tracker---full-user-guide)

The **Laravel Visitor Tracker** package allows you to track guest and user activity on your web application. It provides detailed information about visitors, including their IP address, location, visited URLs, and more. This guide will walk you through the installation, configuration, and usage of the package.

---

Table of Contents
-----------------

[](#table-of-contents)

1. [Installation](#installation)
2. [Configuration](#configuration)
3. [Middleware Setup](#middleware-setup)
4. [Usage](#usage)
5. [Database Structure](#database-structure)
6. [Model Methods](#model-methods)
7. [Customization](#customization)
8. [Troubleshooting](#troubleshooting)

---

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

[](#installation)

1. Install the package via Composer:

    ```
    composer require drsoft28/visitortracker
    ```
2. Publish the configuration file and migrations:

    ```
    php artisan vendor:publish --provider="Drsoft28\VisitorTracker\VisitorTrackerServiceProvider"
    ```

    Or

    ```
    php artisan vendor:publish --tag=visitor-tracker-migrations --tag=visitor-tracker-config --tag=visitor-tracker-model
    ```

    This will create:

    - A `visitortracker.php` file in the `config/` directory.
    - A migration file for the `visitor_trackers` table in the `database/migrations/` directory.
3. Run the migration to create the `visitor_trackers` table:

    ```
    php artisan migrate
    ```

---

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

[](#configuration)

After publishing the configuration file, you can customize the package behavior by editing the `config/visitortracker.php` file. Here are the default options:

```
return [
    /*
    |--------------------------------------------------------------------------
    | Model
    |--------------------------------------------------------------------------
    |
    | This value is the model used for tracking visitors.
    | By default, it uses the package's built-in model.
    | You can replace it with your own model if needed.
    */
    'model' => \Drsoft28\VisitorTracker\Models\VisitorTracker::class,

    /*
    |--------------------------------------------------------------------------
    | Headers to Track
    |--------------------------------------------------------------------------
    |
    | Specify the headers to store in the `request_info` JSON column.
    | Add or remove headers as needed.
    */
    'headers' => [
        'HTTP_USER_AGENT',
        'HTTP_HOST',
        'SERVER_NAME',
        'SERVER_SOFTWARE',
        'REMOTE_ADDR',
        'HTTPS',
    ],
];
```

---

Middleware Setup
----------------

[](#middleware-setup)

To start tracking visitors, you need to add the `VisitorTrackerMiddleware` to your application's middleware stack.

### For Laravel 10 and Below:

[](#for-laravel-10-and-below)

Add the middleware to the `web` group in `app/Http/Kernel.php`:

```
'web' => [
    \App\Http\Middleware\EncryptCookies::class,
    \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
    \Illuminate\Session\Middleware\StartSession::class,
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    \App\Http\Middleware\VerifyCsrfToken::class,
    \Illuminate\Routing\Middleware\SubstituteBindings::class,
    \Drsoft28\VisitorTracker\Middleware\VisitorTrackerMiddleware::class,
],
```

### For Laravel 11 and Above:

[](#for-laravel-11-and-above)

Add the middleware in `bootstrap/app.php`:

```
->withMiddleware(function (Middleware $middleware) {
    $middleware->web(append: [
        \Drsoft28\VisitorTracker\Middleware\VisitorTrackerMiddleware::class,
    ]);
})
```

---

Usage
-----

[](#usage)

Once the middleware is enabled, the package will automatically track visitors and store their information in the `visitor_trackers` table.

### Default Model

[](#default-model)

By default, the package uses the `\Drsoft28\VisitorTracker\Models\VisitorTracker` model. You can change this in the `visitortracker.php` configuration file.

### Database Columns

[](#database-columns)

The `visitor_trackers` table contains the following columns:

- `user_id`: The ID of the authenticated user (if applicable).
- `host_schema`: The protocol (e.g., `http` or `https`).
- `host`: The hostname (e.g., `example.com`).
- `ip`: The visitor's IP address.
- `path`: The visited path (e.g., `/about`).
- `full_url`: The full URL visited.
- `url`: The relative URL.
- `country_name`: The visitor's country name.
- `country_code`: The visitor's country code.
- `region_name`: The visitor's region name.
- `region_code`: The visitor's region code.
- `city_name`: The visitor's city name.
- `zip_code`: The visitor's ZIP code.
- `iso_code`: The ISO code of the visitor's location.
- `latitude`: The visitor's latitude.
- `longitude`: The visitor's longitude.
- `timezone`: The visitor's timezone.
- `referer`: The referer URL.
- `route_name`: The name of the route visited.
- `route_params`: The parameters of the route.
- `request_info`: A JSON column containing additional request information (e.g., headers).

---

Model Methods
-------------

[](#model-methods)

The `VisitorTracker` model provides the following methods for querying visitor data:

1. **`visitorsWithinSeconds($seconds)`**:

    - Retrieve visitors who visited within the last `$seconds` seconds.
2. **`visitorsWithinMinutes($minutes)`**:

    - Retrieve visitors who visited within the last `$minutes` minutes.
3. **`visitorsWithinHours($hours)`**:

    - Retrieve visitors who visited within the last `$hours` hours.

Example Usage:

```
use Drsoft28\VisitorTracker\Models\VisitorTracker;

// Get visitors from the last 5 minutes
$recentVisitors = VisitorTracker::visitorsWithinMinutes(5)->get();
```

---

Customization
-------------

[](#customization)

### Custom Model

[](#custom-model)

If you want to use a custom model for tracking visitors, follow these steps:

1. Create a new model in your `app/Models` directory:

    ```
    namespace App\Models;

    use Illuminate\Database\Eloquent\Model;

    class CustomVisitorTracker extends Model
    {
        protected $table = 'visitor_trackers';
        protected $fillable = [
            'user_id', 'host_schema', 'host', 'ip', 'path', 'full_url', 'url',
            'country_name', 'country_code', 'region_name', 'region_code', 'city_name',
            'zip_code', 'iso_code', 'latitude', 'longitude', 'timezone', 'referer',
            'route_name', 'route_params', 'request_info',
        ];
    }
    ```
2. Update the `visitortracker.php` configuration file to use your custom model:

    ```
    'model' => \App\Models\CustomVisitorTracker::class,
    ```

### Custom Headers

[](#custom-headers)

You can customize the headers tracked in the `request_info` column by updating the `headers` array in the `visitortracker.php` configuration file.

---

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

[](#troubleshooting)

1. **Middleware Not Tracking Visitors**:

    - Ensure the middleware is added to the correct group (`web` or `global`).
    - Verify that the middleware is not being skipped by other middleware.
2. **Migration Errors**:

    - Ensure the `visitor_trackers` table does not already exist before running the migration.
    - Check for any typos in the migration file.
3. **Configuration Not Applied**:

    - Clear the configuration cache after updating the `visitortracker.php` file: ```
        php artisan config:clear
        ```

---

Support
-------

[](#support)

If you encounter any issues or have questions, please open an issue on the [GitHub repository](https://github.com/drsoft28/laravel-visitor-tracker).

---

Thank you for using **Laravel Visitor Tracker**! 🚀

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance45

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

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

Recently: every ~1 days

Total

15

Last Release

428d ago

Major Versions

V1.2 → V2.02025-03-09

### Community

Maintainers

![](https://www.gravatar.com/avatar/b3b320ca3b9d89ad96eeb5595814dbf547e3316f7779113c959a311f69fd3694?d=identicon)[drsoft](/maintainers/drsoft)

---

Top Contributors

[![drsoft28](https://avatars.githubusercontent.com/u/11458383?v=4)](https://github.com/drsoft28 "drsoft28 (34 commits)")

---

Tags

frameworklaravelvisitor tracker

### Embed Badge

![Health badge](/badges/drsoft28-visitor-tracker/health.svg)

```
[![Health](https://phpackages.com/badges/drsoft28-visitor-tracker/health.svg)](https://phpackages.com/packages/drsoft28-visitor-tracker)
```

###  Alternatives

[hemp/presenter

Easy Model Presenters in Laravel

247592.6k1](/packages/hemp-presenter)[marketplacekit/marketplacekit

Open source Marketplace Platform

8185.2k](/packages/marketplacekit-marketplacekit)[yorcreative/laravel-urlshortener

A laravel url shortener package that provides internal url redirects with passwords, url expirations, open limits before expiration and click tracking out of the box.

12011.0k](/packages/yorcreative-laravel-urlshortener)[rahulalam31/laravel-abuse-ip

Block ip address of all spammer's around the world.

27431.5k](/packages/rahulalam31-laravel-abuse-ip)[erik/laralum

The Laravel Framework with Laralum administration panel.

911.1k](/packages/erik-laralum)

PHPackages © 2026

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