feat: Use yaMetrika number in settings

This commit is contained in:
2025-12-01 19:44:14 +03:00
parent c670e38392
commit cedc49f0d5
5 changed files with 54 additions and 46 deletions

View File

@@ -53,6 +53,12 @@ settings.load()
throw new Error('App disabled (maintenance mode)');
}
})
.then(() => settings.ya_metrika_enabled && injectYaMetrika())
.then(() => {
if (! window.Telegram.WebApp.initData) {
throw new Error('Invalid init data. Application not in Telegram View');
}
})
.then(() => pulse.initFromStartParams())
.then(() => pulse.catchTelegramCustomerFromInitData())
.then(() => pulse.ingest(TC_PULSE_EVENTS.WEBAPP_OPEN))
@@ -73,11 +79,6 @@ settings.load()
})();
})
.then(() => blocks.processBlocks(settings.mainpage_blocks))
// .then(async () => {
// console.debug('Load default filters for the main page');
// const filtersStore = useProductFiltersStore();
// filtersStore.applied = await filtersStore.fetchFiltersForMainPage();
// })
.then(() => {
console.debug('[Init] Set theme attributes');
document.documentElement.setAttribute('data-theme', settings.theme[window.Telegram.WebApp.colorScheme]);
@@ -108,7 +109,6 @@ settings.load()
app.mount('#app');
})
.then(() => window.Telegram.WebApp.ready())
.then(() => settings.ya_metrika_enabled && injectYaMetrika())
.catch(error => {
console.error(error);
const errorApp = createApp(ApplicationError, {error});

View File

@@ -17,11 +17,11 @@ export function injectYaMetrika() {
script.src = '/index.php?route=extension/tgshop/handle/ya_metrika';
// script.async = true;
document.head.appendChild(script);
console.debug('[Init] Yandex Metrika injected to the page.');
console.debug('[ym] Yandex Metrika injected to the page.');
script.onload = () => {
window.YA_METRIKA_ID = getMetrikaId();
console.debug('[Init] Detected Yandex.Metrika ID:', window.YA_METRIKA_ID);
console.debug('[ym] Detected Yandex.Metrika ID:', window.YA_METRIKA_ID);
const yaMetrika = useYaMetrikaStore();
yaMetrika.initUserParams();
window.dataLayer = window.dataLayer || [];