### Install with Composer Source: https://github.com/jeffersongoncalves/laravel-metrics-plausible/blob/main/README.md Installs the package via Composer. ```bash composer require jeffersongoncalves/laravel-metrics-plausible ``` -------------------------------- ### Import Enums and Facade Source: https://github.com/jeffersongoncalves/laravel-metrics-plausible/blob/main/README.md Imports the enums and facade used throughout the usage examples. ```php use JeffersonGoncalves\MetricsPlausible\Enums\DateRange; use JeffersonGoncalves\MetricsPlausible\Enums\Dimension; use JeffersonGoncalves\MetricsPlausible\Enums\Metric; use JeffersonGoncalves\MetricsPlausible\Facades\Plausible; ``` -------------------------------- ### Aggregate Totals Source: https://github.com/jeffersongoncalves/laravel-metrics-plausible/blob/main/README.md Fetches aggregate totals with default metrics and period, or custom metrics and a date range. The returned object provides accessors like visitors(), visits(), pageviews(), bounceRate(), visitDuration(), and get(). ```php $stats = Plausible::aggregate(); $stats->visitors(); // 1234 $stats->visits(); // 1500 $stats->pageviews(); // 4321 $stats->bounceRate(); // 41.5 $stats->visitDuration(); // 96.0 // Custom metrics and period $stats = Plausible::aggregate([Metric::Visitors, Metric::Events], DateRange::Last7Days); $stats->get('events'); ``` -------------------------------- ### Run Migrations Source: https://github.com/jeffersongoncalves/laravel-metrics-plausible/blob/main/README.md Runs migrations to create the settings table. ```bash php artisan migrate ``` -------------------------------- ### Manage Sites Source: https://github.com/jeffersongoncalves/laravel-metrics-plausible/blob/main/README.md Lists, retrieves, creates, and deletes sites. createSite takes a domain and timezone. ```php Plausible::sites(); // list sites Plausible::site('example.com'); // one site Plausible::createSite('example.com', 'America/Sao_Paulo'); Plausible::deleteSite('example.com'); ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/jeffersongoncalves/laravel-metrics-plausible/blob/main/README.md Environment variables used to seed settings after migration. PLAUSIBLE_API_KEY is created under Settings → API Keys in Plausible, PLAUSIBLE_SITE_ID is the site domain, and PLAUSIBLE_BASE_URL can point to a self-hosted instance. ```env PLAUSIBLE_API_KEY=your-api-key PLAUSIBLE_SITE_ID=example.com PLAUSIBLE_BASE_URL=https://plausible.io ``` -------------------------------- ### Manage Goals Source: https://github.com/jeffersongoncalves/laravel-metrics-plausible/blob/main/README.md Lists goals, creates event and page goals, and deletes a goal by ID. ```php Plausible::goals(); Plausible::createEventGoal('Signup'); Plausible::createPageGoal('/checkout/success'); Plausible::deleteGoal(1); ``` -------------------------------- ### Custom Query with Explicit Dates and Pagination Source: https://github.com/jeffersongoncalves/laravel-metrics-plausible/blob/main/README.md Shows explicit date ranges, pagination, imported data, and time labels in a custom query. ```php $query = Plausible::query() ->metrics(Metric::Visitors) ->between('2026-01-01', '2026-01-31') ->dimensions(Dimension::TimeDay) ->withImports() ->withTimeLabels() ->limit(100) ->offset(100); ``` -------------------------------- ### Apply Logical Filter with rawFilter Source: https://github.com/jeffersongoncalves/laravel-metrics-plausible/blob/main/README.md Applies a logical filter using rawFilter() on an existing query object. ```php $query->rawFilter(['not', ['is', 'visit:source', ['Google']]]); ``` -------------------------------- ### Update Settings Programmatically Source: https://github.com/jeffersongoncalves/laravel-metrics-plausible/blob/main/README.md Updates the Plausible settings programmatically via the PlausibleSettings class. ```php use JeffersonGoncalves\MetricsPlausible\Settings\PlausibleSettings; $settings = app(PlausibleSettings::class); $settings->api_key = 'new-key'; $settings->site_id = 'example.com'; $settings->base_url = 'https://analytics.example.com'; $settings->save(); ``` -------------------------------- ### Realtime Visitors Source: https://github.com/jeffersongoncalves/laravel-metrics-plausible/blob/main/README.md Returns the current number of realtime visitors. ```php $visitors = Plausible::realtimeVisitors(); // 42 ``` -------------------------------- ### Breakdowns for Various Dimensions Source: https://github.com/jeffersongoncalves/laravel-metrics-plausible/blob/main/README.md Fetches breakdown data for various dimensions: pages, entry/exit pages, sources, channels, UTM, countries, regions, cities, devices, browsers, operating systems, goals, and custom events. Also shows how to access row properties and use the generic breakdown() method with any dimension. ```php $pages = Plausible::pages(DateRange::Last30Days, limit: 10); $entry = Plausible::entryPages(); $exit = Plausible::exitPages(); $sources = Plausible::sources(); $channels = Plausible::channels(); $utm = Plausible::utm('utm_campaign'); $countries = Plausible::countries(); $regions = Plausible::regions(); $cities = Plausible::cities(); $devices = Plausible::devices(); $browsers = Plausible::browsers(); $os = Plausible::operatingSystems(); $goals = Plausible::goalConversions(); $events = Plausible::customEvents(); foreach ($pages as $row) { echo $row->label; // /blog/hello-world echo $row->visitors(); // 90 echo $row->metric('pageviews'); // 120 } // Any other dimension $rows = Plausible::breakdown(Dimension::Hostname); $rows = Plausible::breakdown(Dimension::property('plan')); ``` -------------------------------- ### Custom Query with Query Builder Source: https://github.com/jeffersongoncalves/laravel-metrics-plausible/blob/main/README.md Builds a custom query using the query builder that maps onto the Stats API v2 payload. Supports metrics, date range, dimensions, filters, ordering, and limit. Execute with rows() for a list of StatsRow or run() for the raw API response. ```php $query = Plausible::query() ->metrics(Metric::Visitors, Metric::Pageviews, Metric::BounceRate) ->dateRange(DateRange::Last7Days) ->dimensions(Dimension::Page) ->filter('is', Dimension::Country, ['BR', 'PT']) ->orderBy(Metric::Visitors, 'desc') ->limit(50); $rows = Plausible::rows($query); // list $raw = Plausible::run($query); // raw API response ``` -------------------------------- ### Timeseries Data Source: https://github.com/jeffersongoncalves/laravel-metrics-plausible/blob/main/README.md Retrieves timeseries data with configurable date range and dimension. Defaults to daily visitors and pageviews over the last 30 days; supports hourly, monthly, and other periods. ```php // Daily visitors and pageviews over the last 30 days $rows = Plausible::timeseries(); foreach ($rows as $row) { echo $row->label.': '.$row->visitors(); // 2026-09-01: 120 } // Hourly, today $rows = Plausible::timeseries(DateRange::Day, Dimension::TimeHour); // Monthly, last 12 months $rows = Plausible::timeseries(DateRange::Last12Months, Dimension::TimeMonth); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.