Squashed commit message
Some checks failed
Telegram Mini App Shop Builder / Compute version metadata (push) Has been cancelled
Telegram Mini App Shop Builder / Run Frontend tests (push) Has been cancelled
Telegram Mini App Shop Builder / Run Backend tests (push) Has been cancelled
Telegram Mini App Shop Builder / Run PHP_CodeSniffer (push) Has been cancelled
Telegram Mini App Shop Builder / Build module. (push) Has been cancelled
Telegram Mini App Shop Builder / release (push) Has been cancelled

This commit is contained in:
2026-03-11 22:08:41 +03:00
commit 393bbb286b
585 changed files with 65605 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import {useYaMetrikaStore} from "@/stores/yaMetrikaStore.js";
function getMetrikaId() {
// Пробуем найти все элементы <script> с mc.yandex.ru
const scripts = Array.from(document.scripts);
for (const s of scripts) {
if (s.src.includes('mc.yandex.ru/metrika/tag.js')) {
const match = s.src.match(/id=(\d+)/);
if (match) return match[1];
}
}
return null;
}
export function injectYaMetrika() {
const script = document.createElement('script');
script.src = '/index.php?route=extension/tgshop/handle/ya_metrika';
// script.async = true;
document.head.appendChild(script);
console.debug('[ym] Yandex Metrika injected to the page.');
script.onload = () => {
window.YA_METRIKA_ID = getMetrikaId();
console.debug('[ym] Detected Yandex.Metrika ID:', window.YA_METRIKA_ID);
const yaMetrika = useYaMetrikaStore();
yaMetrika.initUserParams();
window.dataLayer = window.dataLayer || [];
yaMetrika.processQueue();
}
}