api#326 Числовые UTM и новый шум каждого перехода
This commit is contained in:
1 parent
f30742c2fb
commit
81e189ca67
16 files changed
+303
-160
No files matched your search
@@ -4,7 +4,7 @@ require_once __DIR__ . '/i18n.php';
|
||||
require_once __DIR__ . '/components/asset-url.php';
|
||||
require_once __DIR__ . '/components/site-domain.php';
|
||||
require_once __DIR__ . '/components/theme-preference.php';
|
||||
require_once __DIR__ . '/components/cons-utm.php';
|
||||
require_once __DIR__ . '/components/utm-codec.php';
|
||||
|
||||
$configFile = __DIR__ . '/config.json';
|
||||
$config = file_exists($configFile) ? json_decode(file_get_contents($configFile), true) : [];
|
||||
@@ -14,66 +14,12 @@ if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
}
|
||||
|
||||
Yii::init($config['default_language'] ?? 'ru');
|
||||
$config = prelandNormalizeConsConfig($config);
|
||||
|
||||
function getWeightedRandom($weights)
|
||||
{
|
||||
if (empty($weights)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$totalWeight = array_sum($weights);
|
||||
if ($totalWeight <= 0) {
|
||||
$keys = array_keys($weights);
|
||||
return (string)$keys[0];
|
||||
}
|
||||
|
||||
$rand = (mt_rand() / mt_getrandmax()) * $totalWeight;
|
||||
$current = 0.0;
|
||||
|
||||
foreach ($weights as $key => $weight) {
|
||||
$current += (float)$weight;
|
||||
if ($rand <= $current) {
|
||||
return (string)$key;
|
||||
}
|
||||
}
|
||||
|
||||
$keys = array_keys($weights);
|
||||
return (string)end($keys);
|
||||
}
|
||||
|
||||
$get_params = prelandNormalizeConsQuery($_GET, $config['utm']['cons']);
|
||||
|
||||
if (isset($config['utm']) && is_array($config['utm'])) {
|
||||
foreach ($get_params as $key => $value) {
|
||||
if ($key === 'cons') continue;
|
||||
if (!isset($config['utm'][$key])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($config['utm'][$key]['weights'][$value])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($value !== 'rnd') {
|
||||
unset($get_params[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$weights = $config['utm'][$key]['weights'] ?? [];
|
||||
$get_params[$key] = getWeightedRandom($weights);
|
||||
}
|
||||
|
||||
foreach ($config['utm'] as $key => $value) {
|
||||
if (isset($get_params[$key])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$get_params[$key] = $config['utm'][$key]['default'];
|
||||
}
|
||||
}
|
||||
|
||||
$UTM = $get_params;
|
||||
$config = prelandNumericUtmConfig($config);
|
||||
$resolvedUtm = prelandResolveUtm($_GET, $config);
|
||||
$UTM = $resolvedUtm['context'];
|
||||
$get_params = array_diff_key($_GET, array_fill_keys(['indpic','theme','degr','reg','chob','tp','cons','focus','registration','bchoice','chb','key'], true));
|
||||
// Числа — внутренний snapshot для recovery. Публичная оболочка создаётся при навигации.
|
||||
$redirect_digits = $resolvedUtm['digits'];
|
||||
$themeInitial = prelandThemeResolve(($UTM['theme'] ?? 'light') === 'dark' ? 'dark' : 'light');
|
||||
$themeSurface = 'preland';
|
||||
$host = $config['host'] ?? ($_SERVER['HTTP_HOST'] ?? '');
|
||||
@@ -104,7 +50,7 @@ $indpic = isset($UTM['indpic']) && preg_match('/^[a-zA-Z0-9_-]+$/', (string)$UTM
|
||||
|
||||
function renderComponent(string $name, array $params = []): void
|
||||
{
|
||||
global $assetsUriPrefix, $fontsUrl, $favicon, $logoAltExt, $spritePath, $UTM, $config, $indpic, $apiHost, $redirect_url_base, $redirect_url_utm;
|
||||
global $redirect_digits, $assetsUriPrefix, $fontsUrl, $favicon, $logoAltExt, $spritePath, $UTM, $config, $indpic, $apiHost, $redirect_url_base, $redirect_url_utm;
|
||||
extract($params, EXTR_SKIP);
|
||||
$componentFile = __DIR__ . '/components/' . $name . '.php';
|
||||
if (file_exists($componentFile)) {
|
||||
|
||||
Reference in new issue
Block a user