Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | 27x 27x 27x 27x 27x 38x 27x 27x 27x 22x 1x 1x 1x 21x 21x 21x 2x 2x 1x 1x 1x 21x 2x 2x 2x 19x 19x 18x 18x 18x 18x 18x 1x 1x 1x | /*
* Copyright (C) 2025 Sber
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import env, {Plugins} from '@front/helpers/env';
import {userIdentifiersStoreSeafPlugin} from '@front/clickstream/userIdentityStoreSeaf';
import {setConfig, setMeta, setProfile} from '@sbol/clickstream-agent';
import {getUserHash} from '@front/clickstream/userHashStore';
import {getLoggerWithTag} from '@global/logger/v2/logger.mjs';
/**
* Ключ для хранения времени начала загрузки страницы в session storage
*/
export const PAGE_LOAD_START_SESSION_STORE_KEY = 'cs_pageLoadStart';
/**
* Ключ для хранения страницы с которой совершен переход в session storage
*/
export const PAGE_FROM_PATH_SESSION_STORE_KEY = 'cs_pageFromPath';
/**
* Ключ для хранения страницы на которую совершен переход в session storage
*/
export const PAGE_TO_PATH_SESSION_STORE_KEY = 'cs_pageToPath';
/**
* Ключ для хранения uuid, который обновляется при каждом переходе на новую страницу в session storage
*/
export const ROUTE_UID_SESSION_STORE_KEY = 'cs_routeUid';
export enum ClickstreamState {
Initializing = 'initializing',
Running = 'running',
CannotStart = 'cannot_start'
}
/**
* рубильник, указывающий, что clickstream был корректно инициализирован
*/
let clickstreamState: ClickstreamState = ClickstreamState.Initializing;
export const getClickstreamState = (): ClickstreamState => clickstreamState;
/**
* Платформа, в которой на данный момент работает модуль, для отправки в clickstream
*/
export const platform = !env.isPlugin() ? 'web' : env.isPlugin(Plugins.idea) ? 'plugin_idea' : 'plugin_vscode';
const logger = getLoggerWithTag('cs/clickstream.ts');
/**
* Инициализация clickstream
*/
export const enableClickstream = async() => {
if (env.isPlugin(Plugins.vscode)) {
logger.info(() => 'Для vscode clickstream пока не работает');
clickstreamState = ClickstreamState.CannotStart;
return;
}
let reportUrl = env.clickstreamReportUrl;
let apiKey = env.clickstreamApiKey;
if (env.isBackendMode) {
const configFromBack = env.backendEnv;
if (configFromBack?.clickstreamReportUrl && configFromBack?.clickstreamApiKey) {
reportUrl = configFromBack.clickstreamReportUrl;
apiKey = configFromBack.clickstreamApiKey;
} else {
logger.info(() => [
'Конфигурация clickstream с backend не пришла или пришла не корректная, не указан один или оба параметра ' +
'(clickstreamReportUrl, clickstreamApiKey) используем параметры frontend',
{title: 'clickstreamReportUrl', obj: configFromBack?.clickstreamReportUrl},
{title: 'clickstreamApiKey', obj: configFromBack?.clickstreamApiKey}
]);
}
}
if (!reportUrl || !apiKey) {
logger.info(() => 'Настройки clickstream (VUE_APP_CLICKSTREAM_REPORT_URL и VUE_APP_CLICKSTREAM_API_KEY) ' +
'не указаны в переменных окружения, запуск clickstream невозможен.'
);
clickstreamState = ClickstreamState.CannotStart;
return;
}
try {
const userHash = await getUserHash();
setConfig({
reportUrl: reportUrl,
userIdentifiersStore: env.isPlugin() ? userIdentifiersStoreSeafPlugin : null
});
setMeta({
apiKey: apiKey
});
setProfile({
hashUserLoginId: userHash,
appVersion: __APP_VERSION__
});
clickstreamState = ClickstreamState.Running;
logger.info(() => 'clickstream запущен.');
} catch (e: any) {
logger.error(() => 'Произошла ошибка при старте механизма отправки событий в clickstream.');
clickstreamState = ClickstreamState.CannotStart;
return;
}
};
|