devlogx/filament-fathom-dashboard-widget

This is my package filament-fathom-dashboard-widget
11,798 4
Install
composer require devlogx/filament-fathom-dashboard-widget
Latest Version:1.0.0
PHP:^8.1|^8.2|^8.3
License:MIT
Last Updated:May 15, 2024
Links: GitHub  ·  Packagist
Maintainer: devraeph

Filament Fathom Dashboard Widget

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package allows you to integrate a simple analytics dashboard widget for panel.

Screenshots

filament_fathom_light.jpg filament_fathom_dark.jpg

Installation

You can install the package via composer:

composer require devlogx/filament-fathom-dashboard-widget

Get the Fathom API-Token and add it your env file.

  1. Visit the Fathom "API" settings page.
  2. Login and click "Create New".
  3. Give your token a name.
  4. Select under Permissions "Site-specific key".
  5. Select your Site and below "Read".
  6. Add the copied API-Token to your .env file:
# ...
FATHOM_API_TOKEN="xxxxx|xxxxxxxxxxxxxxxxxxx"
FATHOM_SITE_ID="XXXXXXX"

You can publish the config file with:

php artisan vendor:publish --tag="filament-fathom-dashboard-widget-config"

Optionally, you can publish the translations using

php artisan vendor:publish --tag="filament-fathom-dashboard-widget-translations"

This is the contents of the published config file:

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,
];

Usage

Create own Dashboard file

Under Filament/Pages/ create a new file called Dashboard.php with following contents:

<?php

namespace App\Filament\Pages;

use Devlogx\FilamentFathom\Concerns\HasFilter;

class Dashboard extends \Filament\Pages\Dashboard
{
    use HasFilter;
    
}
Remove the default Dashboard from your PanelProvider
->pages([
    //Pages\Dashboard::class,
])

Alternatively if you already have a custom Dashboard, add the HasFilter trait to your Dashboard file.

Add the Widget to your PanelProvider

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

Add the plugin to your PanelProvider

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

Configure the plugin

->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
])

Using the raw Analytics functions

You can use the functions for your own widgets. There are plenty more available.

Get Dashboard link


use Devlogx\FilamentFathom\Facades\FilamentFathom;

$dashboardLink = FilamentFathom::getDashboardLink();

Defining the Filter

use Devlogx\FilamentFathom\Concerns\Filter;

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

Get different data

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

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

637,827,751 9,703
laravel/framework

The Laravel Framework.

589,172,971 34,950
laravel/tinker

Powerful REPL for the Laravel framework.

498,216,183 7,442
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

413,412,504 609
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

394,964,158 4,660

Version History

Version Released PHP License
1.0.0 ^8.1|^8.2|^8.3 MIT