Giter Site home page Giter Site logo

laravel-umami's Introduction

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 (startAt,endAt)

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',[
    'startAt'=>today()->subDays(7),
    'endAt'=>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', [
    'startAt'=>today()->subDays(7),
    'endAt'=>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', [
    'startAt'=>today()->subDays(7),
    'endAt'=>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.

laravel-umami's People

Contributors

atmonshi avatar dependabot[bot] avatar github-actions[bot] avatar marcfowler avatar stylecibot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

laravel-umami's Issues

Error composer require

Hey, I am trying to install this package but getting this error:

Problem 1
- Root composer.json requires still-code/laravel-umami ^4.0 -> satisfiable by still-code/laravel-umami[4.0.0].
- still-code/laravel-umami 4.0.0 requires illuminate/support ^9.0 -> found illuminate/support[v9.0.0, ..., v9.52.5] but these were not loaded, likely because it conflicts with another require.

You can also try re-running composer require with an explicit version constraint, e.g. "composer require still-code/laravel-umami:*" to figure out if any version is installable, or "c

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.