PHP code example of based / fathom

1. Go to this page and download the library: Download based/fathom library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

based / fathom example snippets




$fathom = new Fathom('token');

$fathom->account();



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



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



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

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



use Based\Fathom\Facade\Fathom;

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



use Based\Fathom\Fathom;

$fathom = new Fathom(config('fathom.token'));
$fathom->account()->get();
bash
php artisan vendor:publish --provider="Based\Fathom\FathomServiceProvider" --tag="fathom-config"