fix(editor): Fix sending of Ask AI tracking events (#7002)

This commit is contained in:
OlegIvaniv 2023-08-24 18:40:00 +02:00 committed by GitHub
parent 92d4befea6
commit fb05afa165
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 23 deletions

View file

@ -170,28 +170,12 @@ async function onSubmit() {
type: 'success', type: 'success',
title: i18n.baseText('codeNodeEditor.askAi.generationCompleted'), title: i18n.baseText('codeNodeEditor.askAi.generationCompleted'),
}); });
useTelemetry().trackAskAI('askAi.generationFinished', {
prompt: prompt.value,
code,
tokensCount: usage?.total_tokens,
hasErrors: false,
error: '',
});
} catch (error) { } catch (error) {
showMessage({ showMessage({
type: 'error', type: 'error',
title: i18n.baseText('codeNodeEditor.askAi.generationFailed'), title: i18n.baseText('codeNodeEditor.askAi.generationFailed'),
message: getErrorMessageByStatusCode(error.httpStatusCode || error?.response.status), 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(); stopLoading();
} }
} }

View file

@ -12,6 +12,7 @@ import { usePostHog } from '@/stores/posthog.store';
export class Telemetry { export class Telemetry {
private pageEventQueue: Array<{ route: RouteLocation }>; private pageEventQueue: Array<{ route: RouteLocation }>;
private previousPath: string; private previousPath: string;
private get rudderStack() { private get rudderStack() {
@ -110,16 +111,15 @@ export class Telemetry {
const pageName = route.name; const pageName = route.name;
let properties: { [key: string]: string } = {}; let properties: { [key: string]: string } = {};
if ( if (
route.meta && route.meta?.telemetry &&
route.meta.telemetry &&
typeof route.meta.telemetry.getProperties === 'function' typeof route.meta.telemetry.getProperties === 'function'
) { ) {
properties = route.meta.telemetry.getProperties(route); properties = route.meta.telemetry.getProperties(route);
} }
const category = const category =
(route.meta && route.meta.telemetry && route.meta.telemetry.pageCategory) || 'Editor'; (route.meta?.telemetry?.pageCategory) || 'Editor';
this.rudderStack.page(category, pageName!, properties); this.rudderStack.page(category, pageName, properties);
} else { } else {
this.pageEventQueue.push({ this.pageEventQueue.push({
route, route,
@ -139,10 +139,8 @@ export class Telemetry {
if (this.rudderStack) { if (this.rudderStack) {
properties.session_id = useRootStore().sessionId; properties.session_id = useRootStore().sessionId;
switch (event) { switch (event) {
case 'askAi.generationFinished':
this.track('Ai code generation finished', properties, { withPostHog: true });
case 'ask.generationClicked': case 'ask.generationClicked':
this.track('User clicked on generate code button', properties); this.track('User clicked on generate code button', properties, { withPostHog: true });
default: default:
break; break;
} }