1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
Metrika.php
См. документацию.
1
<?php
2
declare(strict_types=1);
3
4
namespace
Bitrix\Landing\Metrika;
5
6
use Bitrix\Main\Analytics\AnalyticsEvent;
7
use Bitrix\Main\Web\Json;
8
use Bitrix\Main\Web\Uri;
9
10
class
Metrika
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
$type
Определения
options.php:106
Bitrix\Landing\Metrika\Metrika
Определения
Metrika.php:11
Bitrix\Landing\Metrika\Metrika\__construct
__construct(Categories $category, Events $event, ?Tools $tool=null)
Определения
Metrika.php:17
Bitrix\Landing\Metrika\Metrika\send
send()
Определения
Metrika.php:114
Bitrix\Landing\Metrika\Metrika\setStatus
setStatus(?Statuses $status)
Определения
Metrika.php:41
Bitrix\Landing\Metrika\Metrika\setSubSection
setSubSection(?string $subSection)
Определения
Metrika.php:63
Bitrix\Landing\Metrika\Metrika\setType
setType(?Types $type)
Определения
Metrika.php:30
Bitrix\Landing\Metrika\Metrika\getSendingScript
getSendingScript(bool $addTag=false)
Определения
Metrika.php:119
Bitrix\Landing\Metrika\Metrika\setParam
setParam(int $position, string $param, string $value)
Определения
Metrika.php:85
Bitrix\Landing\Metrika\Metrika\setError
setError(string $error, ?Statuses $status=null)
Определения
Metrika.php:105
Bitrix\Landing\Metrika\Metrika\setElement
setElement(?string $element)
Определения
Metrika.php:74
Bitrix\Landing\Metrika\Metrika\setSection
setSection(?Sections $section)
Определения
Metrika.php:52
Bitrix\Main\Analytics\AnalyticsEvent
Определения
analyticsevent.php:16
Bitrix\Main\Web\Uri
Определения
uri.php:17
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$uri
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения
urlrewrite.php:61
$status
$status
Определения
session.php:10
Bitrix\Landing\Metrika\Sections
Sections
Определения
Sections.php:7
Bitrix\Landing\Metrika\Statuses
Statuses
Определения
Statuses.php:7
Bitrix\Landing\Metrika\Tools
Tools
Определения
Tools.php:7
Bitrix\Landing\Metrika\landing
@ landing
Определения
Tools.php:9
Bitrix\Landing\Metrika\Events
Events
Определения
Events.php:7
Bitrix\Landing\Metrika\Categories
Categories
Определения
Categories.php:9
Bitrix\Landing\Metrika\Types
Types
Определения
Types.php:7
$error
$error
Определения
subscription_card_product.php:20
$url
$url
Определения
iframe.php:7
bitrix
modules
landing
lib
Metrika
Metrika.php
Создано системой
1.14.0