mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-25 12:22:58 +03:00
perf(analytics): added tracking for file upload and chat (#376)
This commit is contained in:
parent
97d2c9de10
commit
bdccdf1a0a
@ -4,6 +4,7 @@ import { useEffect, useState } from "react";
|
|||||||
|
|
||||||
import { useBrainConfig } from "@/lib/context/BrainConfigProvider/hooks/useBrainConfig";
|
import { useBrainConfig } from "@/lib/context/BrainConfigProvider/hooks/useBrainConfig";
|
||||||
import { useToast } from "@/lib/hooks";
|
import { useToast } from "@/lib/hooks";
|
||||||
|
import { useEventTracking } from "@/services/analytics/useEventTracking";
|
||||||
|
|
||||||
import { useChatService } from "./useChatService";
|
import { useChatService } from "./useChatService";
|
||||||
import { useChatContext } from "../context/ChatContext";
|
import { useChatContext } from "../context/ChatContext";
|
||||||
@ -11,6 +12,7 @@ import { ChatQuestion } from "../types";
|
|||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||||
export const useChat = () => {
|
export const useChat = () => {
|
||||||
|
const { track } = useEventTracking();
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const [chatId, setChatId] = useState<string | undefined>(
|
const [chatId, setChatId] = useState<string | undefined>(
|
||||||
params?.chatId as string | undefined
|
params?.chatId as string | undefined
|
||||||
@ -54,6 +56,7 @@ export const useChat = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
void track("QUESTION_ASKED");
|
||||||
setGeneratingAnswer(true);
|
setGeneratingAnswer(true);
|
||||||
const currentChatId =
|
const currentChatId =
|
||||||
chatId ??
|
chatId ??
|
||||||
|
@ -6,8 +6,10 @@ import { FileRejection, useDropzone } from "react-dropzone";
|
|||||||
import { useSupabase } from "@/lib/context/SupabaseProvider";
|
import { useSupabase } from "@/lib/context/SupabaseProvider";
|
||||||
import { useAxios } from "@/lib/hooks";
|
import { useAxios } from "@/lib/hooks";
|
||||||
import { useToast } from "@/lib/hooks/useToast";
|
import { useToast } from "@/lib/hooks/useToast";
|
||||||
|
import { useEventTracking } from "@/services/analytics/useEventTracking";
|
||||||
|
|
||||||
export const useFileUploader = () => {
|
export const useFileUploader = () => {
|
||||||
|
const { track} = useEventTracking();
|
||||||
const [isPending, setIsPending] = useState(false);
|
const [isPending, setIsPending] = useState(false);
|
||||||
const { publish } = useToast();
|
const { publish } = useToast();
|
||||||
const [files, setFiles] = useState<File[]>([]);
|
const [files, setFiles] = useState<File[]>([]);
|
||||||
@ -25,7 +27,7 @@ export const useFileUploader = () => {
|
|||||||
formData.append("file", file);
|
formData.append("file", file);
|
||||||
try {
|
try {
|
||||||
const response = await axiosInstance.post(`/upload`, formData);
|
const response = await axiosInstance.post(`/upload`, formData);
|
||||||
|
track("FILE_UPLOADED");
|
||||||
publish({
|
publish({
|
||||||
variant: response.data.type,
|
variant: response.data.type,
|
||||||
text:
|
text:
|
||||||
|
@ -4,14 +4,13 @@ import { useSupabase } from "@/lib/context/SupabaseProvider";
|
|||||||
|
|
||||||
import { useJune } from "./useJune";
|
import { useJune } from "./useJune";
|
||||||
|
|
||||||
type TrackedEvent = "SIGNED_IN";
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||||
export const useEventTracking = () => {
|
export const useEventTracking = () => {
|
||||||
const analytics = useJune();
|
const analytics = useJune();
|
||||||
const { session } = useSupabase();
|
const { session } = useSupabase();
|
||||||
|
|
||||||
const track = async (event: TrackedEvent): Promise<void> => {
|
const track = async (event: string): Promise<void> => {
|
||||||
await analytics?.identify(session?.user.id);
|
await analytics?.identify(session?.user.id);
|
||||||
await analytics?.track(event);
|
await analytics?.track(event);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user