Remove Google Analytics #728 (#745)

* Remove Google Analytics #728

* Remove config file

* Don't set the vacentral url
This commit is contained in:
Nabeel S 2020-06-04 07:36:55 -07:00 committed by GitHub
parent c1408cb8fe
commit 3d211535f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 1051 additions and 366 deletions

View File

@ -1,12 +0,0 @@
<?php
namespace App\Models\Enums;
use App\Contracts\Enum;
class AnalyticsDimensions extends Enum
{
public const PHP_VERSION = 1;
public const DATABASE_VERSION = 2;
public const PHPVMS_VERSION = 3;
}

View File

@ -1,14 +0,0 @@
<?php
namespace App\Models\Enums;
use App\Contracts\Enum;
/**
* Metrics IDs used in Google Analytics
*/
class AnalyticsMetrics extends Enum
{
// Track the lookup time for airports from vaCentral
public const AIRPORT_LOOKUP_TIME = 1;
}

View File

@ -32,7 +32,6 @@ class BindServiceProviders extends ServiceProvider
IVaCentral::class,
function ($app) {
$client = new VaCentral();
$client->setVaCentralUrl(config('vacentral.api_url'));
// Set API if exists
if (filled(config('vacentral.api_key'))) {

View File

@ -21,13 +21,14 @@ class VaCentralLookup extends AirportLookup
*
* @param string $icao
*
* @return array
* @return mixed
*/
public function getAirport($icao)
{
try {
$airport = $this->client->getAirport($icao);
$airport->location = $airport->city;
return $airport;
} catch (HttpException $e) {
Log::error($e);

View File

@ -3,25 +3,15 @@
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;
use PDO;
use VaCentral\Models\Stat;
use VaCentral\VaCentral;
class AnalyticsService extends Service
{
/**
* 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
*/
@ -31,31 +21,39 @@ class AnalyticsService extends Service
return;
}
// Generate a random client ID
$gamp = $this->getGAMPInstance();
$gamp->setDocumentPath('/install');
// Send the PHP version
$gamp->setCustomDimension(PHP_VERSION, AnalyticsDimensions::PHPVMS_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
);
$pdo = DB::connection()->getPdo();
$props = [
'php' => PHP_VERSION,
'db' => strtolower($pdo->getAttribute(PDO::ATTR_SERVER_VERSION)),
'version' => $versionSvc->getCurrentVersion(false),
];
// Send that an install was done
try {
$gamp->sendPageview();
$stat = Stat::new('event', 'install', $props);
$client = new VaCentral();
$client->postStat($stat);
} catch (Exception $e) {
Log::error($e->getMessage());
}
}
public function sendUpdate()
{
if (setting('general.telemetry') === false) {
return;
}
$versionSvc = app(VersionService::class);
$props = [
'version' => $versionSvc->getCurrentVersion(false),
];
try {
$stat = Stat::new('event', 'update', $props);
$client = new VaCentral();
$client->postStat($stat);
} catch (Exception $e) {
Log::error($e->getMessage());
}

View File

@ -53,7 +53,6 @@
"spatie/laravel-backup": "~6.9.0",
"spatie/valuestore": "~1.2.3",
"symfony/polyfill-iconv": "~1.17.0",
"theiconic/php-ga-measurement-protocol": "2.7.*",
"tivie/php-os-detector": "~1.1.0",
"vlucas/phpdotenv": "v4.0",
"webpatser/laravel-uuid": "~3.0",

1299
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +0,0 @@
<?php
return [
'tracking_id' => 'UA-100567975-4',
'protocol_version' => 1,
'is_ssl' => true,
'is_disabled' => false,
'anonymize_ip' => true,
'async_requests' => true,
];

View File

@ -4,6 +4,7 @@ namespace Modules\Updater\Http\Controllers;
use App\Contracts\Controller;
use App\Repositories\KvpRepository;
use App\Services\AnalyticsService;
use App\Services\Installer\InstallerService;
use App\Services\Installer\MigrationService;
use App\Services\Installer\SeederService;
@ -14,6 +15,7 @@ use Illuminate\Support\Facades\Log;
class UpdateController extends Controller
{
private $analyticsSvc;
private $installerSvc;
private $kvpRepo;
private $migrationSvc;
@ -21,19 +23,22 @@ class UpdateController extends Controller
private $updateManager;
/**
* @param AnalyticsService $analyticsSvc
* @param InstallerService $installerSvc
* @param KvpRepository $kvpRepo
* @param MigrationService $migrationSvc
* @param SeederService $seederSvc
* @param KvpRepository $kvpRepo
* @param UpdaterManager $updateManager
*/
public function __construct(
AnalyticsService $analyticsSvc,
InstallerService $installerSvc,
KvpRepository $kvpRepo,
MigrationService $migrationSvc,
SeederService $seederSvc,
UpdaterManager $updateManager
) {
$this->analyticsSvc = $analyticsSvc;
$this->migrationSvc = $migrationSvc;
$this->seederSvc = $seederSvc;
$this->installerSvc = $installerSvc;
@ -137,6 +142,7 @@ class UpdateController extends Controller
$release = $this->updateManager->source('github')->fetch($version);
$this->updateManager->source('github')->update($release);
$this->analyticsSvc->sendUpdate();
Log::info('Update completed to '.$version.', redirecting');
return redirect('/update');

View File

@ -36,7 +36,8 @@ class ApiTest extends TestCase
$uri = '/api/user';
// Missing auth header
$this->get($uri)->assertStatus(401);
$res = $this->get($uri);
$res->assertStatus(401);
// Test invalid API key
$this->withHeaders(['Authorization' => 'invalidKey'])->get($uri)