Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
yacounter.php
1<?php
3
4use \Bitrix\Landing\Field;
5use \Bitrix\Main\Localization\Loc;
6use \Bitrix\Landing\Manager;
7
8Loc::loadMessages(__FILE__);
9
11{
16 protected function getMap()
17 {
18 $helpUrl = \Bitrix\Landing\Help::getHelpUrl('YACOUNTER');
19 return array(
20 'USE' => new Field\Checkbox('USE', array(
21 'title' => Loc::getMessage('LANDING_HOOK_YACOUNTER_USE')
22 )),
23 'COUNTER' => new Field\Text('COUNTER', array(
24 'title' => Loc::getMessage('LANDING_HOOK_YACOUNTER_COUNTER'),
25 'placeholder' => Loc::getMessage('LANDING_HOOK_YACOUNTER_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 if ($this->fields['USE']->getValue() != 'Y')
95 {
96 return;
97 }
98
99 $this->setCounter($this->fields['COUNTER']);
100 }
101
107 public static function setCounter(string $counter): void
108 {
109 $counter = \htmlspecialcharsbx(trim($counter));
110 $counter = \CUtil::jsEscape($counter);
111 if (!$counter)
112 {
113 return;
114 }
115
117 'ym',
118 '(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
119 m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
120 (window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
121 ym(\'' . $counter . '\', "init", {
122 id:\'' . $counter . '\',
123 clickmap:true,
124 trackLinks:true,
125 accurateTrackBounce:true,
126 webvisor:true,
127 trackHash:true
128 });'
129 );
130 Manager::setPageView(
131 'Noscript',
132 '<noscript>
133 <img src="https://mc.yandex.ru/watch/' . $counter . '" style="position:absolute; left:-9999px;" alt="" />
134 </noscript>'
135 );
136 }
137}
static addCookieScript(string $cookieCode, string $functionBody)
Definition cookies.php:167
static setCounter(string $counter)
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29