| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Core\Common\Modules\EventsManager; |
| 4 |
|
| 5 |
use ElementorDeps\Mixpanel; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly. |
| 9 |
} |
| 10 |
|
| 11 |
class Server_Events_Client { |
| 12 |
|
| 13 |
public static function track( string $event_name, array $properties = [] ): bool { |
| 14 |
// The SDK is bundled via php-scoper (see php-scoper/mixpanel-inc.php), so this is only |
| 15 |
// a defensive guard in case the prefixed dependency is ever missing from the build. |
| 16 |
if ( ! class_exists( Mixpanel::class ) ) { |
| 17 |
return false; |
| 18 |
} |
| 19 |
|
| 20 |
try { |
| 21 |
// The SDK's own instance getter is itself a singleton keyed by token - it returns the |
| 22 |
// existing instance or creates a new one if it doesn't exist yet. |
| 23 |
$client = Mixpanel::getInstance( ELEMENTOR_EDITOR_EVENTS_MIXPANEL_TOKEN, [ |
| 24 |
'host' => Module::get_mixpanel_api_host(), |
| 25 |
'consumer' => 'wp', |
| 26 |
'consumers' => [ |
| 27 |
'wp' => Wp_Http_Consumer::class, |
| 28 |
], |
| 29 |
] ); |
| 30 |
|
| 31 |
$client->track( $event_name, $properties ); |
| 32 |
|
| 33 |
return true; |
| 34 |
} catch ( \Throwable $e ) { |
| 35 |
return false; |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
|