immera / analytics
Immera Laravel Analytics
Installs: 3 718
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.1|^8.2
- illuminate/support: ^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ^8.0
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-10-08 15:40:59 UTC
README
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.