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