jeffersongoncalves/laravel-metrics-fathom
Composer 安装命令:
composer require jeffersongoncalves/laravel-metrics-fathom
包简介
Laravel package to interact with Fathom Analytics API - fetch pageviews, visitors, events, and generate custom reports
README 文档
README
Laravel Metrics Fathom
Laravel package to interact with the Fathom Analytics API. Fetch pageviews, visitors, events, milestones, and generate custom aggregation reports.
Settings are stored in the database via spatie/laravel-settings — no config files needed.
Installation
composer require jeffersongoncalves/laravel-metrics-fathom
Run migrations to create the settings:
php artisan migrate
Configuration
After migration, the settings are seeded from environment variables:
FATHOM_API_TOKEN=your-api-token FATHOM_SITE_ID=your-site-id FATHOM_BASE_URL=https://api.usefathom.com/v1 FATHOM_TIMEZONE=UTC
You can also update settings programmatically:
use JeffersonGoncalves\MetricsFathom\Settings\FathomSettings; $settings = app(FathomSettings::class); $settings->api_token = 'new-token'; $settings->site_id = 'NEWSITE'; $settings->timezone = 'America/Sao_Paulo'; $settings->save();
Usage
Using the Facade
use JeffersonGoncalves\MetricsFathom\Facades\Fathom;
Account
$account = Fathom::account();
Sites
// List sites $result = Fathom::sites(limit: 20); foreach ($result['data'] as $site) { echo $site->id . ' - ' . $site->name; } // Get a site $site = Fathom::site('SITEID'); // Create a site use JeffersonGoncalves\MetricsFathom\Enums\Sharing; $site = Fathom::createSite('My Site', Sharing::Public); // Update a site $site = Fathom::updateSite('SITEID', name: 'New Name'); // Delete a site Fathom::deleteSite('SITEID');
Events
// List events $result = Fathom::events(); // Create an event $event = Fathom::createEvent('signup'); // Get an event $event = Fathom::event('EVENTID'); // Update an event $event = Fathom::updateEvent('EVENTID', 'new-name'); // Delete an event Fathom::deleteEvent('EVENTID');
Milestones
// List milestones $result = Fathom::milestones(); // Create a milestone $milestone = Fathom::createMilestone('v2.0 Launch', '2026-03-01'); // Update a milestone $milestone = Fathom::updateMilestone('MSID', name: 'v2.1 Launch'); // Delete a milestone Fathom::deleteMilestone('MSID');
Current Visitors
// Simple count $visitors = Fathom::currentVisitors(); echo $visitors->total; // 42 // Detailed (top pages & referrers) $visitors = Fathom::currentVisitors(detailed: true);
Aggregations (Custom Reports)
Build flexible reports using the fluent query builder:
use JeffersonGoncalves\MetricsFathom\Enums\Aggregate; use JeffersonGoncalves\MetricsFathom\Enums\DateGrouping; use JeffersonGoncalves\MetricsFathom\Enums\FieldGrouping; use JeffersonGoncalves\MetricsFathom\Enums\FilterOperator; // Pageviews per day for the last month $query = Fathom::query() ->aggregate(Aggregate::Visits, Aggregate::Pageviews, Aggregate::BounceRate) ->groupByDate(DateGrouping::Day) ->from('2026-02-01 00:00:00') ->to('2026-02-28 23:59:59'); $result = Fathom::aggregate($query); // Top pages by visits $query = Fathom::query() ->aggregate(Aggregate::Visits) ->groupByField(FieldGrouping::Pathname) ->sortBy('visits', 'desc') ->limit(10); $result = Fathom::aggregate($query); // Visitors by country $query = Fathom::query() ->aggregate(Aggregate::Uniques) ->groupByField(FieldGrouping::CountryCode) ->sortBy('uniques', 'desc'); $result = Fathom::aggregate($query); // Filter by UTM source $query = Fathom::query() ->aggregate(Aggregate::Visits, Aggregate::Uniques) ->where(FieldGrouping::UtmSource, FilterOperator::Is, 'twitter') ->from('2026-01-01 00:00:00'); $result = Fathom::aggregate($query); // Event conversions $query = Fathom::queryEvents() ->aggregate(Aggregate::Conversions, Aggregate::UniqueConversions) ->forSite('SITEID') ->forEvent('signup') ->groupByDate(DateGrouping::Month); $result = Fathom::aggregate($query);
Using DateTime Objects
use Carbon\Carbon; $query = Fathom::query() ->aggregate(Aggregate::Visits) ->between(Carbon::now()->subDays(30), Carbon::now()); $result = Fathom::aggregate($query);
Available Enums
Aggregate
Visits, Uniques, Pageviews, AvgDuration, BounceRate, Conversions, UniqueConversions, Value
DateGrouping
Hour, Day, Month, Year
FieldGrouping
Hostname, Pathname, ReferrerHostname, Referrer, Browser, BrowserVersion, CountryCode, City, DeviceType, OperatingSystem, OperatingSystemVersion, UtmSource, UtmMedium, UtmCampaign, UtmContent, UtmTerm
FilterOperator
Is, IsNot, IsLike, IsNotLike, Matching, NotMatching
Sharing
None, Private, Public
API Rate Limits
- Sites & Events: 2,000 requests/hour
- Aggregations & Current Visitors: 10 requests/minute
Testing
composer test
Code Style
composer format
Static Analysis
composer analyse
License
The MIT License (MIT). Please see License File for more information.
jeffersongoncalves/laravel-metrics-fathom 适用场景与选型建议
jeffersongoncalves/laravel-metrics-fathom 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 3, 最近一次更新时间为 2026 年 03 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「analytics」 「Metrics」 「laravel」 「visitors」 「privacy」 「pageviews」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jeffersongoncalves/laravel-metrics-fathom 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jeffersongoncalves/laravel-metrics-fathom 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jeffersongoncalves/laravel-metrics-fathom 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Analytics chooser extensions for site settings.
A abstraction for generating metrics in Laravel.
Laravel SDK for working with prometheus metrics
Production-ready Laravel Prometheus metrics package with built-in collectors for HTTP, database, cache, queue, events, errors, filesystem, and mail monitoring
A Laravel Nova Card to show Fathom Analytics stats.
Tool to show code coverage metrics, measured by PHP Unit in Cobertura format, in console and CI/CD pipeline
统计信息
- 总下载量: 35
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 32
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-02
