PHPackages                             wappomic/laravel-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. [API Development](/categories/api)
4. /
5. wappomic/laravel-analytics

ActiveLibrary[API Development](/categories/api)

wappomic/laravel-analytics
==========================

Cookie-free GDPR-compliant analytics package for Laravel - API-based without database

v1.0.4(9mo ago)035MITPHPPHP ^8.2

Since Aug 4Pushed 9mo agoCompare

[ Source](https://github.com/wappomic/laravel-Analytics)[ Packagist](https://packagist.org/packages/wappomic/laravel-analytics)[ RSS](/packages/wappomic-laravel-analytics/feed)WikiDiscussions main Synced 2mo ago

READMEChangelogDependencies (6)Versions (10)Used By (0)

Wappomic Laravel Analytics v1
=============================

[](#wappomic-laravel-analytics-v1)

[![en](https://camo.githubusercontent.com/70e2e7022867c491c94661f3b935db7e2c3d679e1b0386c4b98f799386bb18ca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c616e672d656e2d626c75652e737667)](README.md)[![de](https://camo.githubusercontent.com/9a68a3888dc631d5984b0bde6e56238bcac622afcb524d71b2c7c56d4a1ef424/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c616e672d64652d677265656e2e737667)](README.de.md)

**Cookie-free, GDPR-compliant analytics package for Laravel**

Collects anonymized website data and sends it to your own API. No cookies, no banner - just install and go.

🎯 Features
----------

[](#-features)

- 🍪 **Cookie-free** - No consent required
- 🔒 **GDPR-compliant** - Immediate anonymization of all data
- 🌐 **API-based** - Sends data to your own analytics API
- ⚡ **Performance** - &lt; 2ms overhead, asynchronous processing
- 🎛️ **Multi-App Support** - One dashboard for multiple apps/websites
- 🔧 **Plug &amp; Play** - Automatic tracking after installation
- 🔄 **Session Tracking** - Cookie-free unique visitor identification

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

[](#-installation)

```
composer require wappomic/laravel-analytics
php artisan vendor:publish --tag=analytics-config
```

### .env Configuration

[](#env-configuration)

```
# REQUIRED
ANALYTICS_API_URL=https://your-dashboard.com/api/analytics
ANALYTICS_API_KEY=your-unique-app-key-12345

# OPTIONAL
ANALYTICS_APP_NAME="My Laravel Shop"
ANALYTICS_ENABLED=true
ANALYTICS_QUEUE_ENABLED=true
ANALYTICS_QUEUE_CONNECTION=redis
ANALYTICS_QUEUE_NAME=analytics
ANALYTICS_SESSION_TRACKING_ENABLED=true
ANALYTICS_SESSION_TTL_HOURS=24
ANALYTICS_VERBOSE_LOGGING=0  # Use 1 for true, 0 for false
```

That's it! 🎉 The package now automatically tracks all web requests.

📝 Changelog
-----------

[](#-changelog)

All notable changes to this project are documented in the [CHANGELOG.md](CHANGELOG.md).

### 🆕 Current Version: v1.0.4

[](#-current-version-v104)

- 🛡️ **Production Hardening:** Request deduplication prevents 3x tracking issues
- 📊 **Enhanced Diagnostics:** Detailed API error logging with HTTP response details
- 🔧 **Smart Filtering:** Load balancer health check detection and internal request filtering
- 📝 **Flexible Logging:** Optional verbose logging with `ANALYTICS_VERBOSE_LOGGING` config

[→ View Full Changelog](CHANGELOG.md)

🚫 Excluded Routes Configuration
-------------------------------

[](#-excluded-routes-configuration)

By default, certain routes are automatically excluded from tracking (admin pages, APIs, static files, etc.). You can customize this list or disable exclusions entirely.

### Default Excluded Routes

[](#default-excluded-routes)

```
// config/analytics.php
'excluded_routes' => [
    '/admin*',
    '/api*',
    '/broadcasting*',  // 🎯 Solves Laravel Broadcasting auth issues
    '/health*',
    '/robots.txt',
    '/sitemap.xml',
    '*.json',
    '*.xml',
    '*.css',
    '*.js',
    '*.ico',
    '*.png',
    '*.jpg',
    '*.jpeg',
    '*.gif',
    '*.svg',
    '*.woff*',
    '*.ttf',
],
```

### Customization Examples

[](#customization-examples)

```
// Track everything (no exclusions)
'excluded_routes' => [],

// Only exclude specific routes
'excluded_routes' => ['/admin*', '/broadcasting*'],

// Add your custom routes to defaults
'excluded_routes' => [
    '/admin*',
    '/api*',
    '/broadcasting*',
    '/health*',
    '/robots.txt',
    '/sitemap.xml',
    '*.json',
    '*.xml',
    '*.css',
    '*.js',
    '*.ico',
    '*.png',
    '*.jpg',
    '*.jpeg',
    '*.gif',
    '*.svg',
    '*.woff*',
    '*.ttf',
    '/my-private-section*',  // Your custom exclusions
    '/internal-api/*',
    '*.pdf',
],
```

### Wildcard Patterns

[](#wildcard-patterns)

The excluded routes support wildcard patterns using `fnmatch()`:

PatternMatchesExamples`/admin*`Routes starting with `/admin``/admin`, `/admin/users`, `/admin/dashboard/settings``*.json`Routes ending with `.json``/data.json`, `/api/users.json``/api/*`Routes under `/api/``/api/users`, `/api/v1/posts``*broadcasting*`Routes containing `broadcasting``/broadcasting/auth`, `/laravel/broadcasting/auth`### Common Use Cases

[](#common-use-cases)

**Laravel Broadcasting (WebSocket Auth)**:

```
'excluded_routes' => ['/broadcasting*'],
// Prevents tracking of '/broadcasting/auth' routes
```

**SPA Applications**:

```
'excluded_routes' => ['/api*', '*.json'],
// Only track page views, not API calls
```

**Track Everything**:

```
'excluded_routes' => [],
// No automatic exclusions - track all routes
```

### Combined with Route Middleware

[](#combined-with-route-middleware)

You have two options to exclude routes:

```
// Option 1: Global config (recommended)
'excluded_routes' => ['/admin*', '/broadcasting*'],

// Option 2: Per-route basis
Route::get('/admin', AdminController::class)->withoutMiddleware('analytics.tracking');
```

📊 Data Format
-------------

[](#-data-format)

Your API receives POST requests with this JSON payload:

```
{
  "api_key": "your-unique-app-key-12345",
  "app_name": "My Laravel Shop",
  "timestamp": "2025-08-04T14:00:00Z",
  "url": "/products/laptop",
  "referrer": "https://google.com",
  "anonymized_ip": "192.168.1.0",
  "browser": "Chrome",
  "device": "desktop",
  "country": "DE",
  "session_hash": "abc123def456789abcdef123456789abc",
  "is_new_session": true,
  "pageview_count": 1,
  "session_duration": 0,
  "custom_data": null
}
```

### 🔑 Multi-App Setup (Recommended)

[](#-multi-app-setup-recommended)

**One dashboard for all your apps:**

```
# App 1: Online Shop
ANALYTICS_API_KEY=shop-key-abc123
ANALYTICS_APP_NAME="Online Shop"

# App 2: Blog
ANALYTICS_API_KEY=blog-key-def456
ANALYTICS_APP_NAME="Tech Blog"

# App 3: Landing Page
ANALYTICS_API_KEY=landing-key-ghi789
ANALYTICS_APP_NAME="Product Landing"
```

All apps send to the same `ANALYTICS_API_URL` but with different `api_key` - perfect data separation.

🛠️ Analytics Dashboard Implementation
-------------------------------------

[](#️-analytics-dashboard-implementation)

### 1. Create API Endpoint

[](#1-create-api-endpoint)

```
// routes/api.php
Route::post('/analytics', [AnalyticsController::class, 'store']);
```

```
// app/Http/Controllers/AnalyticsController.php
