PluginProbe ʕ •ᴥ•ʔ
Transferito: WP Migration / 12.0.0
Transferito: WP Migration v12.0.0
trunk 11.4.0 12.0.0 13.1.0 14.0.0 14.0.11 14.0.7 14.1.0 14.1.1 14.1.2 14.1.3 14.1.4
transferito / src / Models / Settings / Telemetry.php
transferito / src / Models / Settings Last commit date
Setup.php 1 year ago Telemetry.php 1 year ago
Telemetry.php
60 lines
1 <?php
2
3 namespace Transferito\Models\Settings;
4
5 use Transferito\Models\Core\Api as TransferitoAPI;
6
7 class Telemetry
8 {
9 private $api;
10
11 public function __construct()
12 {
13 if (current_user_can('activate_plugins')) {
14 $this->api = new TransferitoAPI();
15 }
16 }
17
18 private function getUUID()
19 {
20 $uuid = get_transient('transferito_telemetry_uuid');
21
22 if (!$uuid) {
23 $userId = $this->createUUID();
24 set_transient('transferito_telemetry_uuid', $userId);
25 } else {
26 $userId = $uuid;
27 }
28
29 return $userId;
30 }
31
32 private function createUUID()
33 {
34 $ip = $_SERVER['REMOTE_ADDR'];
35 $siteUrl = site_url();
36
37 return hash('md5', "{$ip}_{$siteUrl}");
38 }
39
40 private function getUserProperties()
41 {
42 $userStatus = get_transient('transferito_user_status');
43 return [
44 'Cohort' => !$userStatus ? 'FREE' : $userStatus
45 ];
46 }
47
48 public function pushEvent($event, array $eventProperties)
49 {
50 return $this->api->pushTelemetry([
51 'userId' => $this->getUUID(),
52 'event' => $event,
53 'eventProperties' => $eventProperties,
54 'userProperties' => $this->getUserProperties()
55 ]);
56 }
57
58
59 }
60