基于 / 测量
测量分析API PHP客户端
v0.1.2
2021-08-16 17:38 UTC
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.3
- illuminate/http: ^8.54
- illuminate/validation: ^8.54
- spatie/laravel-package-tools: ^1.4.3
Requires (Dev)
- nunomaduro/larastan: ^0.6.10
- orchestra/testbench: ^6.20
- pestphp/pest: ^1.15
README
此包是新发布的测量分析API的包装器。由于API仍处于早期访问阶段,因此该包处于work in progress(进行中)模式。
安装
此版本支持PHP 8.0。您可以通过composer安装此包
composer require based/fathom
使用方法
账户
<?php $fathom = new Fathom('token'); $fathom->account();
网站
<?php $fathom = new Fathom('token'); $fathom->sites()->get( limit: 10, // A limit on the number of objects to be returned, between 1 and 100 next: true // Paginate requests ); $site = $fathom->sites()->getSite( siteId: 'BASED', // The ID of the site you wish to load ); $fathom->sites()->create( name: 'purple-peak', sharing: 'private', // The sharing configuration. Supported values are: `none`, `private` or `public`. Default: `none` password: 'secret', // When sharing is set to private, you must also send a password to access the site with. ); $fathom->sites()->update( siteId: 'BASED', name: 'purple-peak', sharing: Sharing::NONE, password: 'secret', ); // Wipe all pageviews & event completions from a website $fathom->sites()->wipe($siteId); $fathom->sites()->delete($siteId);
事件
<?php $fathom = new Fathom('token'); $fathom->events()->get( siteId: 'BASED', // The ID of the site you wish to load events for limit: 10, // A limit on the number of objects to be returned, between 1 and 100 next: true // Paginate requests ); $fathom->events()->getEvent($siteId, $eventId); $fathom->events()->create( siteId: 'purple-peak', name: 'Purchase early access', ); $fathom->events()->update( siteId: 'BASED', eventId: 'purchase-early-access', name: 'Purchase early access (live)', ); // Wipe all pageviews & event completions from a webevent $fathom->events()->wipe($siteId, $eventId); $fathom->events()->delete($siteId, $eventId);
聚合
生成一个聚合。这是一个非常灵活的报告,允许您根据任何您希望的任何字段进行分组,并在您方便的时候进行筛选。
<?php $fathom = new Fathom('token'); $fathom->reports() ->for('pageview', 'CNODFN') ->aggregate(['visits', 'uniques']) ->between(now()->subMonth()->startOfDay(), now()) ->interval('hour') ->timezone('UTC') ->where('device', '!=', 'iPhone') ->where('hostname', '<>', 'google.com') ->groupBy('hostname') ->orderBy('visits', true) ->limit(10) ->get(); $fathom->reports()->for(Entity::PAGEVIEW, 'CNODFN'); // or $site = $fathom->sites()->get()->first(); $fathom->reports($site)->get( aggregate: Aggregate::VISITS ); // or $site = $fathom->sites()->get()->first(); $fathom->reports()->get( entity: $site, aggregate: Aggregate::VISITS );
获取当前访客
$fathom->sites()->getCurrentVisitors('XXXXX');
Laravel
此包包含Laravel应用程序的facade和配置文件。
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Based\Fathom\FathomServiceProvider" --tag="fathom-config"
这是已发布的配置文件的内容
return [ 'token' => env('FATHOM_TOKEN'), ];
直接更新配置文件,或将环境变量FATHOM_TOKEN
设置为您的API密钥(推荐)。
示例
使用facade的示例
<?php use Based\Fathom\Facade\Fathom; Fathom::account()->get(); Fathom::sites()->get(); Fathom::sites()->create(...);
或者直接创建一个实例
<?php use Based\Fathom\Fathom; $fathom = new Fathom(config('fathom.token')); $fathom->account()->get();
测试
composer test
鸣谢
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。