API wrapper for umami website analytics. get your statistics in the laravel app.
check out Umami, own your website analytics
- Manage websites
- Manage users
- query statistics stats, page views, events and metrics
You can install the package via composer:
composer require still-code/laravel-umami
- for umami v1 use v4
- for umami v2 use v5
to publish the configuration file:
php artisan vendor:publish --provider="Umami\UmamiServiceProvider"
and then add these to your .env
file:
UMAMI_URL=https://stats-site-com/api
UMAMI_USERNAME=username
UMAMI_PASSWORD="password"
UMAMI_WEBSITE_ID=d131d2ae-5d21-4a54-80ba-16719afedf7b
\Umami\Umami::query('example-site-id', 'metrics', [
'start_at'=>today()->subDays(7),
'end_at'=>today(),
'type'=>'referrer',
]);
short usage for PHP 8
to get default stats for the last 7 days and without cache:
\Umami\Umami::query(siteID: 1, force: true)
required: site id from umami server
\Umami\Umami::query('example-site-id');
required: the stats part you want to get from umami,
available options : active, stats, pageviews, events, metrics
default: stats
\Umami\Umami::query('example-site-id','pageviews');
optional: Timestamp of starting and end date,
default: last 7 days
you can pass carbon
object or timestamp in milliseconds
\Umami\Umami::query('example-site-id','metrics',[
'start_at'=>today()->subDays(7),
'end_at'=>now(),
]);
only available on pageviews
and events
optional: Time unit, available options: year, month, hour, day
,
default: day
\Umami\Umami::query('example-site-id','metrics',[
'unit'=>'year',
]);
optional: Timezone,
only available on pageviews
and events
default: config('app.timezone')
\Umami\Umami::query('example-site-id','metrics',[
'tz'=>'America/Los_Angeles',
]);
optional: Gets metrics for a given time range,
available options: url, referrer, browser, os, device, country, event
,
default: url
\Umami\Umami::query('example-site-id','metrics',[
'tz'=>'America/Los_Angeles',
]);
\Umami\Umami::websites();
\Umami\Umami::createWebsite([
'domain'=>'domain.ltd',
'name'=>'user name',
]);
If you want to create a website for different user then the admin user defined in the config, you need to provide the authentication for that user. this is helpful when creating a new user with a website
\Umami\Umami::createWebsite([
'domain' => 'domain.ltd',
'name' => 'user name',
],[
'username' => 'otherUserName',
'password' => 'otherPassword',
]);
\Umami\Umami::updateWebsites('example-site-id',[
'name'=>'user name',
]);
\Umami\Umami::deleteWebsite('example-site-id');
See the API documentation for details: https://umami.is/docs/api/event-data#get-/api/event-data/events
\Umami\Umami::events('example-site-id', [
'start_at'=>today()->subDays(7),
'end_at'=>now(),
'event' => 'custom_event',
]);
See the API documentation for details: https://umami.is/docs/api/event-data#get-/api/event-data/fields
\Umami\Umami::event_fields('example-site-id', [
'start_at'=>today()->subDays(7),
'end_at'=>now(),
]);
\Umami\Umami::users();
\Umami\Umami::createUser('username','password');
\Umami\Umami::updateUser(1,[
'username'=>'username',
'password'=>'password',
]);
\Umami\Umami::deleteUser(2);
Please check out Umami website for more information.
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.