PHP code example of devlogx / filament-fathom-dashboard-widget

1. Go to this page and download the library: Download devlogx/filament-fathom-dashboard-widget 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/ */

    

devlogx / filament-fathom-dashboard-widget example snippets


return [
    /*
    |--------------------------------------------------------------------------
    | Fathom API-Token & Site id
    |--------------------------------------------------------------------------
    |
    | You can acquire your API-Token from the url below:
    | https://app.usefathom.com/api
    |
    */
    'api_token' => env('FATHOM_API_TOKEN'),
    'site_id' => env('FATHOM_SITE_ID'),

    /*
    |--------------------------------------------------------------------------
    | Fathom Domain
    |--------------------------------------------------------------------------
    |
    | If you're from the EU, I can recommend using the EU CDN:
    | cdn-eu.usefathom.com
    |
    */
    'domain' => env('FATHOM_DOMAIN', 'cdn.usefathom.com'),

    /*
    |--------------------------------------------------------------------------
    | Stats cache ttl
    |--------------------------------------------------------------------------
    |
    | This value is the ttl for the displayed dashboard
    | stats values. You can increase or decrease
    | this value.
    |
    */
    'cache_time' => 300,
];



namespace App\Filament\Pages;

use Devlogx\FilamentFathom\Concerns\HasFilter;

class Dashboard extends \Filament\Pages\Dashboard
{
    use HasFilter;
    
}

->pages([
    //Pages\Dashboard::class,
])

->widgets([
    Widgets\AccountWidget::class,
    Widgets\FilamentInfoWidget::class,
    \Devlogx\FilamentFathom\Widgets\FathomStatsWidget::class,// <-- add this widget
])

->plugins([
    \Devlogx\FilamentFathom\FilamentFathomPlugin::make()
])

->plugins([
    \Devlogx\FilamentFathom\FilamentFathomPlugin::make()
        ->fathomLink(true) //Direct link to fathom analytics page
        ->pollingInterval("60s") //Auto polling interval
        ->filterSectionIcon("heroicon-s-adjustments-vertical")
        ->filterSectionIconColor("primary")
        ->liveVisitorIcon("heroicon-s-user") //First Block | Live Visitors
        ->liveVisitorColor("primary") //First Block | Live Visitors
        ->visitorsIcon("heroicon-s-user-group") //Second Block | All Visitors
        ->visitorsColor("primary") //Second Block | All Visitors
        ->viewsIcom("heroicon-s-eye") //Third Block | All Page Views
        ->visitorsColor("primary") //Third Block | All Page Views
        ->sessionTimeIcon("heroicon-s-clock") //Fourth Block | Avg. Session Time
        ->sessionTimeColor("primary") //Fourth Block | Avg. Session Time
])


use Devlogx\FilamentFathom\Facades\FilamentFathom;

$dashboardLink = FilamentFathom::getDashboardLink();

use Devlogx\FilamentFathom\Concerns\Filter;

$filter = (new Filter())
    ->setFrom(Carbon::now()->subDays(30))
    ->setTo(Carbon::now());

use Devlogx\FilamentFathom\Facades\FilamentFathom;

//Get active visitors
$activeVisitors = FilamentFathom::activeVisitors($filter,false);

//Get avg session duration
$sessionDuration = FilamentFathom::sessionDuration($filter,false);

//Get visitors
$visitors = FilamentFathom::visitors($filter,false);

//Get page views
$views = FilamentFathom::views($filter,false);
bash
php artisan vendor:publish --tag="filament-fathom-dashboard-widget-config"
bash
php artisan vendor:publish --tag="filament-fathom-dashboard-widget-translations"