Move telemetry option into settings; checkbox in install refs #415 (#416)

This commit is contained in:
Nabeel S
2019-10-29 13:07:53 -04:00
committed by GitHub
parent a2ea9b29ba
commit ae68550448
7 changed files with 76 additions and 38 deletions

View File

@@ -26,6 +26,13 @@
options: ''
type: boolean
description: 'Include beta and other pre-release versions when checking for a new version'
- key: general.telemetry
name: 'Send telemetry to phpVMS'
group: general
value: true
options: ''
type: boolean
description: 'Send some data (php version, mysql version) to phpVMS. See AnalyticsSvc code for details'
- key: units.distance
name: 'Distance Units'
group: units

View File

@@ -4,6 +4,7 @@ namespace App\Services;
use App\Contracts\Service;
use App\Models\Enums\AnalyticsDimensions;
use Exception;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Irazasyed\LaravelGAMP\Facades\GAMP;
@@ -12,30 +13,50 @@ use PDO;
class AnalyticsService extends Service
{
/**
* Send out some stats about the install
* Create a GAMP instance with a random ID
*
* @return mixed
*/
private function getGAMPInstance()
{
return GAMP::setClientId(uniqid('', true));
}
/**
* Send out some stats about the install, like the PHP and DB versions
*/
public function sendInstall()
{
if (config('app.analytics') === false) {
if (setting('general.telemetry') === false) {
return;
}
// some analytics
$gamp = GAMP::setClientId(uniqid('', true));
// Generate a random client ID
$gamp = $this->getGAMPInstance();
$gamp->setDocumentPath('/install');
$gamp->setCustomDimension(PHP_VERSION, AnalyticsDimensions::PHP_VERSION);
// Send the PHP version
$gamp->setCustomDimension(PHP_VERSION, AnalyticsDimensions::PHPVMS_VERSION);
// figure out database version
// Figure out the database version
$pdo = DB::connection()->getPdo();
$gamp->setCustomDimension(
strtolower($pdo->getAttribute(PDO::ATTR_SERVER_VERSION)),
AnalyticsDimensions::DATABASE_VERSION
);
// Send the PHPVMS Version
$versionSvc = app(VersionService::class);
$gamp->setCustomDimension(
$versionSvc->getCurrentVersion(false),
AnalyticsDimensions::PHP_VERSION
);
// Send that an install was done
try {
$gamp->sendPageview();
} catch (\Exception $e) {
} catch (Exception $e) {
Log::error($e->getMessage());
}
}

View File

@@ -43,7 +43,7 @@ if (!function_exists('get_truth_state')) {
$state = strtolower($state);
}
return \in_array($state, $enabledStates, false);
return in_array($state, $enabledStates, false);
}
}
@@ -148,6 +148,18 @@ if (!function_exists('setting')) {
}
}
/*
* Shortcut for retrieving a setting value
*/
if (!function_exists('setting_save')) {
function setting_save($key, $value)
{
$settingRepo = app('setting');
$settingRepo->save($key, $value);
return $value;
}
}
/*
* Wrap the asset URL in the publicBaseUrl that's been
* set