From 5f7927598520314bc40411e32390ee09b8bebfa0 Mon Sep 17 00:00:00 2001 From: sauravniraula Date: Wed, 13 Aug 2025 13:31:33 +0545 Subject: [PATCH] chore: adds ppt prepare and stream api call events --- .../outline/hooks/usePresentationGeneration.ts | 10 ++++++---- .../presentation/hooks/usePresentationStreaming.ts | 5 ++++- servers/nextjs/utils/mixpanel.ts | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/servers/nextjs/app/(presentation-generator)/outline/hooks/usePresentationGeneration.ts b/servers/nextjs/app/(presentation-generator)/outline/hooks/usePresentationGeneration.ts index 3b80204b..6743dcd1 100644 --- a/servers/nextjs/app/(presentation-generator)/outline/hooks/usePresentationGeneration.ts +++ b/servers/nextjs/app/(presentation-generator)/outline/hooks/usePresentationGeneration.ts @@ -5,6 +5,7 @@ import { toast } from "sonner"; import { clearPresentationData } from "@/store/slices/presentationGeneration"; import { PresentationGenerationApi } from "../../services/api/presentation-generation"; import { LayoutGroup, LoadingState, TABS } from "../types/index"; +import { MixpanelEvent, trackEvent } from "@/utils/mixpanel"; const DEFAULT_LOADING_STATE: LoadingState = { message: "", @@ -37,7 +38,7 @@ export const usePresentationGeneration = ( }); return false; } - if(!selectedLayoutGroup.slides.length){ + if (!selectedLayoutGroup.slides.length) { toast.error("No Slide Schema found", { description: "Please select a Group before generating presentation", }); @@ -63,7 +64,7 @@ export const usePresentationGeneration = ( } if (!validateInputs()) return; - + setLoadingState({ message: "Generating presentation data...", @@ -74,8 +75,9 @@ export const usePresentationGeneration = ( try { const layoutData = prepareLayoutData(); - + if (!layoutData) return; + trackEvent(MixpanelEvent.Presentation_Prepare_API_Call); const response = await PresentationGenerationApi.presentationPrepare({ presentation_id: presentationId, outlines: outlines, @@ -84,7 +86,7 @@ export const usePresentationGeneration = ( if (response) { dispatch(clearPresentationData()); - router.replace(`/presentation?id=${presentationId}&stream=true`); + router.replace(`/presentation?id=${presentationId}&stream=true`); } } catch (error: any) { console.error('Error In Presentation Generation(prepare).', error); diff --git a/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationStreaming.ts b/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationStreaming.ts index b28fe3ca..23d3c80f 100644 --- a/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationStreaming.ts +++ b/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationStreaming.ts @@ -7,6 +7,7 @@ import { } from "@/store/slices/presentationGeneration"; import { jsonrepair } from "jsonrepair"; import { toast } from "sonner"; +import { MixpanelEvent, trackEvent } from "@/utils/mixpanel"; export const usePresentationStreaming = ( presentationId: string, @@ -26,6 +27,8 @@ export const usePresentationStreaming = ( dispatch(setStreaming(true)); dispatch(clearPresentationData()); + trackEvent(MixpanelEvent.Presentation_Stream_API_Call); + eventSource = new EventSource( `/api/v1/ppt/presentation/stream?presentation_id=${presentationId}` ); @@ -99,7 +102,7 @@ export const usePresentationStreaming = ( setLoading(false); dispatch(setStreaming(false)); setError(true); - break; + break; } }); diff --git a/servers/nextjs/utils/mixpanel.ts b/servers/nextjs/utils/mixpanel.ts index da03f2ec..3f51de71 100644 --- a/servers/nextjs/utils/mixpanel.ts +++ b/servers/nextjs/utils/mixpanel.ts @@ -14,6 +14,8 @@ export enum MixpanelEvent { Outline_Generate_Presentation_Button_Clicked = 'Outline Generate Presentation Button Clicked', Outline_Select_Template_Button_Clicked = 'Outline Select Template Button Clicked', Outline_Add_Slide_Button_Clicked = 'Outline Add Slide Button Clicked', + Presentation_Prepare_API_Call = 'Presentation Prepare API Call', + Presentation_Stream_API_Call = 'Presentation Stream API Call', Group_Layout_Selected_Clicked = 'Group Layout Selected Clicked', Header_Export_PDF_Button_Clicked = 'Header Export PDF Button Clicked', Header_Export_PPTX_Button_Clicked = 'Header Export PPTX Button Clicked',