From bdccdf1a0ae0803d3205494e090aba763f46cb3e Mon Sep 17 00:00:00 2001 From: Stan Girard Date: Mon, 26 Jun 2023 12:54:07 +0200 Subject: [PATCH] perf(analytics): added tracking for file upload and chat (#376) --- frontend/app/chat/[chatId]/hooks/useChat.ts | 3 +++ .../upload/components/FileUploader/hooks/useFileUploader.ts | 4 +++- frontend/services/analytics/useEventTracking.ts | 3 +-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/frontend/app/chat/[chatId]/hooks/useChat.ts b/frontend/app/chat/[chatId]/hooks/useChat.ts index e431edc1f..d565f4f22 100644 --- a/frontend/app/chat/[chatId]/hooks/useChat.ts +++ b/frontend/app/chat/[chatId]/hooks/useChat.ts @@ -4,6 +4,7 @@ import { useEffect, useState } from "react"; import { useBrainConfig } from "@/lib/context/BrainConfigProvider/hooks/useBrainConfig"; import { useToast } from "@/lib/hooks"; +import { useEventTracking } from "@/services/analytics/useEventTracking"; import { useChatService } from "./useChatService"; import { useChatContext } from "../context/ChatContext"; @@ -11,6 +12,7 @@ import { ChatQuestion } from "../types"; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export const useChat = () => { + const { track } = useEventTracking(); const params = useParams(); const [chatId, setChatId] = useState( params?.chatId as string | undefined @@ -54,6 +56,7 @@ export const useChat = () => { }; try { + void track("QUESTION_ASKED"); setGeneratingAnswer(true); const currentChatId = chatId ?? diff --git a/frontend/app/upload/components/FileUploader/hooks/useFileUploader.ts b/frontend/app/upload/components/FileUploader/hooks/useFileUploader.ts index 833e8996a..f5a254190 100644 --- a/frontend/app/upload/components/FileUploader/hooks/useFileUploader.ts +++ b/frontend/app/upload/components/FileUploader/hooks/useFileUploader.ts @@ -6,8 +6,10 @@ import { FileRejection, useDropzone } from "react-dropzone"; import { useSupabase } from "@/lib/context/SupabaseProvider"; import { useAxios } from "@/lib/hooks"; import { useToast } from "@/lib/hooks/useToast"; +import { useEventTracking } from "@/services/analytics/useEventTracking"; export const useFileUploader = () => { + const { track} = useEventTracking(); const [isPending, setIsPending] = useState(false); const { publish } = useToast(); const [files, setFiles] = useState([]); @@ -25,7 +27,7 @@ export const useFileUploader = () => { formData.append("file", file); try { const response = await axiosInstance.post(`/upload`, formData); - + track("FILE_UPLOADED"); publish({ variant: response.data.type, text: diff --git a/frontend/services/analytics/useEventTracking.ts b/frontend/services/analytics/useEventTracking.ts index 9812f0ade..a482f4112 100644 --- a/frontend/services/analytics/useEventTracking.ts +++ b/frontend/services/analytics/useEventTracking.ts @@ -4,14 +4,13 @@ import { useSupabase } from "@/lib/context/SupabaseProvider"; import { useJune } from "./useJune"; -type TrackedEvent = "SIGNED_IN"; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export const useEventTracking = () => { const analytics = useJune(); const { session } = useSupabase(); - const track = async (event: TrackedEvent): Promise => { + const track = async (event: string): Promise => { await analytics?.identify(session?.user.id); await analytics?.track(event); };