Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
gtm.php
1<?php
3
4use \Bitrix\Landing\Manager;
5use \Bitrix\Landing\Field;
6use \Bitrix\Main\Localization\Loc;
7
8Loc::loadMessages(__FILE__);
9
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 {
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}
static addCookieScript(string $cookieCode, string $functionBody)
Definition cookies.php:167
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29