feat: track and push TeleCart Pulse events
This commit is contained in:
@@ -87,3 +87,39 @@ export function getCssVarOklchRgb(cssVarName) {
|
||||
return `#${toHex(r)}${toHex(g)}${toHex(b_)}`;
|
||||
}
|
||||
|
||||
export function deserializeStartParams(serialized) {
|
||||
if (!serialized) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// Восстанавливаем стандартные base64 символы
|
||||
let encoded = serialized.replace(/-/g, '+').replace(/_/g, '/');
|
||||
|
||||
// Добавляем padding, если нужно
|
||||
const padding = encoded.length % 4;
|
||||
if (padding !== 0) {
|
||||
encoded += '='.repeat(4 - padding);
|
||||
}
|
||||
|
||||
// Декодируем из base64
|
||||
let json;
|
||||
try {
|
||||
json = atob(encoded); // btoa / atob стандартные в браузере
|
||||
} catch (e) {
|
||||
throw new Error('Failed to decode base64 string');
|
||||
}
|
||||
|
||||
// Парсим JSON
|
||||
let parameters;
|
||||
try {
|
||||
parameters = JSON.parse(json);
|
||||
} catch (e) {
|
||||
throw new Error('Failed to decode JSON: ' + e.message);
|
||||
}
|
||||
|
||||
if (typeof parameters !== 'object' || parameters === null || Array.isArray(parameters) && !Array.isArray(parameters)) {
|
||||
throw new Error('Decoded value is not an object');
|
||||
}
|
||||
|
||||
return parameters;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user