|
3 | 3 | namespace AlexWestergaard\PhpGa4\Helper; |
4 | 4 |
|
5 | 5 | use AlexWestergaard\PhpGa4\Facade\Type\Event; |
| 6 | +use AlexWestergaard\PhpGa4\Facade\Type\DefaultEventParams; |
6 | 7 | use AlexWestergaard\PhpGa4\Exception\Ga4EventException; |
7 | 8 |
|
8 | 9 | abstract class AbstractEvent extends AbstractIO implements Event |
9 | 10 | { |
| 11 | + protected null|string $language; |
| 12 | + protected null|string $page_location; |
| 13 | + protected null|string $page_referrer; |
| 14 | + protected null|string $page_title; |
| 15 | + protected null|string $screen_resolution; |
| 16 | + |
| 17 | + public function setLanguage(string $lang) |
| 18 | + { |
| 19 | + $this->language = $lang; |
| 20 | + return $this; |
| 21 | + } |
| 22 | + |
| 23 | + public function setPageLocation(string $url) |
| 24 | + { |
| 25 | + $this->page_location = $url; |
| 26 | + return $this; |
| 27 | + } |
| 28 | + |
| 29 | + public function setPageReferrer(string $url) |
| 30 | + { |
| 31 | + $this->page_referrer = $url; |
| 32 | + return $this; |
| 33 | + } |
| 34 | + |
| 35 | + public function setPageTitle(string $title) |
| 36 | + { |
| 37 | + $this->page_title = $title; |
| 38 | + return $this; |
| 39 | + } |
| 40 | + |
| 41 | + public function setScreenResolution(string $wxh) |
| 42 | + { |
| 43 | + $this->screen_resolution = $wxh; |
| 44 | + return $this; |
| 45 | + } |
| 46 | + |
| 47 | + public function setEventPage(DefaultEventParams $page) |
| 48 | + { |
| 49 | + $args = $page->toArray(); |
| 50 | + |
| 51 | + $this->language = $args['language'] ?? null; |
| 52 | + $this->page_location = $args['page_location'] ?? null; |
| 53 | + $this->page_referrer = $args['page_referrer'] ?? null; |
| 54 | + $this->page_title = $args['page_title'] ?? null; |
| 55 | + $this->screen_resolution = $args['screen_resolution'] ?? null; |
| 56 | + |
| 57 | + return $this; |
| 58 | + } |
| 59 | + |
10 | 60 | public function toArray(): array |
11 | 61 | { |
12 | 62 | $return = []; |
@@ -34,6 +84,21 @@ public function toArray(): array |
34 | 84 | return $return; |
35 | 85 | } |
36 | 86 |
|
| 87 | + public function getAllParams(): array |
| 88 | + { |
| 89 | + return array_unique(array_merge( |
| 90 | + [ |
| 91 | + 'language', |
| 92 | + 'page_location', |
| 93 | + 'page_referrer', |
| 94 | + 'page_title', |
| 95 | + 'screen_resolution', |
| 96 | + ], |
| 97 | + $this->getParams(), |
| 98 | + $this->getRequiredParams() |
| 99 | + )); |
| 100 | + } |
| 101 | + |
37 | 102 | public static function new(): static |
38 | 103 | { |
39 | 104 | return new static(); |
|
0 commit comments