PHPackages                             yenhunter/laravel-website-analytics - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. yenhunter/laravel-website-analytics

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

yenhunter/laravel-website-analytics
===================================

A lightweight visitor tracking package for Laravel.

v1.1.0(4mo ago)00MITPHPPHP ^8.1

Since Jan 4Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/yenHunter/laravel-website-analytics)[ Packagist](https://packagist.org/packages/yenhunter/laravel-website-analytics)[ RSS](/packages/yenhunter-laravel-website-analytics/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

Laravel Website Analytics
=========================

[](#laravel-website-analytics)

A lightweight, efficient visitor tracking package for Laravel applications. It tracks unique visitors, page views, and user locations (GeoIP) without bloating your database. It includes a dedicated database for Country Coordinates, allowing for instant generation of Vector Maps without hardcoding logic in JavaScript.

🚀 Features
----------

[](#-features)

- **Efficient Tracking:** Groups visits by IP and Date (prevents spamming DB on every page reload).
- **GeoIP Integration:** Automatically detects Country based on IP (via `stevebauman/location`).
- **Bot Protection:** Ignores common bots and crawlers (configurable).
- **Database-Backed Mapping:** Includes a pre-filled database of Country Coordinates (Lat/Long) for mapping.
- **Dashboard Ready:** Helper methods to get formatted data for ApexCharts and Vector Maps instantly.

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

[](#installation)

You can install the package via composer:

```
composer require yenhunter/laravel-website-analytics
```

### 1. Run Migrations

[](#1-run-migrations)

Publish and run the migrations to create the `website_analytics` and `analytics_countries` tables:

```
php artisan migrate
```

### 2. Configure GeoIP

[](#2-configure-geoip)

This package relies on `stevebauman/location` for country detection. Publish the config:

```
php artisan vendor:publish --provider="Stevebauman\Location\LocationServiceProvider"
```

### 3. Seed Country Coordinates (Important)

[](#3-seed-country-coordinates-important)

To populate the map with Latitude/Longitude data for countries, run the included seeder command:

```
php artisan analytics:seed-countries
```

*This populates the `analytics_countries` table so your vector map works immediately.*

---

Usage
-----

[](#usage)

### 1. Enable Tracking

[](#1-enable-tracking)

Register the Middleware in your `bootstrap/app.php` file (Laravel 11) or `Http/Kernel.php` (Laravel 10).

**bootstrap/app.php:**

```
use Yenhunter\LaravelWebsiteAnalytics\Http\Middleware\TrackVisitor;

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

By default, the middleware tracks routes named `visitor.*`.

### 2. Retrieving Data for Dashboard

[](#2-retrieving-data-for-dashboard)

Inject the `Analytics` class into any Controller.

```
namespace App\Http\Controllers;

use Yenhunter\LaravelWebsiteAnalytics\Analytics;

class DashboardController extends Controller
{
    public function index(Analytics $analytics)
    {
        // Get line chart data (Last 7 days)
        $chartData = $analytics->getChartData(7);

        // Get map data (Returns Country Name, Coords, and Visit Count)
        // Format: [{ name: 'USA', coords: [37.09, -95.71], visits: 500 }, ...]
        $mapData = $analytics->getMapData();

        return view('admin.dashboard', compact('chartData', 'mapData'));
    }
}
```

---

Frontend Examples
-----------------

[](#frontend-examples)

### 1. Line Chart (ApexCharts)

[](#1-line-chart-apexcharts)

The `getChartData()` method returns arrays perfectly formatted for ApexCharts.

```

    var options = {
        chart: { type: 'line', height: 350 },
        series: [{
            name: 'Total Views',
            data: @json($chartData['total'])
        }, {
            name: 'Unique Visitors',
            data: @json($chartData['unique'])
        }],
        xaxis: {
            categories: @json($chartData['dates'])
        }
    };
    var chart = new ApexCharts(document.querySelector("#traffic-chart"), options);
    chart.render();

```

### 2. World Map (jsVectorMap)

[](#2-world-map-jsvectormap)

The `getMapData()` method returns an array of objects with coordinates, so you **do not** need to hardcode Lat/Long in JavaScript.

```

    document.addEventListener('DOMContentLoaded', function () {
        // 1. Get Data directly from Laravel
        var dbData = @json($mapData);

        new jsVectorMap({
            selector: '#world-map-markers',
            map: 'world',
            markersSelectable: true,

            // 2. Pass data directly to markers
            markers: dbData, // [{name: 'BD', coords: [23.68, 90.35], visits: 100}]

            labels: {
                markers: {
                    render: marker => `${marker.name}: ${marker.visits}`
                }
            },
            onMarkerTooltipShow(event, tooltip, index) {
                tooltip.text(`${dbData[index].name}Visits: ${dbData[index].visits}`);
            }
        });
    });

```

---

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

[](#database-structure)

### Table: `website_analytics`

[](#table-website_analytics)

Tracks individual daily visits per IP.

ColumnTypeDescription`id`BigIntPrimary Key`ip_address`StringVisitor IP`visit_date`DateThe date of the visit`visits`IntegerCount of hits per day`country_code`StringISO Code (e.g., US, BD)`user_agent`StringBrowser/Device Info### Table: `analytics_countries`

[](#table-analytics_countries)

Stores static coordinate data for mapping. Populated via `analytics:seed-countries`.

ColumnTypeDescription`id`BigIntPrimary Key`country_code`StringUnique ISO Code (e.g., US)`name`StringCountry Name (e.g., United States)`lat`DecimalLatitude`long`DecimalLongitudeLicense
-------

[](#license)

The MIT License (MIT). Please see License File for more information.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance77

Regular maintenance activity

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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

Total

2

Last Release

125d ago

### Community

Maintainers

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

---

Top Contributors

[![yenHunter](https://avatars.githubusercontent.com/u/54746332?v=4)](https://github.com/yenHunter "yenHunter (15 commits)")

---

Tags

analyticsapex-chartslaravelvector-mapwebsite-analytics

### Embed Badge

![Health badge](/badges/yenhunter-laravel-website-analytics/health.svg)

```
[![Health](https://phpackages.com/badges/yenhunter-laravel-website-analytics/health.svg)](https://phpackages.com/packages/yenhunter-laravel-website-analytics)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)[illuminate/cookie

The Illuminate Cookie package.

224.3M122](/packages/illuminate-cookie)

PHPackages © 2026

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