feat: add headless question tracking (#1051)

This commit is contained in:
Mamadou DICKO 2023-08-29 12:26:08 +02:00 committed by GitHub
parent 072d97adb1
commit 6e43e6f16f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -24,7 +24,7 @@ export const useChat = () => {
const [generatingAnswer, setGeneratingAnswer] = useState(false);
const { history } = useChatContext();
const { currentBrain, currentPromptId } = useBrainContext();
const { currentBrain, currentPromptId, currentBrainId } = useBrainContext();
const { publish } = useToast();
const { createChat } = useChatApi();
@ -55,7 +55,11 @@ export const useChat = () => {
//TODO: update chat list here
}
void track("QUESTION_ASKED");
void track("QUESTION_ASKED", {
brainId: currentBrainId,
promptId: currentPromptId,
});
const chatConfig = getChatConfigFromLocalStorage(currentChatId);
const chatQuestion: ChatQuestion = {

View File

@ -9,7 +9,10 @@ export const useEventTracking = () => {
const analytics = useJune();
const { session } = useSupabase();
const track = async (event: string): Promise<void> => {
const track = async (
event: string,
properties?: Record<string, unknown>
): Promise<void> => {
console.log("Event to track", event);
if (analytics === undefined) {
console.log("No analytics found");
@ -17,7 +20,7 @@ export const useEventTracking = () => {
return;
}
await analytics.identify(session?.user.id, { email: session?.user.email });
await analytics.track(event);
await analytics.track(event, properties);
};
return {