Skip to content
This repository was archived by the owner on Dec 18, 2025. It is now read-only.

immera/analytics-laravel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Interface to access Analytics API

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.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages