diff --git a/src/components/story/StoryGenerator.tsx b/src/components/story/StoryGenerator.tsx index aab010e..1ab109a 100644 --- a/src/components/story/StoryGenerator.tsx +++ b/src/components/story/StoryGenerator.tsx @@ -130,6 +130,26 @@ export function StoryGenerator() { if (storyError) throw storyError; + // Tracking da criação da história + const selectedTheme = themes?.find(t => t.id === choices.theme_id)?.title || ''; + const selectedSubject = subjects?.find(s => s.id === choices.subject_id)?.title || ''; + const selectedCharacter = characters?.find(c => c.id === choices.character_id)?.title || ''; + const selectedSetting = settings?.find(s => s.id === choices.setting_id)?.title || ''; + + trackStoryGenerated({ + story_id: story.id, + theme: selectedTheme, + subject: selectedSubject, + character: selectedCharacter, + setting: selectedSetting, + context: choices.context, + generation_time: Date.now() - startTime.current, + word_count: 0, // será atualizado após a geração + student_id: session.user.id, + school_id: session.user.user_metadata?.school_id, + class_id: session.user.user_metadata?.class_id + }); + setGenerationStatus('generating-images'); console.log('Chamando Edge Function com:', story); @@ -153,21 +173,14 @@ export function StoryGenerator() { if (updateError) throw updateError; - // Track story generation - const selectedTheme = themes?.find(t => t.id === choices.theme_id)?.title || ''; - const generationTime = Date.now() - startTime.current; + // Atualizar a contagem de palavras após a geração const wordCount = updatedStory.content.pages.reduce((acc: number, page: { text: string }) => acc + page.text.split(/\s+/).length, 0); - trackStoryGenerated({ + await supabase.from('story_metrics').insert({ story_id: story.id, - theme: selectedTheme, - prompt: JSON.stringify(choices), - generation_time: generationTime, word_count: wordCount, - student_id: session.user.id, - school_id: session.user.user_metadata?.school_id, - class_id: session.user.user_metadata?.class_id + generation_time: Date.now() - startTime.current }); navigate(`/aluno/historias/${story.id}`); diff --git a/src/hooks/useStudentTracking.ts b/src/hooks/useStudentTracking.ts index a40915f..3abb376 100644 --- a/src/hooks/useStudentTracking.ts +++ b/src/hooks/useStudentTracking.ts @@ -3,7 +3,11 @@ import { analytics } from '../lib/analytics'; interface StoryGeneratedProps { story_id: string; theme: string; - prompt: string; + subject: string; + character: string; + setting: string; + context?: string; + prompt?: string; generation_time: number; word_count: number; student_id: string;