1. Go to this page and download the library: Download actengage/metrics library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
actengage / metrics example snippets
use Actengage\Metrics\Contracts\Result;
use Actengage\Metrics\Value;
use App\Models\User;
use Illuminate\Http\Request;
$metric = new class extends Value {
public function ranges(): array {
return [
'5' => '5 Days',
'10' => '10 Days',
'15' => '15 Days',
'P21D' => '21 Days',
'today' => 'Today',
'yesterday' => 'Yesterday',
'MTD' => 'Month To Date',
'QTD' => 'Quarter To Date',
'YTD' => 'Year To Date',
'ALL' => 'All Time'
];
}
public function calculate(Request $request): Result {
return $this
->title('Total Users')
->description('The total number of users.')
->timezone('EST')
->range('P21D')
->count(User::class)
->prefix('#')
->suffix('users');
}
};
$result = $metric->resolve(request()->merge([
'range' => 'MTD'
]));
use Actengage\Metrics\Contracts\Result;
use Actengage\Metrics\Trend;
use App\Models\User;
use Illuminate\Http\Request;
$metric = new class extends Trend {
public function calculate(Request $request): Result {
return $this
->title('User Registrations')
->description('User registrations trending by day.')
->twelveHourTime()
->range($request->range)
->count(User::class, Trend::BY_DAYS)
->prefix('#')
->suffix('users');
}
};
$result = $metric->resolve(request()->merge([
'range' => 30
]));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.