Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
promatik committed Mar 6, 2023
2 parents 149b64a + 19d8579 commit 717d95a
Showing 1 changed file with 58 additions and 4 deletions.
62 changes: 58 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,77 @@ ANALYTICS_SERIAL_KEY=

## Usage

#### Store data
```php
// Store data
Analytics::store([
'action' => 'test',
'project' => 'boilerplate',
'project' => 'analytics',
'price' => rand(0, 10000) / 100,
'quantity' => rand(0, 8),
])
```

#### Fetch data
```php
// Fetch data
$result = Analytics::query()
->match(['action' => 'test'])
->project(['action' => 1, 'project' => 1])
->limit(1)
->fetchJson();
```

dd($result);
#### Count actions by hour
```php
$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
```php
$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
Expand Down

0 comments on commit 717d95a

Please sign in to comment.