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.
This version supports PHP 8.0. You can install the package via 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);
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($dateFrom, $dateTo)
->interval('hour')
->groupBy('hostname')
->timezone('UTC')
->orderBy('visits', true)
->where('device', '!=', 'iPhone')
->where('hostname', '<>', 'google.com')
->get();
$fathom->reports()->for(Entity::PAGEVIEW, 'CNODFN');
// or
$site = $fathom->sites()->get()->first();
$fathom->reports($site)->get(
aggregate: Aggregate::PAGEVIEW
);
// or
$site = $fathom->sites()->get()->first();
$fathom->reports()->get(
entity: $site,
aggregate: Aggregate::PAGEVIEW
);
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 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();
composer test
- Current visitors
The MIT License (MIT). Please see License File for more information.