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',
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();
}
}

View file

@ -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;
}