PHPackages                             justawebdev/laravel-simple-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. justawebdev/laravel-simple-analytics

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

justawebdev/laravel-simple-analytics
====================================

Lightweight server-side analytics for Laravel

v0.1.0(1mo ago)08PHP

Since Apr 25Pushed 1mo agoCompare

[ Source](https://github.com/JustAWebDev/laravel-simple-analytics)[ Packagist](https://packagist.org/packages/justawebdev/laravel-simple-analytics)[ RSS](/packages/justawebdev-laravel-simple-analytics/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Laravel Simple Analytics
========================

[](#laravel-simple-analytics)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a4822db02ee00475e7397c02d5c521e7838bdd8acce6d1a96a2fa8fb2c523352/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a757374617765626465762f6c61726176656c2d73696d706c652d616e616c79746963732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/justawebdev/laravel-simple-analytics)[![Total Downloads](https://camo.githubusercontent.com/0b6a72bd5e3db90b82ded38dc69a9bf9aa757dba4783ca081e1a1b76d299bbcd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a757374617765626465762f6c61726176656c2d73696d706c652d616e616c79746963732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/justawebdev/laravel-simple-analytics)[![Laravel Version](https://camo.githubusercontent.com/213a2486e1a6704fb19248da12c759d1f3fb584847fb09c0a243a8c91977d21a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d31302532422d7265642e7376673f7374796c653d666c61742d737175617265)](https://laravel.com)[![License](https://camo.githubusercontent.com/c4ae13af3a898e59b1530ccfdb1bfc4bd501dad5d5e1c6ff450bf458f357f1a8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a757374617765626465762f6c61726176656c2d73696d706c652d616e616c79746963732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/justawebdev/laravel-simple-analytics)

A lightweight, server-side analytics package for Laravel applications. Track page views, custom events, and generate simple reports without relying on third-party services.

✨ Features
----------

[](#-features)

- 🚀 **Zero Dependencies** - Pure Laravel implementation
- 📊 **Page View Tracking** - Automatic middleware-based tracking
- 🎯 **Custom Events** - Track any event with metadata
- 🛡️ **Route Filtering** - Ignore specific routes (like admin panels)
- 📈 **Simple Reports** - Built-in console command for top pages
- 🎨 **Facade &amp; Helpers** - Easy-to-use API
- ⚡ **Performance Focused** - Minimal overhead

📦 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require justawebdev/laravel-simple-analytics
```

Publish the configuration file:

```
php artisan vendor:publish --provider="JustAWebDev\Analytics\AnalyticsServiceProvider"
```

Run the migration to create the analytics table:

```
php artisan migrate
```

⚙️ Configuration
----------------

[](#️-configuration)

After publishing, you'll find the config file at `config/analytics.php`. Here's what you can configure:

```
return [
    'enabled' => true,  // Enable/disable analytics globally

    'ignore_routes' => [
        'telescope/*',  // Ignore Laravel Telescope routes
        'horizon/*',    // Ignore Laravel Horizon routes
        // Add any routes you want to ignore
    ],
];
```

🚀 Usage
-------

[](#-usage)

### Automatic Page View Tracking

[](#automatic-page-view-tracking)

Add the middleware to your `app/Http/Kernel.php` or route group:

```
// In routes/web.php or api.php
Route::middleware(['analytics'])->group(function () {
    // Your routes here
});

// Or globally in Kernel.php
protected $middlewareGroups = [
    'web' => [
        // ... other middleware
        \JustAWebDev\Analytics\Middleware\TrackPageView::class,
    ],
];
```

### Manual Event Tracking

[](#manual-event-tracking)

Use the facade to track custom events:

```
use JustAWebDev\Analytics\Facades\Analytics;

// Track a simple event
Analytics::track('user_login');

// Track with metadata
Analytics::track('purchase', [
    'product_id' => 123,
    'amount' => 99.99,
    'currency' => 'USD'
]);
```

### Using the Helper Function

[](#using-the-helper-function)

```
// Global helper function
analytics()->track('button_click', ['button' => 'hero_cta']);
```

### Getting Analytics Data

[](#getting-analytics-data)

```
// Count total page views
$totalViews = analytics()->count('pageview');

// Count views for a specific page
$pageViews = analytics()->count('pageview', '/home');

// Get top 5 pages
$topPages = analytics()->topPages(5);

// Returns collection with 'name' and 'total' columns
foreach ($topPages as $page) {
    echo "{$page->name}: {$page->total} views\n";
}
```

### Console Reports

[](#console-reports)

Generate a quick report from the command line:

```
php artisan analytics:report
```

Output:

```
Top Pages:
/home (150)
/about (89)
/contact (45)

```

🔧 Advanced Usage
----------------

[](#-advanced-usage)

### Custom Middleware Implementation

[](#custom-middleware-implementation)

If you need more control, you can create your own middleware:

```
