setName( $name ); $this->setTime( time() ); $this->setId( self::generateId() ); $this->setSourceUrl( $this->getCurrentUrl() ); if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) { $this->setReferrer( sanitize_text_field( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) ); } $this->userData = new UserDataDTO(); } /** * @return mixed */ public function getContentType() { return $this->contentType; } /** * @param mixed $contentType */ public function setContentType( $contentType ) { $this->contentType = $contentType; return $this; } /** * @return mixed */ public function getDeliveryCategory() { return $this->deliveryCategory; } /** * @param mixed $deliveryCategory */ public function setDeliveryCategory( $deliveryCategory ) { $this->deliveryCategory = $deliveryCategory; return $this; } public function getId() { return $this->id; } public function setId( $id ) { $this->id = $id; return $this; } public function getPixels() { return $this->pixels; } public function setPixels( $pixels ) { $this->pixels = $pixels; return $this; } private static function generateId() { $id = microtime( false ); $id = str_replace( ' ', '', $id ); $id = str_replace( '.', '', $id ); return $id; } public function getName() { return $this->name; } public function getValue() { return $this->value; } /** * @param mixed $order_id */ public function setOrderId( $order_id ) { $this->order_id = $order_id; return $this; } private function getCurrentUrl() { if ( empty( $_SERVER['SERVER_NAME'] ) || empty( $_SERVER['REQUEST_URI'] ) ) { return ''; } return 'https://' . sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ); } /** * @param string $name */ public function setName( $name ) { $this->name = $name; return $this; } /** * @param string $time */ public function setTime( $time ) { $this->time = $time; return $this; } /** * @param string $sourceUrl */ public function setSourceUrl( $sourceUrl ) { $this->sourceUrl = $sourceUrl; return $this; } public function setCurrency( $currency ) { $this->currency = $currency; return $this; } public function setContentIds( $contentIds ) { $this->contentIds = $contentIds; return $this; } public function setValue( $value ) { $this->value = $value; return $this; } public function setContents( $contents ) { $this->contents = $contents; return $this; } /** * @param mixed $referrer */ public function setReferrer( $referrer ) { $this->referrer = $referrer; return $this; } public function getCurrency() { return $this->currency; } public function getOrderId() { return $this->order_id; } public function getContentIds() { return $this->contentIds; } public function __toArray() { return array( 'event_id' => $this->id, 'event_name' => $this->name, 'event_time' => $this->time, 'event_source_url' => $this->sourceUrl, 'referrer' => $this->referrer, 'action_source' => 'website', 'custom_data' => array( 'value' => $this->value, 'currency' => $this->currency, 'content_ids' => $this->contentIds, 'contents' => $this->contents, 'order_id' => $this->order_id, 'content_type' => $this->contentType, 'delivery_category' => $this->deliveryCategory, ), 'user_data' => $this->userData->__toArray(), ); } } }