based/fathom 问题修复 & 功能扩展

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

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

based/fathom

Composer 安装命令:

composer require based/fathom

包简介

Fathom Analytics API PHP Client

README 文档

README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

This package is a wrapper for the newly released Fathom Analytics API. The package is in wip mode as the API is still in early access.

Installation

This version supports PHP 8.0. You can install the package via composer:

composer require based/fathom

Usage

Account

<?php

$fathom = new Fathom('token');

$fathom->account();

Sites

<?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);

Events

<?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);

Aggregation

Generate an aggregation. This is effectively an unbelievably flexible report that allows you to group on any fields you wish, and filter them at your leisure.

<?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
);

Get Current Visitors

$fathom->sites()->getCurrentVisitors('XXXXX');

Laravel

This package contains a facade and a config file for Laravel applications.

You can publish the config file with:

php artisan vendor:publish --provider="Based\Fathom\FathomServiceProvider" --tag="fathom-config"

This is the contents of the published config file:

return [
    'token' => env('FATHOM_TOKEN'),
];

Update the config file directly, or set the environment variable FATHOM_TOKEN to your API key (preferred).

Example

Example using a facade:

<?php

use Based\Fathom\Facade\Fathom;

Fathom::account()->get();
Fathom::sites()->get();
Fathom::sites()->create(...);

Or create an instance directly:

<?php

use Based\Fathom\Fathom;

$fathom = new Fathom(config('fathom.token'));
$fathom->account()->get();

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

  • Stars: 22
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-08-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固