Server IP : 172.67.157.199 / Your IP : 3.140.198.225 [ Web Server : Apache System : Linux b70eb322-3aee-0c53-7c82-0db91281f2c6.secureserver.net 6.1.90-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 2 12:09:22 EDT 2024 x86_64 User : root ( 0) PHP Version : 8.0.30.2 Disable Function : NONE Domains : 0 Domains MySQL : ON | cURL : ON | WGET : ON | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/wp-content/mu-plugins/vendor/wptool/wp-admin-dash/src/adminDash/services/ |
Upload File : |
<?php namespace Wptool\adminDash\services; use Wptool\adminDash\clients\ga\GAClient; use Wptool\adminDash\constants\TrackingConstants; use Wptool\adminDash\services\tracking\ClickProcessor; use Wptool\adminDash\services\tracking\PageviewProcessor; use Wptool\adminDash\services\tracking\TrackingProcessor; class TrackingService { /** @var GAClient */ private $ga_client; /** * @param GAClient $ga_client */ public function __construct( $ga_client ) { $this->ga_client = $ga_client; } const TYPES = array( TrackingConstants::CLICK, TrackingConstants::PAGE_VIEW, ); const PROCESSORS = array( TrackingConstants::PAGE_VIEW => PageviewProcessor::class, TrackingConstants::CLICK => ClickProcessor::class, ); /** * Process load data and send it to GoogleAnalytics. * * @param $data * * @return bool * @throws \Exception */ public function process_load_data( $data ) { $type = $data['type']; $processor = $this->get_tracking_processor( $type ); if ( ! $processor instanceof TrackingProcessor ) { throw new \Exception( 'Tracking data cannot be processed.' ); } $tracking_request = $processor->process( $data ); return $this->ga_client->send( $tracking_request ); } /** * Fetch processor depending on event type. * * @param $type * * @return mixed * @throws \Exception */ private function get_tracking_processor( $type ) { if ( isset( self::PROCESSORS[ $type ] ) ) { $processor = self::PROCESSORS[ $type ]; return new $processor; } throw new \Exception( 'Tracking data cannot be processed. Processor not found.' ); } }