https://github.com/still-code/laravel-umami
API wrapper for umami website analytics. get your stats in the laravel app
https://github.com/still-code/laravel-umami
Last synced: over 1 year ago
JSON representation
API wrapper for umami website analytics. get your stats in the laravel app
- Host: GitHub
- URL: https://github.com/still-code/laravel-umami
- Owner: still-code
- License: mit
- Created: 2021-10-03T10:21:15.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-03-26T02:59:17.000Z (about 2 years ago)
- Last Synced: 2024-03-26T03:44:45.701Z (about 2 years ago)
- Language: PHP
- Homepage:
- Size: 170 KB
- Stars: 12
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README

# Umami API wrapper for laravel
API wrapper for umami website analytics. get your statistics in the laravel app.
check out [Umami](https://umami.is/), own your website analytics
## Features
- Manage websites
- Manage users
- query statistics stats, page views, events and metrics
## Installation
You can install the package via composer:
```bash
composer require still-code/laravel-umami
```
#### Umami version:
- for umami v1 use v4
- for umami v2 use v5
### Config
to publish the configuration file:
```bash
php artisan vendor:publish --provider="Umami\UmamiServiceProvider"
```
and then add these to your `.env` file:
```bash
UMAMI_URL=https://stats-site-com/api
UMAMI_USERNAME=username
UMAMI_PASSWORD="password"
UMAMI_WEBSITE_ID=d131d2ae-5d21-4a54-80ba-16719afedf7b
```
## Usage
### Query Stats
```php
\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:
```php
\Umami\Umami::query(siteID: 1, force: true)
```
### Parameters
#### Site id
required: site id from umami server
```php
\Umami\Umami::query('example-site-id');
```
#### Part
required: the stats part you want to get from umami,
available options : `active, stats, pageviews, events, metrics`
default: `stats`
```php
\Umami\Umami::query('example-site-id','pageviews');
```
### Options for Query Stats
#### Dates (start_at,end_at)
optional: Timestamp of starting and end date,
default: last 7 days
you can pass `carbon` object or timestamp in milliseconds
```php
\Umami\Umami::query('example-site-id','metrics',[
'start_at'=>today()->subDays(7),
'end_at'=>now(),
]);
```
##### unit
only available on `pageviews` and `events`
optional: Time unit, available options: `year, month, hour, day`,
default: day
```php
\Umami\Umami::query('example-site-id','metrics',[
'unit'=>'year',
]);
```
##### Timezone (tz)
optional: Timezone,
only available on `pageviews` and `events`
default: config('app.timezone')
```php
\Umami\Umami::query('example-site-id','metrics',[
'tz'=>'America/Los_Angeles',
]);
```
##### type (for metrics only)
optional: Gets metrics for a given time range,
available options: `url, referrer, browser, os, device, country, event`,
default: url
```php
\Umami\Umami::query('example-site-id','metrics',[
'tz'=>'America/Los_Angeles',
]);
```
## Websites
### Get All websites
```php
\Umami\Umami::websites();
```
### Create a website
```php
\Umami\Umami::createWebsite([
'domain'=>'domain.ltd',
'name'=>'user name',
]);
```
#### create a website for a diffrent user
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
```php
\Umami\Umami::createWebsite([
'domain' => 'domain.ltd',
'name' => 'user name',
],[
'username' => 'otherUserName',
'password' => 'otherPassword',
]);
```
### Update a website
```php
\Umami\Umami::updateWebsites('example-site-id',[
'name'=>'user name',
]);
```
### Delete a website
```php
\Umami\Umami::deleteWebsite('example-site-id');
```
## Event data
### Get website event and field key record counts within a given time range
See the API documentation for details: https://umami.is/docs/api/event-data#get-/api/event-data/events
```php
\Umami\Umami::events('example-site-id', [
'start_at'=>today()->subDays(7),
'end_at'=>now(),
'event' => 'custom_event',
]);
```
### Get website field key and value record counts within a given time range
See the API documentation for details: https://umami.is/docs/api/event-data#get-/api/event-data/fields
```php
\Umami\Umami::event_fields('example-site-id', [
'start_at'=>today()->subDays(7),
'end_at'=>now(),
]);
```
## Users
### Get all users
```php
\Umami\Umami::users();
```
### Create a user
```php
\Umami\Umami::createUser('username','password');
```
### Update a user
```php
\Umami\Umami::updateUser(1,[
'username'=>'username',
'password'=>'password',
]);
```
### Delete a user
```php
\Umami\Umami::deleteUser(2);
```
## More details
Please check out [Umami website](https://umami.is/) for more information.
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Credits
- [Mike Cao](https://github.com/mikecao)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.