feat: add TeleCartPulse telemetry system and ETL endpoints

- Add TeleCartPulse service for event tracking and analytics
  - Implement PayloadSigner for secure payload signing/verification
  - Add StartParamSerializer for campaign parameter handling
  - Create TeleCartPulseServiceProvider for dependency injection
  - Add PulseEvents constants and exception classes

- Add TelemetryHandler for ingesting client-side events
  - Implement /ingest endpoint for receiving webapp events
  - Support WEBAPP_OPEN event tracking with campaign metadata

- Add ETLHandler for customer data export
  - Implement /customers endpoint for ETL processes
  - Add /customers/meta endpoint for pagination metadata
  - Support filtering by updated_at timestamp
  - Include customer metrics: orders count, total spent, etc.

- Add InvalidApiTokenException for API key validation
- Update Request class to support API key extraction
- Add Utils helper methods for domain extraction
- Integrate telemetry in frontend SPA (webapp open event)
- Add TeleCartPulseView in admin panel for API key configuration
- Update routes to include new telemetry and ETL endpoints
This commit is contained in:
2025-11-30 11:49:55 +03:00
committed by Nikita Kiselev
parent 2743b83a2c
commit e8d0f8a819
26 changed files with 607 additions and 18 deletions

View File

@@ -38,6 +38,10 @@
<RouterLink :to="{name: 'customers'}">Telegram Покупатели</RouterLink>
</li>
<li :class="{active: route.name === 'pulse'}">
<RouterLink :to="{name: 'pulse'}">TeleCart Pulse</RouterLink>
</li>
<li :class="{active: route.name === 'logs'}">
<RouterLink :to="{name: 'logs'}">Журнал событий</RouterLink>
</li>

View File

@@ -9,6 +9,7 @@ import MainPageView from "@/views/MainPageView.vue";
import LogsView from "@/views/LogsView.vue";
import FormBuilderView from "@/views/FormBuilderView.vue";
import CustomersView from "@/views/CustomersView.vue";
import TeleCartPulseView from "@/views/TeleCartPulseView.vue";
const router = createRouter({
history: createMemoryHistory(),
@@ -20,6 +21,7 @@ const router = createRouter({
{path: '/mainpage', name: 'mainpage', component: MainPageView},
{path: '/metrics', name: 'metrics', component: MetricsView},
{path: '/orders', name: 'orders', component: OrdersView},
{path: '/pulse', name: 'pulse', component: TeleCartPulseView},
{path: '/store', name: 'store', component: StoreView},
{path: '/telegram', name: 'telegram', component: TelegramView},
{path: '/texts', name: 'texts', component: TextsView},

View File

@@ -73,6 +73,10 @@ export const useSettingsStore = defineStore('settings', {
schema: [],
}
},
pulse: {
api_key: '',
},
},
}),

View File

@@ -0,0 +1,15 @@
<template>
<ItemInput label="API ключ"
v-model="settings.items.pulse.api_key"
placeholder="AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE"
>
Используется для обмена информацией по кампаниям, рассылкам, сбору метрик.
</ItemInput>
</template>
<script setup>
import {useSettingsStore} from "@/stores/settings.js";
import ItemInput from "@/components/Settings/ItemInput.vue";
const settings = useSettingsStore();
</script>

View File

@@ -0,0 +1,3 @@
export const TC_PULSE_EVENTS = {
WEBAPP_OPEN: 'WEBAPP_OPEN',
};

View File

@@ -8,18 +8,18 @@ import {useSettingsStore} from "@/stores/SettingsStore.js";
import ApplicationError from "@/ApplicationError.vue";
import AppMetaInitializer from "@/utils/AppMetaInitializer.ts";
import {injectYaMetrika} from "@/utils/yaMetrika.js";
import {checkIsUserPrivacyConsented, saveTelegramCustomer} from "@/utils/ftch.js";
import {checkIsUserPrivacyConsented, ingest, saveTelegramCustomer} from "@/utils/ftch.js";
import {register} from 'swiper/element/bundle';
import 'swiper/element/bundle';
import 'swiper/css/bundle';
import AppLoading from "@/AppLoading.vue";
import {useProductFiltersStore} from "@/stores/ProductFiltersStore.js";
import {useBlocksStore} from "@/stores/BlocksStore.js";
import {getCssVarOklchRgb} from "@/helpers.js";
import {defaultConfig, plugin} from '@formkit/vue';
import config from './formkit.config.js';
import {TC_PULSE_EVENTS} from "@/constants/tPulseEvents.js";
register();
@@ -51,18 +51,22 @@ settings.load()
throw new Error('App disabled (maintenance mode)');
}
})
.then(async () => {
.then(() => {
const webapp = window.Telegram.WebApp;
ingest({
event: TC_PULSE_EVENTS.WEBAPP_OPEN,
webapp,
})
.catch(err => console.error('Ingest failed:', err));
})
.then(() => {
// Сохраняем данные Telegram-пользователя в базу данных
const userData = window.Telegram?.WebApp?.initDataUnsafe?.user;
if (userData) {
try {
console.debug('[Init] Saving Telegram customer data');
await saveTelegramCustomer(userData);
console.debug('[Init] Telegram customer data saved successfully');
} catch (error) {
// Не прерываем загрузку приложения, если не удалось сохранить пользователя
console.warn('[Init] Failed to save Telegram customer data:', error);
}
console.debug('[Init] Saving Telegram customer data');
saveTelegramCustomer(userData)
.then(() => console.debug('[Init] Telegram customer data saved successfully'))
.catch(() => console.warn('[Init] Failed to save Telegram customer data:', error));
}
})
.then(() => {
@@ -82,11 +86,11 @@ 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(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]);