Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
gacounter.php
1
<?php
2
namespace
Bitrix\Landing\Hook\Page
;
3
4
use \Bitrix\Landing\Field;
5
use \Bitrix\Landing\Manager;
6
use \Bitrix\Main\Localization\Loc;
7
8
Loc::loadMessages
(__FILE__);
9
10
class
GaCounter
extends
\Bitrix\Landing\Hook\Page
11
{
16
protected
function
getMap
()
17
{
18
$helpUrl = \Bitrix\Landing\Help::getHelpUrl(
'GACOUNTER'
);
19
return
array(
20
'USE'
=>
new
Field
\
Checkbox
(
'USE'
, array(
21
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_GACOUNTER_USE'
)
22
)),
23
'COUNTER'
=>
new
Field
\
Text
(
'COUNTER'
, array(
24
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_GACOUNTER_COUNTER'
),
25
'placeholder'
=>
Loc::getMessage
(
'LANDING_HOOK_GACOUNTER_PLACEHOLDER_1'
)
26
)),
27
'COUNTER_GA4'
=>
new
Field
\
Text
(
'COUNTER_GA4'
, array(
28
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_GACOUNTER_COUNTER'
),
29
'placeholder'
=>
Loc::getMessage
(
'LANDING_HOOK_GACOUNTER_PLACEHOLDER_2'
),
30
'help'
=> $helpUrl
31
?
'<a href="'
. $helpUrl .
'" target="_blank">'
.
32
Loc::getMessage
(
'LANDING_HOOK_DETAIL_HELP'
) .
33
'</a>'
34
:
''
35
)),
36
'SEND_CLICK'
=>
new
Field\Checkbox
(
'SEND_CLICK'
, array(
37
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_GACOUNTER_SEND_CLICK'
)
38
)),
39
'CLICK_TYPE'
=>
new
Field\Select
(
'CLICK_TYPE'
, array(
40
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_GACOUNTER_CLICK_TYPE'
),
41
'options'
=> [
42
'href'
=>
Loc::getMessage
(
'LANDING_HOOK_GACOUNTER_CLICK_TYPE_HREF'
),
43
'text'
=>
Loc::getMessage
(
'LANDING_HOOK_GACOUNTER_CLICK_TYPE_TEXT'
),
44
]
45
)),
46
'SEND_SHOW'
=>
new
Field\Checkbox
(
'SEND_SHOW'
, array(
47
'title'
=>
Loc::getMessage
(
'LANDING_HOOK_GACOUNTER_SEND_SHOW'
),
48
))
49
);
50
}
51
56
public
function
isFree
()
57
{
58
return
false
;
59
}
60
65
public
function
isLocked
()
66
{
67
return
!\Bitrix\Landing\Restriction\Manager::isAllowed(
68
'limit_sites_google_analytics'
69
);
70
}
71
76
public
function
enabled
()
77
{
78
if
($this->
isLocked
())
79
{
80
return
false
;
81
}
82
83
if
($this->
issetCustomExec
())
84
{
85
return
true
;
86
}
87
88
return
$this->fields[
'USE'
]->getValue() ==
'Y'
;
89
}
90
95
public
function
enabledInEditMode
()
96
{
97
return
false
;
98
}
99
104
public
function
exec
()
105
{
106
if
($this->
execCustom
())
107
{
108
return
;
109
}
110
111
if
($this->fields[
'USE'
]->getValue() !=
'Y'
)
112
{
113
return
;
114
}
115
116
//Universal Analytics
117
$this->
setCounter
($this->fields[
'COUNTER'
]);
118
//Google Analytics 4
119
$this->
setCounter
($this->fields[
'COUNTER_GA4'
]);
120
121
// send analytics
122
$sendData = [];
123
if
($this->fields[
'SEND_CLICK'
]->getValue() ==
'Y'
)
124
{
125
$sendData[] =
'click'
;
126
}
127
if
($this->fields[
'SEND_SHOW'
]->getValue() ==
'Y'
)
128
{
129
$sendData[] =
'show'
;
130
}
131
if
(!empty($sendData))
132
{
133
\Bitrix\Landing\Manager::setPageView(
134
'BodyTag'
,
135
' data-event-tracker=\''
. json_encode($sendData) .
'\''
136
);
137
$clickType = $this->fields[
'CLICK_TYPE'
]->getValue();
138
if
(!$clickType)
139
{
140
$clickType =
'text'
;
141
}
142
if
($clickType)
143
{
144
\Bitrix\Landing\Manager::setPageView(
145
'BodyTag'
,
146
' data-event-tracker-label-from="'
. \htmlspecialcharsbx($clickType) .
'"'
147
);
148
}
149
}
150
}
151
157
public
static
function
setCounter
(
string
$counter): void
158
{
159
$counter = \htmlspecialcharsbx(trim($counter));
160
$counter = \CUtil::jsEscape($counter);
161
162
if
(!$counter)
163
{
164
return
;
165
}
166
167
Manager::setPageView
(
168
'AfterHeadOpen'
,
169
'<script async
170
src="https://www.googletagmanager.com/gtag/js?id='
. $counter .
'"
171
data-skip-moving="true"
172
></script>'
173
);
174
Cookies::addCookieScript
(
175
'ga'
,
176
'window.dataLayer = window.dataLayer || [];
177
function gtag(){dataLayer.push(arguments)};
178
gtag("js", new Date());
179
gtag("config", "'
. $counter .
'");'
180
);
181
}
182
}
Bitrix\Landing\Field\Checkbox
Definition
checkbox.php:5
Bitrix\Landing\Field\Select
Definition
select.php:9
Bitrix\Landing\Field\Text
Definition
text.php:5
Bitrix\Landing\Field
Definition
field.php:5
Bitrix\Landing\Hook\Page\Cookies\addCookieScript
static addCookieScript(string $cookieCode, string $functionBody)
Definition
cookies.php:167
Bitrix\Landing\Hook\Page\GaCounter
Definition
gacounter.php:11
Bitrix\Landing\Hook\Page\GaCounter\isLocked
isLocked()
Definition
gacounter.php:65
Bitrix\Landing\Hook\Page\GaCounter\setCounter
static setCounter(string $counter)
Definition
gacounter.php:157
Bitrix\Landing\Hook\Page\GaCounter\getMap
getMap()
Definition
gacounter.php:16
Bitrix\Landing\Hook\Page\GaCounter\enabledInEditMode
enabledInEditMode()
Definition
gacounter.php:95
Bitrix\Landing\Hook\Page\GaCounter\enabled
enabled()
Definition
gacounter.php:76
Bitrix\Landing\Hook\Page\GaCounter\exec
exec()
Definition
gacounter.php:104
Bitrix\Landing\Hook\Page\GaCounter\isFree
isFree()
Definition
gacounter.php:56
Bitrix\Landing\Hook\Page
Definition
page.php:7
Bitrix\Landing\Hook\Page\issetCustomExec
issetCustomExec()
Definition
page.php:253
Bitrix\Landing\Hook\Page\execCustom
execCustom()
Definition
page.php:262
Bitrix\Landing\Manager\setPageView
static setPageView(string $marker, string $content, bool $skipTrim=false)
Definition
manager.php:465
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Landing\Hook\Page
Definition
b24button.php:2
modules
landing
lib
hook
page
gacounter.php
Создано системой
1.10.0