fix(utm): заменить публичную chob на banch (#327)
deploy-preland / deploy zoomstage.online (push) Successful in 42s

This commit is contained in:
Panfilov Konstantin committed 2026-10-25 05:09:55 +03:00
1 parent 08febba368
commit 965eb2e6a5
12 files changed
+58 -33

No files matched your search

+6 -6
View File
@@ -4,14 +4,14 @@ declare(strict_types=1);
function prelandUtmEnums(): array
{
return ['theme'=>['1'=>'dark','2'=>'light'], 'reg'=>['1'=>'before','2'=>'after'], 'chob'=>['1'=>'b','2'=>'a'], 'focus'=>['1'=>'face','2'=>'center']];
return ['theme'=>['1'=>'dark','2'=>'light'], 'reg'=>['1'=>'before','2'=>'after'], 'banch'=>['1'=>'b','2'=>'a'], 'focus'=>['1'=>'face','2'=>'center']];
}
/** Совместимость host-config при доставке кода до точечной миграции. */
function prelandNumericUtmConfig(array $config): array
{
$settings = is_array($config['utm'] ?? null) ? $config['utm'] : [];
foreach (['registration'=>'reg','bchoice'=>'chob'] as $old=>$new) {
foreach (['registration'=>'reg','chob'=>'banch','bchoice'=>'banch'] as $old=>$new) {
if (!isset($settings[$new]) && isset($settings[$old])) $settings[$new] = $settings[$old];
unset($settings[$old]);
}
@@ -36,15 +36,15 @@ function prelandNumericUtmConfig(array $config): array
function prelandResolveUtm(array $query, array $config): array
{
$config=prelandNumericUtmConfig($config);
$defaults=['indpic'=>'1','theme'=>'2','degr'=>'1','reg'=>'2','chob'=>'2','tp'=>'1','cons'=>'2','focus'=>'1'];
$defaults=['indpic'=>'1','theme'=>'2','degr'=>'1','reg'=>'2','banch'=>'2','tp'=>'1','cons'=>'2','focus'=>'1'];
$enums=prelandUtmEnums(); $digits=[]; $context=$query;
foreach (['registration','bchoice','chb'] as $old) unset($context[$old]);
foreach (['registration','bchoice','chob','chb'] as $old) unset($context[$old]);
foreach ($defaults as $key=>$fallback) {
unset($context[$key]);
$settings=$config['utm'][$key] ?? [];
$valid=static fn($digit): bool => preg_match('/^[1-9]$/D',(string)$digit)===1
&& (!isset($enums[$key]) || isset($enums[$key][$digit]))
&& (in_array($key,['cons','theme','reg','chob','focus'],true) || isset($settings['weights'][$digit]));
&& (in_array($key,['cons','theme','reg','banch','focus'],true) || isset($settings['weights'][$digit]));
$default=(string)($settings['default'] ?? $fallback);
if (!$valid($default)) $default=$fallback;
$value=$query[$key] ?? null;
@@ -81,7 +81,7 @@ function prelandResolveUtm(array $query, array $config): array
}
if (!$valid($digit ?? '')) $digit=$default;
$digits[$key]=$digit;
$internal=['reg'=>'registration','chob'=>'bchoice'][$key] ?? $key;
$internal=['reg'=>'registration','banch'=>'bchoice'][$key] ?? $key;
$context[$internal]=$enums[$key][$digit] ?? $digit;
}
return ['digits'=>$digits,'context'=>$context];
+6 -6
View File
@@ -2,18 +2,18 @@
/** api#326: новый шум при каждой навигации; recovery хранит выбранные цифры. */
return <<<'JS'
(function () {
const keys = ['indpic','theme','degr','reg','chob','tp','cons','focus'];
const enums = {theme:{dark:'1',light:'2'},reg:{before:'1',after:'2'},chob:{b:'1',a:'2'},focus:{face:'1',center:'2'}};
const legacy = {reg:'registration',chob:'bchoice'};
const keys = ['indpic','theme','degr','reg','banch','tp','cons','focus'];
const enums = {theme:{dark:'1',light:'2'},reg:{before:'1',after:'2'},banch:{b:'1',a:'2'},focus:{face:'1',center:'2'}};
const legacy = {reg:'registration',banch:'bchoice'};
const valid = (key, value) => /^[1-9]$/.test(value || '') && (!enums[key] || Object.values(enums[key]).includes(value));
function restore(meta, defaults) {
const query = new URLSearchParams(meta.redirectUtm || '');
const digits = {};
for (const key of keys) {
let value = meta.utmDigits?.[key];
let value = meta.utmDigits?.[key] ?? (key === 'banch' ? meta.utmDigits?.chob : undefined);
if (!valid(key, value)) {
// Только сохранённый record: старые enum/открытые цифры не являются raw URL alias.
const stored = query.get(legacy[key] || key) ?? query.get(key);
const stored = query.get(legacy[key] || key) ?? query.get(key) ?? (key === 'banch' ? query.get('chob') : null);
value = enums[key]?.[stored] || stored;
if (!valid(key, value)) value = Array.from(stored || '')[4];
}
@@ -32,7 +32,7 @@ return <<<'JS'
function query(meta, defaults) {
const params = new URLSearchParams(meta.redirectUtm || '');
const digits = restore(meta, defaults);
for (const key of ['registration','bchoice','chb','key','shown_theme',...keys]) params.delete(key);
for (const key of ['registration','bchoice','chob','chb','key','shown_theme',...keys]) params.delete(key);
for (const key of keys) params.set(key, mask(digits[key]));
return params.toString();
}