1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
counter.php
См. документацию.
1<?php
2namespace Bitrix\Main\Analytics;
3
4use Bitrix\Main\Config\Configuration;
5use Bitrix\Main\Application;
6use Bitrix\Main\Context;
7use Bitrix\Main\Page\Asset;
8use Bitrix\Main\Page\AssetLocation;
9use Bitrix\Main\Text\JsExpression;
10
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://") + "sitespeed.bitrix24.tech/ba.js";
41 var s = document.getElementsByTagName("script")[0];
42 s.parentNode.insertBefore(ba, s);
43 })();
44JS;
45
46 $js = str_replace(array("\n", "\t"), "", $js);
47 if ($stripTags === false)
48 {
49 return "<script>".$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 {
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}
$arParams
Определения access_dialog.php:21
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
static getAccountId()
Определения counter.php:62
static onBeforeRestartBuffer()
Определения counter.php:118
static onBeforeEndBufferContent()
Определения counter.php:88
static getInjectedJs($stripTags=false)
Определения counter.php:27
static enable()
Определения counter.php:17
static disable()
Определения counter.php:22
static injectIntoPage()
Определения counter.php:57
static $data
Определения counter.php:13
static sendData($id, array $arParams)
Определения counter.php:123
static $enabled
Определения counter.php:14
static getPrivateKey()
Определения counter.php:75
static $bufferRestarted
Определения counter.php:15
static isIntranetSite($siteId)
Определения sitespeed.php:69
static isOn()
Определения sitespeed.php:115
static getInstance()
Определения application.php:98
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
if(file_exists(( $_fname=__DIR__ . "/classes/general/update_db_updater.php"))) if(($_fname=getLocalPath("init.php")) !==false) if(( $_fname=getLocalPath("php_interface/init.php", BX_PERSONAL_ROOT)) !==false) if(($_fname=getLocalPath("php_interface/" . SITE_ID . "/init.php", BX_PERSONAL_ROOT)) !==false) if((!(defined("STATISTIC_ONLY") &&STATISTIC_ONLY &&!str_starts_with( $GLOBALS["APPLICATION"]->GetCurPage(), BX_ROOT . "/admin/"))) &&COption::GetOptionString("main", "include_charset", "Y")=="Y" &&LANG_CHARSET !='') if(COption::GetOptionString("main", "set_p3p_header", "Y")=="Y") $license
Определения include.php:158
$host
Определения mysql_to_pgsql.php:32
$settings
Определения product_settings.php:43
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
const ADMIN_SECTION
Определения rss.php:2
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
const SITE_ID
Определения sonet_set_content_view.php:12