From 8fc9f7dc78dd2c58f541e7f1389c40710941adfb Mon Sep 17 00:00:00 2001 From: Oleg Ivaniv Date: Wed, 23 Aug 2023 18:59:36 +0200 Subject: [PATCH] fix(editor): Fix sending of Ask AI tracking events --- .../components/CodeNodeEditor/AskAI/AskAI.vue | 16 ---------------- .../editor-ui/src/plugins/telemetry/index.ts | 12 +++++------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/packages/editor-ui/src/components/CodeNodeEditor/AskAI/AskAI.vue b/packages/editor-ui/src/components/CodeNodeEditor/AskAI/AskAI.vue index 9a4876b33bd6c..78787734d262c 100644 --- a/packages/editor-ui/src/components/CodeNodeEditor/AskAI/AskAI.vue +++ b/packages/editor-ui/src/components/CodeNodeEditor/AskAI/AskAI.vue @@ -170,28 +170,12 @@ async function onSubmit() { type: 'success', title: i18n.baseText('codeNodeEditor.askAi.generationCompleted'), }); - - useTelemetry().trackAskAI('askAi.generationFinished', { - prompt: prompt.value, - code, - tokensCount: usage?.total_tokens, - hasErrors: false, - error: '', - }); } catch (error) { showMessage({ type: 'error', title: i18n.baseText('codeNodeEditor.askAi.generationFailed'), message: getErrorMessageByStatusCode(error.httpStatusCode || error?.response.status), }); - - useTelemetry().trackAskAI('askAi.generationFinished', { - prompt: prompt.value, - code: '', - tokensCount: 0, - hasErrors: true, - error: getErrorMessageByStatusCode(error.httpStatusCode || error?.response.status), - }); stopLoading(); } } diff --git a/packages/editor-ui/src/plugins/telemetry/index.ts b/packages/editor-ui/src/plugins/telemetry/index.ts index c7ec049b2377c..1c9a783d8fec2 100644 --- a/packages/editor-ui/src/plugins/telemetry/index.ts +++ b/packages/editor-ui/src/plugins/telemetry/index.ts @@ -12,6 +12,7 @@ import { usePostHog } from '@/stores/posthog.store'; export class Telemetry { private pageEventQueue: Array<{ route: RouteLocation }>; + private previousPath: string; private get rudderStack() { @@ -110,16 +111,15 @@ export class Telemetry { const pageName = route.name; let properties: { [key: string]: string } = {}; if ( - route.meta && - route.meta.telemetry && + route.meta?.telemetry && typeof route.meta.telemetry.getProperties === 'function' ) { properties = route.meta.telemetry.getProperties(route); } const category = - (route.meta && route.meta.telemetry && route.meta.telemetry.pageCategory) || 'Editor'; - this.rudderStack.page(category, pageName!, properties); + (route.meta?.telemetry?.pageCategory) || 'Editor'; + this.rudderStack.page(category, pageName, properties); } else { this.pageEventQueue.push({ route, @@ -139,10 +139,8 @@ export class Telemetry { if (this.rudderStack) { properties.session_id = useRootStore().sessionId; switch (event) { - case 'askAi.generationFinished': - this.track('Ai code generation finished', properties, { withPostHog: true }); case 'ask.generationClicked': - this.track('User clicked on generate code button', properties); + this.track('User clicked on generate code button', properties, { withPostHog: true }); default: break; }