47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace adrienpayet\analytics;
|
||
|
|
|
||
|
|
class Visit
|
||
|
|
{
|
||
|
|
public string $id;
|
||
|
|
public string $email;
|
||
|
|
public ?string $country;
|
||
|
|
public string $timestamp;
|
||
|
|
public string $sessionId;
|
||
|
|
public string $pageUrl;
|
||
|
|
public string $pageType;
|
||
|
|
public ?string $pageName;
|
||
|
|
|
||
|
|
public function __construct(array $data)
|
||
|
|
{
|
||
|
|
$this->id = $data['id'] ?? uniqid('visit_', true);
|
||
|
|
$this->email = $data['email'];
|
||
|
|
$this->country = $data['country'] ?? null;
|
||
|
|
$this->timestamp = $data['timestamp'] ?? date('Y-m-d H:i:s');
|
||
|
|
$this->sessionId = $data['sessionId'];
|
||
|
|
$this->pageUrl = $data['pageUrl'];
|
||
|
|
$this->pageType = $data['pageType'];
|
||
|
|
$this->pageName = $data['pageName'] ?? null;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function toArray(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'id' => $this->id,
|
||
|
|
'email' => $this->email,
|
||
|
|
'country' => $this->country,
|
||
|
|
'timestamp' => $this->timestamp,
|
||
|
|
'sessionId' => $this->sessionId,
|
||
|
|
'pageUrl' => $this->pageUrl,
|
||
|
|
'pageType' => $this->pageType,
|
||
|
|
'pageName' => $this->pageName,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function fromArray(array $data): self
|
||
|
|
{
|
||
|
|
return new self($data);
|
||
|
|
}
|
||
|
|
}
|