Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
gtm.php
1
<?php
2
namespace
Bitrix\Landing\Hook\Page
;
3
4
use \Bitrix\Landing\Manager;
5
use \Bitrix\Landing\Field;
6
use \Bitrix\Main\Localization\Loc;
7
8
Loc::loadMessages
(__FILE__);
9
10
class
GTM
extends
\Bitrix\Landing\Hook\Page
11
{
16
protected
function
getMap
()
17
{
18
$helpUrl = \Bitrix\Landing\Help::getHelpUrl(
'GTM'
);
19
return
array(
20
'USE'
=>
new
Field
\
Checkbox
(
'USE'
, array(
21
'title'
=>
'Google Tag Manager'
22
)),
23
'COUNTER'
=>
new
Field
\
Text
(
'COUNTER'
, array(
24
'title'
=>
'Google Tag Manager'
,
25
'placeholder'
=>
Loc::getMessage
(
'LANDING_HOOK_GTM_PLACEHOLDER'
),
26
'help'
=> $helpUrl
27
?
'<a href="'
. $helpUrl .
'" target="_blank">'
.
28
Loc::getMessage
(
'LANDING_HOOK_DETAIL_HELP'
) .
29
'</a>'
30
:
''
31
))
32
);
33
}
34
39
public
function
isFree
()
40
{
41
return
false
;
42
}
43
48
public
function
isLocked
()
49
{
50
return
!\Bitrix\Landing\Restriction\Manager::isAllowed(
51
'limit_sites_google_analytics'
52
);
53
}
54
59
public
function
enabled
()
60
{
61
if
($this->
isLocked
())
62
{
63
return
false
;
64
}
65
66
if
($this->
issetCustomExec
())
67
{
68
return
true
;
69
}
70
71
return
$this->fields[
'USE'
]->getValue() ==
'Y'
;
72
}
73
78
public
function
enabledInEditMode
()
79
{
80
return
false
;
81
}
82
87
public
function
exec
()
88
{
89
if
($this->
execCustom
())
90
{
91
return
;
92
}
93
94
$counter = \htmlspecialcharsbx(trim($this->fields[
'COUNTER'
]));
95
$counter = \CUtil::jsEscape($counter);
96
if
($counter)
97
{
98
Cookies::addCookieScript
(
99
'gtm'
,
100
'(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({\'gtm.start\':new Date().getTime(),event:\'gtm.js\'});
101
var f=d.getElementsByTagName(s)[0],
102
j=d.createElement(s),
103
dl=l!=\'dataLayer\'?\'&l=\'+l:\'\';
104
j.async=true;
105
j.src=\'https://www.googletagmanager.com/gtm.js?id=\'+i+dl;
106
f.parentNode.insertBefore(j,f);})(window,document,\'script\',\'dataLayer\',\''
. $counter .
'\'
);
'
107
);
108
Manager::setPageView(
109
'
Noscript
',
110
'
<noscript>
111
<iframe src=
"https://www.googletagmanager.com/ns.html?id=' . $counter . '"
height=
"0"
width=
"0"
style=
"display:none;visibility:hidden"
></iframe>
112
</noscript>
');
113
}
114
}
115
}
Bitrix\Landing\Field\Checkbox
Definition
checkbox.php:5
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\GTM
Definition
gtm.php:11
Bitrix\Landing\Hook\Page\GTM\isLocked
isLocked()
Definition
gtm.php:48
Bitrix\Landing\Hook\Page\GTM\getMap
getMap()
Definition
gtm.php:16
Bitrix\Landing\Hook\Page\GTM\enabledInEditMode
enabledInEditMode()
Definition
gtm.php:78
Bitrix\Landing\Hook\Page\GTM\enabled
enabled()
Definition
gtm.php:59
Bitrix\Landing\Hook\Page\GTM\exec
exec()
Definition
gtm.php:87
Bitrix\Landing\Hook\Page\GTM\isFree
isFree()
Definition
gtm.php:39
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\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
gtm.php
Создано системой
1.10.0