1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Metrika.php
См. документацию.
1<?php
2declare(strict_types=1);
3
4namespace Bitrix\Landing\Metrika;
5
6use Bitrix\Main\Analytics\AnalyticsEvent;
7use Bitrix\Main\Web\Json;
8use Bitrix\Main\Web\Uri;
9
11{
12 private const ERROR_PARAM = 'errorType';
13
14 private array $data = [];
15 private AnalyticsEvent $event;
16
17 public function __construct(Categories $category, Events $event, ?Tools $tool = null)
18 {
19 $toolValue = isset($tool) ? $tool->value : Tools::landing->value;
20
21 $this->event = new AnalyticsEvent($event->value, $toolValue, $category->value);
22 $this->event->setStatus(Statuses::Success->value);
23
24 $this->data['tool'] = $toolValue;
25 $this->data['status'] = Statuses::Success->value;
26 $this->data['category'] = $category->value;
27 $this->data['event'] = $event->value;
28 }
29
30 public function setType(?Types $type): self
31 {
32 if ($type)
33 {
34 $this->event->setType($type->value);
35 $this->data['type'] = $type->value;
36 }
37
38 return $this;
39 }
40
41 public function setStatus(?Statuses $status): self
42 {
43 if (isset($status))
44 {
45 $this->event->setStatus($status->value);
46 $this->data['status'] = $status->value;
47 }
48
49 return $this;
50 }
51
52 public function setSection(?Sections $section): self
53 {
54 if ($section)
55 {
56 $this->event->setSection($section->value);
57 $this->data['c_section'] = $section->value;
58 }
59
60 return $this;
61 }
62
63 public function setSubSection(?string $subSection): self
64 {
65 if (isset($subSection))
66 {
67 $this->event->setSubSection($subSection);
68 $this->data['c_sub_section'] = $subSection;
69 }
70
71 return $this;
72 }
73
74 public function setElement(?string $element): self
75 {
76 if (isset($element))
77 {
78 $this->event->setElement($element);
79 $this->data['c_element'] = $element;
80 }
81
82 return $this;
83 }
84
85 public function setParam(int $position, string $param, string $value): self
86 {
87 if ($position <= 0 || $position > 5)
88 {
89 return $this;
90 }
91
92 $param = str_replace(['_', ' '], '-', $param);
93 $value = str_replace(['_', ' '], '-', $value);
94 $this->data['p' . $position] = [$param, $value];
95 $this->event->{'setP' . $position}("{$param}_{$value}");
96
97 return $this;
98 }
99
105 public function setError(string $error, ?Statuses $status = null): self
106 {
107 return
108 $this
109 ->setStatus($status ?? Statuses::Error)
110 ->setParam(5, self::ERROR_PARAM, $error)
111 ;
112 }
113
114 public function send(): void
115 {
116 $this->event->send();
117 }
118
119 public function getSendingScript(bool $addTag = false): string
120 {
121 $data = Json::encode($this->data);
122
123 $script = <<<script
124 if (typeof BX.Landing.Metrika !== 'undefined')
125 {
126 const metrika = new BX.Landing.Metrika();
127 metrika.sendData($data);
128 }
129 script;
130
131 return $addTag
132 ? "<script>$script</script>"
133 : $script;
134 }
135
141 public function parametrizeUri(string $url): string
142 {
143 $uri = new Uri($url);
144 $add = [];
145 foreach ($this->data as $param => $value)
146 {
147 if ($value !== null)
148 {
149 $add["st[{$param}]"] = $value;
150 }
151 }
152 $uri->addParams($add);
153
154 return $uri->getUri();
155 }
156}
$type
Определения options.php:106
__construct(Categories $category, Events $event, ?Tools $tool=null)
Определения Metrika.php:17
setStatus(?Statuses $status)
Определения Metrika.php:41
setSubSection(?string $subSection)
Определения Metrika.php:63
setType(?Types $type)
Определения Metrika.php:30
getSendingScript(bool $addTag=false)
Определения Metrika.php:119
setParam(int $position, string $param, string $value)
Определения Metrika.php:85
setError(string $error, ?Statuses $status=null)
Определения Metrika.php:105
setElement(?string $element)
Определения Metrika.php:74
setSection(?Sections $section)
Определения Metrika.php:52
Определения uri.php:17
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения urlrewrite.php:61
$status
Определения session.php:10
Sections
Определения Sections.php:7
Statuses
Определения Statuses.php:7
Tools
Определения Tools.php:7
@ landing
Определения Tools.php:9
Events
Определения Events.php:7
Categories
Определения Categories.php:9
Types
Определения Types.php:7
$error
Определения subscription_card_product.php:20
$url
Определения iframe.php:7