PHP code example of schmeits / filament-umami-widgets

1. Go to this page and download the library: Download schmeits/filament-umami-widgets 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/ */

    

schmeits / filament-umami-widgets example snippets


return [
    /*
    |--------------------------------------------------------------------------
    | Umami type
    |--------------------------------------------------------------------------
    |
    | Which version of Umami are you using?
    | Option 1: self_hosted (https://umami.is/docs)
    | Option 2: cloud (https://umami.is/docs/cloud)
    |
    */
    'type' => env('UMAMI_TYPE', 'self-hosted'),

    /*
    |--------------------------------------------------------------------------
    | Umami API Endpoint URL
    |--------------------------------------------------------------------------
    |
    | For the self hosted version you should provide the API
    | endpoint e.g. https://your_url.com/api
    |
    | If you are using the Cloud type your values should be something
    | like: https://api.umami.is/v1
    |
    */
    'api_endpoint_url' => env('UMAMI_API_ENDPOINT', 'https://api.umami.is/v1'),

    /*
    |--------------------------------------------------------------------------
    | Umami Website ID
    |--------------------------------------------------------------------------
    |
    | This is the ID of the website stats you want to show on the website
    |
    | In Umami Cloud you can find the ID by going to Websites
    | Click edit and use the Website ID provided
    |
    | In the self-hosted version navigate to Settings and edit the website
    | use the Website ID provided
    |
    */
    'website_id' => env('UMAMI_WEBSITE_ID', null),

    /*
    |--------------------------------------------------------------------------
    | Umami Http options
    |--------------------------------------------------------------------------
    |
    | The timeout options defines the default timeout for the API requests
    | in seconds
    |
    */
    'timeout' => env('UMAMI_TIMEOUT', 5),

    /*
    |--------------------------------------------------------------------------
    | Self Hosted Options
    |--------------------------------------------------------------------------
    |
    | Add a user to your Umami installation
    | https://umami.is/docs/add-a-user
    |
    */
    'username' => env('UMAMI_USERNAME', null),
    'password' => env('UMAMI_PASSWORD', null),

    /*
    |--------------------------------------------------------------------------
    | Cloud Options
    |--------------------------------------------------------------------------
    |
    | Check the website how to obtain an API key
    | https://umami.is/docs/cloud/api-key
    |
    */
    'cloud_api_key' => env('UMAMI_API_KEY', null),

    /*
    |--------------------------------------------------------------------------
    | Caching options
    |--------------------------------------------------------------------------
    |
    | You can set the options for the caching here
    | cache_time is the time the values will be cached in seconds
    |
    */
    'cache_time' => 300,
    
];

namespace App\Filament\Pages;

use Schmeits\FilamentUmami\Concerns\HasFilter;

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

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

->plugins([
    \Schmeits\FilamentUmami\FilamentUmamiPlugin::make()
])

->widgets([
    Widgets\AccountWidget::class,
    Widgets\FilamentInfoWidget::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetStatsGrouped::class, // <-- add this widget
])

->widgets([
    // this is the grouped stats widget
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetStatsGrouped::class,

    // these are the separate stats widgets
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetStatsLiveVisitors::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetStatsPageViews::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetStatsVisitors::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetStatsVisits::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetStatsBounces::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetStatsTotalTime::class,

    // and some table widgets
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetTableUrls::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetTableTitle::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetTableReferrers::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetTableCountry::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetTableRegion::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetTableCity::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetTableDevice::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetTableOs::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetTableBrowser::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetTableLanguage::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetTableScreen::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetTableEvents::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetTableQuery::class,

    // grouped table widgets
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetTableGroupedPages::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetTableGroupedGeo::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetTableGroupedClientInfo::class,

    // chart widgets
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetGraphPageViews::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetGraphSessions::class,
    \Schmeits\FilamentUmami\Widgets\UmamiWidgetGraphEvents::class,
])

    \Schmeits\FilamentUmami\FilamentUmamiPlugin::make()
        ->pollingInterval("60s") //Auto polling interval
        ->widgetsForGroupedStats([
            UmamiStatsWidgets::WIDGET_LIVE,
            UmamiStatsWidgets::WIDGET_PAGEVIEWS,
            UmamiStatsWidgets::WIDGET_VISITORS,
            UmamiStatsWidgets::WIDGET_TOTAL_TIME,
            UmamiStatsWidgets::WIDGET_BOUNCES,
            UmamiStatsWidgets::WIDGET_VISITS,
        ]),

use Schmeits\FilamentUmami\Concerns\Filter;

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

use Schmeits\FilamentUmami\Facades\FilamentUmami;

// Gets the number of active users on a website.
$activeVisitors = FilamentUmami::activeVisitors($filter);

// *** STATS ***

// Pages hits
$views = FilamentUmami::pageViews($filter);

// Number of unique visitors
$visitors = FilamentUmami::visitors($filter);

// Number of sessions
$visits = FilamentUmami::visits($filter);

// Number of visitors who only visit a single page
$bounces = FilamentUmami::bounces($filter);

// Time spent on the website (formatted H:i)
$total_time = FilamentUmami::totalTime($filter);

// *** METRICS ***

// Get pages visited url's
$pages = FilamentUmami::metricsPages($filter);
// or
$pages = FilamentUmami::metrics($filter, \Schmeits\FilamentUmami\Enums\UmamiMetricTypes::METRIC_PAGES);

// *** PAGEVIEWS LAST 7 DAYS ***
$views_and_sessions = FilamentUmami::pageViewsAndSessions(); 


enum UmamiMetricTypes: string
{
    case METRIC_PAGES = 'url'; // Url's of the Pages visited
    case METRIC_TITLE = 'title'; // Titles of the Pages visited
    case METRIC_REFERRER = 'referrer'; // Referrers (where do the visitors come from)
    case METRIC_BROWSER = 'browser'; // Browser (Chrome, Edge, Safari, etc.)
    case METRIC_OS = 'os'; // Operating system (iOS, MacOS, etc.)
    case METRIC_DEVICE = 'device'; // Devices (Laptop, Mobile, etc.)
    case METRIC_COUNTRY = 'country'; // Countries (US, NL, etc.)
    case METRIC_REGION = 'region'; // Regions (NL-LI, US-AZ, NL-NH, etc.)
    case METRIC_CITY = 'city'; // Cities (Amsterdam, Netherlands / Phoenix, United States / etc)
    case METRIC_LANGUAGE = 'language'; // Languages (Dutch, English, etc.)
    case METRIC_SCREEN = 'screen'; // Screen resolutions (1440x900, 1920x1200, etc.)
    case METRIC_EVENT = 'event'; // Events (Clicked link, etc.)
    case METRIC_QUERY = 'query'; // Query parameters (search=test, etc.)
}

bash
php artisan vendor:publish --tag="filament-umami-widgets-config"
bash
php artisan vendor:publish --tag="filament-umami-widgets-views"
bash
php artisan vendor:publish --tag="filament-umami-widgets-translations"