Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
counter.php
1
<?php
2
namespace
Bitrix\Main\Analytics
;
3
4
use
Bitrix\Main\Config\Configuration
;
5
use
Bitrix\Main\Application
;
6
use
Bitrix\Main\Context
;
7
use Bitrix\Main\Page\Asset;
8
use
Bitrix\Main\Page\AssetLocation
;
9
use
Bitrix\Main\Text\JsExpression
;
10
11
class
Counter
12
{
13
protected
static
$data
= array();
14
protected
static
$enabled
=
true
;
15
protected
static
$bufferRestarted
=
false
;
16
17
public
static
function
enable
()
18
{
19
static::$enabled =
true
;
20
}
21
22
public
static
function
disable
()
23
{
24
static::$enabled =
false
;
25
}
26
27
public
static
function
getInjectedJs
($stripTags =
false
)
28
{
29
$accountId = static::getAccountId();
30
$params = static::injectDataParams();
31
32
$host =
Context::getCurrent
()->getServer()->getHttpHost();
33
$host = preg_replace(
"/:(80|443)$/"
,
""
, $host);
34
$host = \CUtil::JSEscape($host);
35
36
$js = <<<JS
37
var _ba = _ba || []; _ba.push([
"aid"
,
"{$accountId}"
]); _ba.push([
"host"
,
"{$host}"
]); {$params}
38
(
function
() {
39
var ba = document.createElement(
"script"
); ba.type =
"text/javascript"
; ba.async =
true
;
40
ba.src = (document.location.protocol ==
"https:"
?
"https://"
:
"http://"
) +
"bitrix.info/ba.js"
;
41
var s = document.getElementsByTagName(
"script"
)[0];
42
s.parentNode.insertBefore(ba, s);
43
})();
44
JS;
45
46
$js = str_replace(array(
"\n"
,
"\t"
),
""
, $js);
47
if
($stripTags ===
false
)
48
{
49
return
"<script type=\"text/javascript\">"
.$js.
"</script>"
;
50
}
51
else
52
{
53
return
$js;
54
}
55
}
56
57
public
static
function
injectIntoPage
()
58
{
59
Asset::getInstance()->addString(static::getInjectedJs(),
false
, AssetLocation::AFTER_JS);
60
}
61
62
public
static
function
getAccountId
()
63
{
64
$license =
Application::getInstance
()->getLicense();
65
if
(!$license->isDemoKey())
66
{
67
return
$license->getPublicHashKey();
68
}
69
else
70
{
71
return
""
;
72
}
73
}
74
75
public
static
function
getPrivateKey
()
76
{
77
$license =
Application::getInstance
()->getLicense();
78
if
(!$license->isDemoKey())
79
{
80
return
$license->getHashLicenseKey();
81
}
82
else
83
{
84
return
""
;
85
}
86
}
87
88
public
static
function
onBeforeEndBufferContent
()
89
{
90
$request =
Context::getCurrent
()->getRequest();
91
$isAjaxRequest = $request->isAjaxRequest();
92
$isAdminSection = defined(
"ADMIN_SECTION"
) && ADMIN_SECTION ===
true
;
93
if
($isAjaxRequest || $isAdminSection)
94
{
95
return
;
96
}
97
98
$isSlider = $request->getQuery(
'IFRAME'
) ===
"Y"
;
99
if
(static::$bufferRestarted ===
true
&& !$isSlider)
100
{
101
return
;
102
}
103
104
$settings = Configuration::getValue(
"analytics_counter"
);
105
$forceEnabled = isset($settings[
"enabled"
]) && $settings[
"enabled"
] ===
true
;
106
107
if
($forceEnabled ===
false
&&
SiteSpeed::isIntranetSite
(SITE_ID))
108
{
109
return
;
110
}
111
112
if
(
SiteSpeed::isOn
() && static::$enabled ===
true
)
113
{
114
Counter::injectIntoPage
();
115
}
116
}
117
118
public
static
function
onBeforeRestartBuffer
()
119
{
120
static::$bufferRestarted =
true
;
121
}
122
123
public
static
function
sendData
($id, array $arParams)
124
{
125
static::$data[$id] = $arParams;
126
}
127
128
private
static
function
injectDataParams()
129
{
130
$result =
""
;
131
foreach
(static::$data as $index => $arItem)
132
{
133
foreach
($arItem as $key => $value)
134
{
135
if
(is_array($value))
136
{
137
$jsValue =
'"'
.\CUtil::PhpToJSObject($value).
'"'
;
138
}
139
elseif ($value instanceof
JsExpression
)
140
{
141
$jsValue = $value;
142
}
143
else
144
{
145
$jsValue =
'"'
.\CUtil::JSEscape($value).
'"'
;
146
}
147
148
$result .=
'_ba.push(["ad['
.$index.
']['
.\CUtil::JSEscape($key).
']", '
.$jsValue.
']);'
;
149
}
150
}
151
152
return
$result;
153
}
154
}
Bitrix\Main\Analytics\Counter
Definition
counter.php:12
Bitrix\Main\Analytics\Counter\getAccountId
static getAccountId()
Definition
counter.php:62
Bitrix\Main\Analytics\Counter\onBeforeRestartBuffer
static onBeforeRestartBuffer()
Definition
counter.php:118
Bitrix\Main\Analytics\Counter\onBeforeEndBufferContent
static onBeforeEndBufferContent()
Definition
counter.php:88
Bitrix\Main\Analytics\Counter\getInjectedJs
static getInjectedJs($stripTags=false)
Definition
counter.php:27
Bitrix\Main\Analytics\Counter\enable
static enable()
Definition
counter.php:17
Bitrix\Main\Analytics\Counter\disable
static disable()
Definition
counter.php:22
Bitrix\Main\Analytics\Counter\injectIntoPage
static injectIntoPage()
Definition
counter.php:57
Bitrix\Main\Analytics\Counter\$data
static $data
Definition
counter.php:13
Bitrix\Main\Analytics\Counter\sendData
static sendData($id, array $arParams)
Definition
counter.php:123
Bitrix\Main\Analytics\Counter\$enabled
static $enabled
Definition
counter.php:14
Bitrix\Main\Analytics\Counter\getPrivateKey
static getPrivateKey()
Definition
counter.php:75
Bitrix\Main\Analytics\Counter\$bufferRestarted
static $bufferRestarted
Definition
counter.php:15
Bitrix\Main\Analytics\SiteSpeed\isIntranetSite
static isIntranetSite($siteId)
Definition
sitespeed.php:81
Bitrix\Main\Analytics\SiteSpeed\isOn
static isOn()
Definition
sitespeed.php:127
Bitrix\Main\Application
Definition
application.php:28
Bitrix\Main\Application\getInstance
static getInstance()
Definition
application.php:95
Bitrix\Main\Config\Configuration
Definition
configuration.php:7
Bitrix\Main\Context\getCurrent
static getCurrent()
Definition
context.php:241
Bitrix\Main\Page\AssetLocation
Definition
assetlocation.php:5
Bitrix\Main\Text\JsExpression
Definition
jsexpression.php:17
Bitrix\Main\Analytics
Definition
analyticsevent.php:5
Bitrix\Main\Context
Definition
culture.php:9
modules
main
lib
analytics
counter.php
Создано системой
1.10.0