justawebdev/laravel-simple-analytics 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

justawebdev/laravel-simple-analytics

Composer 安装命令:

composer require justawebdev/laravel-simple-analytics

包简介

Lightweight server-side analytics for Laravel

README 文档

README

Latest Version on Packagist Total Downloads Laravel Version License

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

  • 🚀 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 & Helpers - Easy-to-use API
  • Performance Focused - Minimal overhead

📦 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

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

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

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

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

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

Generate a quick report from the command line:

php artisan analytics:report

Output:

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

🔧 Advanced Usage

Custom Middleware Implementation

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

<?php

namespace App\Http\Middleware;

use Closure;
use JustAWebDev\Analytics\Facades\Analytics;

class CustomAnalytics
{
    public function handle($request, Closure $next)
    {
        $response = $next($request);

        // Only track GET requests
        if ($request->isMethod('get')) {
            Analytics::pageView([
                'name' => $request->path(),
                'method' => $request->method(),
                'status' => $response->getStatusCode(),
                'user_agent' => $request->userAgent(),
            ]);
        }

        return $response;
    }
}

Database Schema

The package creates an analytics_events table with these columns:

  • id - Primary key
  • type - Event type (pageview, event)
  • name - Event name or page path
  • meta - JSON metadata (nullable)
  • method - HTTP method (nullable)
  • status - HTTP status code (nullable)
  • duration_ms - Response time in milliseconds (nullable)
  • created_at / updated_at - Timestamps

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

📄 License

This package is open-sourced software licensed under the MIT license.

🙏 Credits

Made with ❤️ for the Laravel community

justawebdev/laravel-simple-analytics 适用场景与选型建议

justawebdev/laravel-simple-analytics 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 justawebdev/laravel-simple-analytics 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 justawebdev/laravel-simple-analytics 我们能提供哪些服务?
定制开发 / 二次开发

基于 justawebdev/laravel-simple-analytics 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 27
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2026-04-25