still-code/laravel-umami

Umami API wrapper for laravel

5.0.2 2024-06-18 16:51 UTC

This package is auto-updated.

Last update: 2024-11-08 08:22:01 UTC


README

Umami API wrapper for laravel

API wrapper for umami website analytics. get your statistics in the laravel app.

check out Umami, 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:

composer require still-code/laravel-umami

Umami version:

  • for umami v1 use v4
  • for umami v2 use v5

Config

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

Usage

Query Stats

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

Parameters

Site id

required: site id from umami server

\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

\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

\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

\Umami\Umami::query('example-site-id','metrics',[
    'unit'=>'year',
]);
Timezone (tz)

optional: Timezone,

only available on pageviews and events

default: config('app.timezone')

\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

\Umami\Umami::query('example-site-id','metrics',[
    'tz'=>'America/Los_Angeles',
]);

Websites

Get All websites

\Umami\Umami::websites();

Create a website

\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

\Umami\Umami::createWebsite([
    'domain' => 'domain.ltd',
    'name' => 'user name',
],[
    'username' => 'otherUserName',
    'password' => 'otherPassword',
]);

Update a website

\Umami\Umami::updateWebsites('example-site-id',[
    'name'=>'user name',
]);

Delete a website

\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

\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

\Umami\Umami::event_fields('example-site-id', [
    'start_at'=>today()->subDays(7),
    'end_at'=>now(),
]);

Users

Get all users

\Umami\Umami::users();

Create a user

\Umami\Umami::createUser('username','password');

Update a user

\Umami\Umami::updateUser(1,[
    'username'=>'username',
    'password'=>'password',
]);

Delete a user

\Umami\Umami::deleteUser(2);

More details

Please check out Umami website for more information.

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

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