PHPackages                             artisanpack-ui/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. [Admin Panels](/categories/admin)
4. /
5. artisanpack-ui/analytics

ActiveLibrary[Admin Panels](/categories/admin)

artisanpack-ui/analytics
========================

Privacy-first analytics package for Laravel with local database storage, external provider support (GA4, Plausible), and a beautiful Livewire dashboard.

1.2.0(1mo ago)04[16 issues](https://github.com/ArtisanPack-UI/analytics/issues)MITPHPPHP ^8.2CI passing

Since Jan 12Pushed 3w agoCompare

[ Source](https://github.com/ArtisanPack-UI/analytics)[ Packagist](https://packagist.org/packages/artisanpack-ui/analytics)[ RSS](/packages/artisanpack-ui-analytics/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (39)Versions (10)Used By (0)

ArtisanPack UI Analytics
========================

[](#artisanpack-ui-analytics)

ArtisanPack UI Analytics is a privacy-first analytics package for Laravel applications. Built on Livewire 3, it provides local database storage for complete data ownership, GDPR-compliant consent management, real-time dashboards, multi-tenant support, and optional integration with Google Analytics 4 and Plausible.

Quick Start
-----------

[](#quick-start)

### Installation

[](#installation)

```
# Install the package
composer require artisanpack-ui/analytics

# Run the installer (migrations, config, assets)
php artisan analytics:install

# Or manually publish and migrate
php artisan vendor:publish --provider="ArtisanPackUI\Analytics\AnalyticsServiceProvider"
php artisan migrate
```

### Basic Usage

[](#basic-usage)

```

@analyticsScripts

@analyticsConsentBanner

```

```
// Track page views programmatically
trackPageView('/products', 'Products Page');

// Track custom events
trackEvent('button_click', ['button_id' => 'signup']);

// Get visitor statistics
$stats = analyticsStats(DateRange::last30Days());
```

Key Features
------------

[](#key-features)

- **Privacy First**: Local database storage for complete data ownership
- **GDPR Compliant**: Built-in consent management with Do Not Track support
- **Real-Time Dashboard**: Beautiful Livewire dashboard with live visitor counts
- **Session Tracking**: Track visitors, sessions, page views, and bounce rates
- **Event Tracking**: Custom event tracking with categories and values
- **Goal Tracking**: Set up conversion goals with progress tracking
- **Multi-Tenant Support**: Domain, subdomain, API key, and header-based resolution
- **External Providers**: Optional integration with Google Analytics 4 and Plausible
- **Queue Processing**: High-performance async tracking for busy sites
- **Data Retention**: Configurable retention with automatic cleanup and aggregation
- **IP Anonymization**: GDPR-compliant IP address handling
- **Bot Filtering**: Automatic exclusion of known bots and crawlers

Components
----------

[](#components)

### Livewire Components

[](#livewire-components)

ComponentDescription`AnalyticsDashboard`Full-featured analytics dashboard with all widgets`StatsCards`Summary statistics (page views, visitors, sessions, bounce rate)`VisitorsChart`Interactive line chart of visitors over time`TopPages`Most visited pages table with view counts`TrafficSources`Referrer breakdown with percentage charts`RealtimeVisitors`Live count of active visitors`GoalProgress`Goal completion tracking with progress bars`ConsentBanner`GDPR consent collection banner### Widget Usage

[](#widget-usage)

```

```

Documentation
-------------

[](#documentation)

Comprehensive documentation is available at our [Documentation Site](https://github.com/ArtisanPack-UI/analytics/wiki):

- **[Getting Started](https://github.com/ArtisanPack-UI/analytics/wiki/Getting-Started)** - Quick start guide
- **[Installation Guide](https://github.com/ArtisanPack-UI/analytics/wiki/Installation)** - Detailed setup instructions
- **[Configuration](https://github.com/ArtisanPack-UI/analytics/wiki/Installation-Configuration)** - All configuration options
- **[Tracking Page Views](https://github.com/ArtisanPack-UI/analytics/wiki/Usage-Tracking-Page-Views)** - Page view tracking
- **[Tracking Events](https://github.com/ArtisanPack-UI/analytics/wiki/Usage-Tracking-Events)** - Custom event tracking
- **[Components](https://github.com/ArtisanPack-UI/analytics/wiki/Components)** - Dashboard and widget components
- **[Multi-Tenancy](https://github.com/ArtisanPack-UI/analytics/wiki/Advanced-Multi-Tenancy)** - Multi-tenant setup
- **[Privacy &amp; Consent](https://github.com/ArtisanPack-UI/analytics/wiki/Advanced-Privacy-Consent)** - GDPR compliance
- **[API Reference](https://github.com/ArtisanPack-UI/analytics/wiki/Api)** - Models, services, and events

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

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=analytics-config
```

### Environment Variables

[](#environment-variables)

The package supports the following environment variables:

VariableDescriptionDefault`ANALYTICS_ENABLED`Enable/disable all tracking`true``ANALYTICS_ACTIVE_PROVIDERS`Comma-separated list of providers`local``ANALYTICS_DB_CONNECTION`Database connection for analytics`null` (default)`ANALYTICS_TABLE_PREFIX`Prefix for analytics tables`analytics_``ANALYTICS_ANONYMIZE_IP`Anonymize visitor IP addresses`true``ANALYTICS_QUEUE_PROCESSING`Process tracking via queues`true``ANALYTICS_QUEUE_NAME`Queue name for async processing`analytics``ANALYTICS_RETENTION_PERIOD`Days to retain data (null = forever)`90``ANALYTICS_DASHBOARD_PREFIX`URL prefix for dashboard routes`analytics``ANALYTICS_CACHE_DURATION`Dashboard cache duration in seconds`300``ANALYTICS_MULTI_TENANT`Enable multi-tenant mode`false``ANALYTICS_CONSENT_REQUIRED`Require consent before tracking`false``ANALYTICS_RESPECT_DNT`Honor Do Not Track headers`true``ANALYTICS_GOOGLE_ENABLED`Enable Google Analytics 4`false``ANALYTICS_GOOGLE_MEASUREMENT_ID`GA4 Measurement ID`null``ANALYTICS_GOOGLE_API_SECRET`GA4 API Secret`null``ANALYTICS_PLAUSIBLE_ENABLED`Enable Plausible Analytics`false``ANALYTICS_PLAUSIBLE_DOMAIN`Plausible domain`null``ANALYTICS_PLAUSIBLE_API_URL`Plausible API URL`https://plausible.io/api`### Configuration Options

[](#configuration-options)

Key configuration options in `config/artisanpack/analytics.php`:

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

    // Active providers
    'active_providers' => ['local'], // Options: local, google, plausible

    // Local provider settings
    'local' => [
        'connection' => null,
        'table_prefix' => 'analytics_',
        'anonymize_ip' => true,
        'queue_processing' => true,
        'queue_name' => 'analytics',
    ],

    // Privacy settings
    'privacy' => [
        'consent_required' => false,
        'respect_dnt' => true,
        'cookie_name' => 'analytics_consent',
        'cookie_duration' => 365,
    ],

    // Data retention
    'retention' => [
        'period' => 90, // days, null = keep forever
        'aggregate_before_delete' => true,
    ],

    // Multi-tenant settings
    'multi_tenant' => [
        'enabled' => false,
        'resolver' => 'domain', // domain, subdomain, api_key, header
    ],

    // Dashboard settings
    'dashboard' => [
        'prefix' => 'analytics',
        'middleware' => ['web', 'auth'],
        'cache_duration' => 300,
    ],
];
```

Artisan Commands
----------------

[](#artisan-commands)

```
# Install the package (migrations, config, assets)
php artisan analytics:install

# Create a new analytics site (multi-tenant)
php artisan analytics:create-site "Site Name" --domain=example.com

# List all configured sites
php artisan analytics:list-sites

# Regenerate API key for a site
php artisan analytics:regenerate-api-key {site_id}

# Clean up old data based on retention settings
php artisan analytics:cleanup

# Clean up data older than specific days
php artisan analytics:cleanup --days=30

# Preview cleanup without deleting
php artisan analytics:cleanup --dry-run

# Aggregate raw data into summary tables
php artisan analytics:aggregate

# Export analytics data
php artisan analytics:export --format=csv --output=analytics.csv

# Delete visitor data (GDPR compliance)
php artisan analytics:delete-visitor {visitor_id}

# Clear analytics cache
php artisan analytics:clear-cache

# Warm dashboard cache
php artisan analytics:warm-cache

# Display quick statistics
php artisan analytics:stats --period=month
```

### Scheduling Commands

[](#scheduling-commands)

Add to your scheduler for automated maintenance:

```
// routes/console.php or bootstrap/app.php
use Illuminate\Support\Facades\Schedule;

Schedule::command('analytics:cleanup')->daily();
Schedule::command('analytics:aggregate')->hourly();
Schedule::command('analytics:warm-cache')->hourly();
```

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

[](#requirements)

- Laravel 11 or 12: PHP 8.2+
- Laravel 13: PHP 8.3+
- Livewire 3.6.4+

Dependencies
------------

[](#dependencies)

The package has minimal external dependencies:

- [doctrine/dbal](https://github.com/doctrine/dbal) - Database abstraction
- [nesbot/carbon](https://github.com/briannesbitt/Carbon) - Date handling
- [livewire/livewire](https://github.com/livewire/livewire) - Reactive components

Optional integrations with the ArtisanPack UI ecosystem:

- [artisanpack-ui/livewire-ui-components](https://github.com/ArtisanPack-UI/livewire-ui-components) - UI components for dashboard
- [artisanpack-ui/hooks](https://github.com/ArtisanPack-UI/hooks) - WordPress-style hooks for extensibility

Events
------

[](#events)

The package dispatches events for key actions:

```
use ArtisanPackUI\Analytics\Events\PageViewRecorded;
use ArtisanPackUI\Analytics\Events\EventTracked;
use ArtisanPackUI\Analytics\Events\SessionStarted;
use ArtisanPackUI\Analytics\Events\GoalCompleted;
use ArtisanPackUI\Analytics\Events\ConsentGiven;
use ArtisanPackUI\Analytics\Events\ConsentRevoked;

// Listen for page views
Event::listen(PageViewRecorded::class, function ($event) {
    // $event->pageView contains the page view model
});

// Listen for custom events
Event::listen(EventTracked::class, function ($event) {
    // $event->event contains the tracked event
});

// Listen for goal completions
Event::listen(GoalCompleted::class, function ($event) {
    // $event->goal contains the completed goal
    // $event->conversion contains the conversion record
});
```

Extensibility
-------------

[](#extensibility)

### Custom Analytics Providers

[](#custom-analytics-providers)

Create custom providers by implementing `AnalyticsProviderInterface`:

```
use ArtisanPackUI\Analytics\Contracts\AnalyticsProviderInterface;
use ArtisanPackUI\Analytics\Data\PageViewData;
use ArtisanPackUI\Analytics\Data\EventData;

class MixpanelProvider implements AnalyticsProviderInterface
{
    public function trackPageView(PageViewData $data): void
    {
        // Send to Mixpanel
    }

    public function trackEvent(EventData $data): void
    {
        // Send to Mixpanel
    }

    public function isEnabled(): bool
    {
        return config('services.mixpanel.enabled', false);
    }

    public function getName(): string
    {
        return 'mixpanel';
    }
}

// Register in a service provider
Analytics::extend('mixpanel', function ($app) {
    return new MixpanelProvider(config('services.mixpanel'));
});
```

### Custom Site Resolvers (Multi-Tenant)

[](#custom-site-resolvers-multi-tenant)

Create custom resolvers by implementing `SiteResolverInterface`:

```
use ArtisanPackUI\Analytics\Contracts\SiteResolverInterface;
use Illuminate\Http\Request;

class TeamResolver implements SiteResolverInterface
{
    public function resolve(Request $request): ?Site
    {
        $teamId = $request->user()?->current_team_id;
        return Site::where('team_id', $teamId)->first();
    }
}

// Register in config
'multi_tenant' => [
    'enabled' => true,
    'resolver' => App\Analytics\TeamResolver::class,
],
```

### Filter Hooks

[](#filter-hooks)

Extend functionality using filter hooks:

```
use function addFilter;

// Modify page view data before recording
addFilter('analytics.pageview.data', function (array $data) {
    $data['custom_dimension'] = 'value';
    return $data;
});

// Add custom excluded paths
addFilter('analytics.excluded_paths', function (array $paths) {
    $paths[] = '/internal/*';
    return $paths;
});

// Modify dashboard query
addFilter('analytics.dashboard.query', function ($query) {
    return $query->where('is_bot', false);
});
```

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

[](#contributing)

Contributions are welcome! To contribute:

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

Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct and the process for submitting merge requests.

License
-------

[](#license)

ArtisanPack UI Analytics is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance93

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

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

Total

5

Last Release

43d ago

### Community

Maintainers

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

---

Top Contributors

[![ViewFromTheBox](https://avatars.githubusercontent.com/u/8247489?v=4)](https://github.com/ViewFromTheBox "ViewFromTheBox (95 commits)")

---

Tags

analyticsdashboardgoogle-analyticslaravellaravel-packagephptrackinglaraveltrackinglivewiredashboardanalyticsprivacy

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/artisanpack-ui-analytics/health.svg)

```
[![Health](https://phpackages.com/badges/artisanpack-ui-analytics/health.svg)](https://phpackages.com/packages/artisanpack-ui-analytics)
```

###  Alternatives

[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M130](/packages/laravel-pulse)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M130](/packages/roots-acorn)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k29.9M145](/packages/laravel-cashier)[flarum/core

Delightfully simple forum software.

201.4M2.3k](/packages/flarum-core)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M149](/packages/laravel-mcp)

PHPackages © 2026

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