PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 9.1.3
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v9.1.3
9.1.3 9.1.2 9.1.1 9.1.0 9.0.3 9.0.2 9.0.1 9.0.0 8.5.79 8.5.78 8.5.77 8.5.76 8.5.75 8.5.74 8.5.73 8.5.72 8.5.71 8.5.70 8.5.69 8.5.68 8.5.35 8.5.36 8.5.37 8.5.38 8.5.39 All 222 releases
wpvr / vendor / linno / telemetry / src / Drivers / PostHogDriver.php

PostHogDriver.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 9.1.3, at vendor/linno/telemetry/src/Drivers/PostHogDriver.php

53 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace LinnoSDK\Telemetry\Drivers;
4
5 use LinnoSDK\Telemetry\Helpers\Utils;
6 use PostHog\PostHog;
7
8 class PostHogDriver implements DriverInterface
9 {
10 protected $host;
11 protected $apiKey;
12 protected $lastError;
13
14 public function __construct(string $host)
15 {
16 $this->host = $host;
17 }
18
19 public function send(string $event, array $properties): bool
20 {
21 try {
22 PostHog::init($this->apiKey, ['host' => $this->host]);
23
24 $identify = $properties['__identify'] ?? [];
25 unset($properties['__identify']);
26
27 PostHog::capture([
28 'distinctId' => Utils::getUniqueSiteId(),
29 'event' => $event,
30 'properties' => $properties,
31 '$set' => $identify,
32 ]);
33
34 PostHog::flush();
35
36 return true;
37 } catch (\Exception $e) {
38 $this->lastError = $e->getMessage();
39 return false;
40 }
41 }
42
43 public function setApiKey(string $apiKey): void
44 {
45 $this->apiKey = $apiKey;
46 }
47
48 public function getLastError(): ?string
49 {
50 return $this->lastError;
51 }
52 }
53