11"use client" ;
2- import type { Survey } from "posthog-js" ;
3- import { usePostHog } from "posthog-js/react" ;
2+ import posthog , { type Survey } from "posthog-js" ;
43import { useEffect , useRef } from "react" ;
54import { useSurvey } from "./hooks/use-survey" ;
65import { Navigation } from "./navigation" ;
@@ -19,7 +18,6 @@ export default function DynamicSurvey({
1918 onComplete,
2019 onBack,
2120} : DynamicSurveyProps ) {
22- const posthog = usePostHog ( ) ;
2321 const surveyShown = useRef ( false ) ;
2422
2523 const {
@@ -33,30 +31,30 @@ export default function DynamicSurvey({
3331
3432 // Capture the survey shown event when the survey is loaded
3533 useEffect ( ( ) => {
36- if ( ! ( surveyData && posthog ) || surveyData . questions . length === 0 ) {
34+ if ( ! surveyData || surveyData . questions . length === 0 ) {
3735 return ;
3836 }
3937 if ( ! surveyShown . current ) {
40- posthog ? .capture ( "survey shown" , { $survey_id : surveyData . id } ) ;
38+ posthog . capture ( "survey shown" , { $survey_id : surveyData . id } ) ;
4139 surveyShown . current = true ;
4240 }
43- } , [ surveyData , posthog ] ) ;
41+ } , [ surveyData ] ) ;
4442
4543 // Capture the survey dismissed event when the user navigates away from the survey
4644 useEffect ( ( ) => {
47- if ( ! ( surveyData && posthog ) ) {
45+ if ( ! surveyData ) {
4846 return ;
4947 }
5048
5149 const handleBeforeUnload = ( ) => {
5250 if ( currentQuestionIndex < surveyData . questions . length - 1 ) {
53- posthog ? .capture ( "survey dismissed" , { $survey_id : surveyData . id } ) ;
51+ posthog . capture ( "survey dismissed" , { $survey_id : surveyData . id } ) ;
5452 }
5553 } ;
5654
5755 window . addEventListener ( "beforeunload" , handleBeforeUnload ) ;
5856 return ( ) => window . removeEventListener ( "beforeunload" , handleBeforeUnload ) ;
59- } , [ surveyData , posthog , currentQuestionIndex ] ) ;
57+ } , [ surveyData , currentQuestionIndex ] ) ;
6058
6159 // Handle back button click
6260 const handleBackButton = ( ) => {
0 commit comments