immera/analytics

Immera Laravel Analytics

0.1.1 2023-03-06 23:03 UTC

This package is auto-updated.

Last update: 2024-04-08 14:40:36 UTC


README

Latest Version on Packagist Total Downloads

This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.

Installation

You can install the package via composer:

composer require immera/analytics

After installing please setup your API key in the .env file

ANALYTICS_SERIAL_KEY=

Usage

Store data

Analytics::store([
    'action' => 'test',
    'project' => 'analytics',
    'price' => rand(0, 10000) / 100,
    'quantity' => rand(0, 8),
])

Fetch data

$result = Analytics::query()
    ->match(['action' => 'test'])
    ->project(['action' => 1, 'project' => 1])
    ->limit(1)
    ->fetchJson();

Count actions by hour

$result = Analytics::query()
    ->match([
        'action' => 'test',
        'created_at.year' => 2022,
    ])
    ->group([
        '_id' => [
            'year' => '$created_at.year',
            'month' => '$created_at.month',
            'day' => '$created_at.day',
            'hour' => '$created_at.hour',
        ],
        'count' => [
            '$sum' => 1,
        ],
    ])
    ->sort([
        '_id.year' => -1,
        '_id.month' => -1,
        '_id.day' => -1,
        '_id.hour' => -1,
    ])
    ->limit(100)
    ->fetchJson();

Get Total price and average quantity by month, order desc

$result = Analytics::query()
    ->match([
        'action' => 'test',
    ])
    ->group([
        '_id' => [
            'year' => '$created_at.year',
            'month' => '$created_at.month',
        ],
        'totalPrice' => [
            '$sum' => '$price',
        ],
        'averageQuantity' => [
            '$avg' => '$quantity',
        ],
    ])
    ->sort([
        '_id.year' => -1,
        '_id.month' => -1,
    ])
    ->limit(100)
    ->fetchJson();

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email antonioalmeida@immera.io instead of using the issue tracker.

Credits

License

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

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.