diff --git a/frontend/admin/src/App.vue b/frontend/admin/src/App.vue index 5185a9f..af18536 100644 --- a/frontend/admin/src/App.vue +++ b/frontend/admin/src/App.vue @@ -11,7 +11,7 @@
  • - Метрики + Метрика
  • diff --git a/frontend/admin/src/views/MetricsView.vue b/frontend/admin/src/views/MetricsView.vue index 85dcc60..fbafdad 100644 --- a/frontend/admin/src/views/MetricsView.vue +++ b/frontend/admin/src/views/MetricsView.vue @@ -6,24 +6,47 @@ Задействовать Яндекс.Метрику для Telegram магазина. - -

    Код счётчика нужно предварительно настроить, чтобы он работал корректно с Telegram Mini App. - - Инструкция как настроить i.fa.fa-external-link - .

    -

    Для проверки интеграции через кнопку "Проверить" в интерфейсе Яндекс Метрики, - необходимо сначала включить "Режим разработчика" на вкладке "Общие".

    -
    + + + + + + + diff --git a/frontend/spa/src/main.js b/frontend/spa/src/main.js index a954508..8eb7bfc 100644 --- a/frontend/spa/src/main.js +++ b/frontend/spa/src/main.js @@ -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}); diff --git a/frontend/spa/src/utils/yaMetrika.js b/frontend/spa/src/utils/yaMetrika.js index 509b6ee..1c8f3de 100644 --- a/frontend/spa/src/utils/yaMetrika.js +++ b/frontend/spa/src/utils/yaMetrika.js @@ -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 || []; diff --git a/module/oc_telegram_shop/upload/catalog/controller/extension/tgshop/handle.php b/module/oc_telegram_shop/upload/catalog/controller/extension/tgshop/handle.php index a230477..fc7165f 100755 --- a/module/oc_telegram_shop/upload/catalog/controller/extension/tgshop/handle.php +++ b/module/oc_telegram_shop/upload/catalog/controller/extension/tgshop/handle.php @@ -95,37 +95,22 @@ class ControllerExtensionTgshopHandle extends Controller ->bootAndHandleRequest(); } - function extractPureJs($input) - { - // Убираем - $input = preg_replace('##is', '', $input); - - // Убираем - $input = preg_replace('##s', '', $input); - - // Извлекаем содержимое - if (preg_match('#]*>(.*?)#is', $input, $matches)) { - return trim($matches[1]); - } - - return ''; - } - - private function safeJsonDecode(?string $input = null, $default = null) - { - try { - return json_decode($input, true, 512, JSON_THROW_ON_ERROR); - } catch (JsonException $e) { - return $default; - } - } - + /** @noinspection PhpUnused */ public function ya_metrika(): void { $json = $this->model_setting_setting->getSetting('module_telecart'); if (isset($json['module_telecart_settings'])) { - $raw = Arr::get($json, 'module_telecart_settings.metrics.yandex_metrika_counter'); - $raw = $this->extractPureJs($raw); + $yaCounterId = Arr::get($json, 'module_telecart_settings.metrics.yandex_metrika_counter'); + $raw = <<