PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.10.9
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.10.9
3.13.4 3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 All 262 releases
wpfunnels / vendor / linno / telemetry / src / Drivers / PostHogDriver.php

PostHogDriver.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.10.9, 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