🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(web): simplify onboarding survey (#13600)
annabellscha74face2fe368
diff --git a/web/src/features/onboarding/components/OnboardingSurvey.tsx b/web/src/features/onboarding/components/OnboardingSurvey.tsxindex 73e34d031a..d018d9f606 100644--- a/web/src/features/onboarding/components/OnboardingSurvey.tsx+++ b/web/src/features/onboarding/components/OnboardingSurvey.tsx@@ -1,125 +1,46 @@-import { useCallback, useEffect } from "react";-import type { Path } from "react-hook-form";+import { useCallback } from "react";import { useRouter } from "next/router";import { Button } from "@/src/components/ui/button";-import { Form } from "@/src/components/ui/form";+import {+ Form,+ FormControl,+ FormField,+ FormItem,+ FormLabel,+ FormMessage,+} from "@/src/components/ui/form";+import { Input } from "@/src/components/ui/input";import { LangfuseIcon } from "@/src/components/LangfuseLogo";import { useSurveyForm } from "../hooks/useSurveyForm";-import { SurveyProgress } from "./SurveyProgress";-import { SurveyStep } from "./SurveyStep";import type { SurveyFormData } from "../lib/surveyTypes";export function OnboardingSurvey() {const router = useRouter();- const {- form,- state,- currentQuestion,- isLastStep,- isFirstStep,- goNext,- goBack,- handleAutoAdvance,- handleSubmit,- totalSteps,- } = useSurveyForm();+ const { form, handleSubmit } = useSurveyForm();++ const handleSkipButton = useCallback(() => {+ void router.push("/");+ }, [router]);const onSubmit = useCallback(async (data: SurveyFormData) => {+ if (!data.referralSource?.trim()) {+ handleSkipButton();+ return;+ }+await handleSubmit(data);void router.push("/");},- [handleSubmit, router],+ [handleSkipButton, handleSubmit, router],);- useEffect(() => {- const handleKeyDown = (event: KeyboardEvent) => {- // Cmd+Enter (Mac) or Ctrl+Enter (Windows/Linux) on referralSource step submits the form- if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {- if (currentQuestion?.id === "referralSource") {- event.preventDefault();- form.handleSubmit(onSubmit)();- return;- }- }-- // Regular Enter advances to next step (existing behavior)- if (event.key === "Enter" && !isLastStep) {- if (currentQuestion?.type !== "text") {- goNext();- }- }- };-- document.addEventListener("keydown", handleKeyDown);- return () => {- document.removeEventListener("keydown", handleKeyDown);- };- }, [- isLastStep,- currentQuestion?.type,- currentQuestion?.id,- goNext,- form,- onSubmit,- ]);-- // Auto-focus the first form control of the current step- useEffect(() => {- if (!currentQuestion?.id) return;- const field = currentQuestion.id as Path<SurveyFormData>;- const raf = requestAnimationFrame(() => {- try {- form.setFocus(field, { shouldSelect: true });- } catch {- // ignore if the control cannot be focused- }- });- return () => cancelAnimationFrame(raf);- }, [currentQuestion?.id, form]);-- // Determine labeling/behavior of the primary (right) button- const roleValue = form.watch("role");- const signupReasonValue = form.watch("signupReason");- const referralSourceValue = form.watch("referralSource");-- const currentFieldId = currentQuestion?.id as- | keyof SurveyFormData- | undefined;- const currentValue = currentFieldId- ? form.watch(currentFieldId as Path<SurveyFormData>)- : undefined;+ const currentValue = form.watch("referralSource");const isEmpty = (v: unknown) =>v == null || (typeof v === "string" && v.trim() === "");- const allFields = {- role: roleValue,- signupReason: signupReasonValue,- referralSource: referralSourceValue,- } as const;-const currentEmpty = isEmpty(currentValue);- const otherTwoEmpty = Object.entries(allFields)- .filter(([key]) => key !== currentFieldId)- .every(([, v]) => isEmpty(v));- // showSkip: ghost button labeled "Skip" when skipping is the intended action- const showSkip = isLastStep ? currentEmpty && otherTwoEmpty : currentEmpty;-- const handleSkipButton = () => {- if (isLastStep) {- void router.push("/");- } else {- goNext();- }- };-- const handleSubmitButton = () => {- if (isLastStep) {- form.handleSubmit(onSubmit)();- } else {- goNext();- }- };+ const showSkip = currentEmpty;return (<div className="flex flex-1 flex-col py-6 sm:min-h-full sm:justify-start sm:px-6 sm:py-12 lg:px-8">@@ -132,19 +53,37 @@ export function OnboardingSurvey() {<formclassName="flex h-full flex-col"onSubmit={form.handleSubmit(onSubmit)}+ onKeyDown={(event) => {+ if (event.key === "Enter" && currentEmpty) {+ event.preventDefault();+ handleSkipButton();+ }+ }}><div className="flex-1">- {currentQuestion && (- <SurveyStep- question={currentQuestion}- control={form.control}- onAutoAdvance={handleAutoAdvance}- isLast={isLastStep}- />- )}+ <FormField+ control={form.control}+ name="referralSource"+ render={({ field }) => (+ <FormItem className="flex flex-col gap-2">+ <FormLabel className="text-xl font-semibold">+ Where did you hear about us?+ </FormLabel>+ <FormControl>+ <Input+ autoFocus+ placeholder="Colleague, Word of Mouth, X, Reddit, Event"+ {...field}+ value={field.value ?? ""}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ /></div>- <div className="flex flex-row-reverse items-center justify-between pt-6">+ <div className="flex justify-end pt-6">{showSkip ? (<Buttontype="button"@@ -155,35 +94,10 @@ export function OnboardingSurvey() {Skip</Button>) : (- <Button- type="button"- onClick={handleSubmitButton}- variant="default"- className="w-20"- >- {isLastStep ? "Finish" : "Next"}+ <Button type="submit" variant="default" className="w-20">+ Finish</Button>)}-- <div className="basis-40 px-4">- <SurveyProgress- currentStep={state.currentStep}- totalSteps={totalSteps}- />- </div>-- {!isFirstStep ? (- <Button- type="button"- variant="ghost"- onClick={goBack}- className="w-20"- >- Back- </Button>- ) : (- <div className="w-20" />- )}</div></form></Form>diff --git a/web/src/features/onboarding/components/SurveyProgress.tsx b/web/src/features/onboarding/components/SurveyProgress.tsxdeleted file mode 100644index b0341a76a1..0000000000--- a/web/src/features/onboarding/components/SurveyProgress.tsx+++ /dev/null@@ -1,27 +0,0 @@-import { cn } from "@/src/utils/tailwind";--interface SurveyProgressProps {- currentStep: number;- totalSteps: number;- className?: string;-}--export function SurveyProgress({- currentStep,- totalSteps,- className,-}: SurveyProgressProps) {- return (- <div className={cn("flex w-full gap-3", className)}>- {Array.from({ length: totalSteps }).map((_, index) => (- <div- key={index}- className={cn(- "h-1 flex-1 rounded-full transition-colors duration-300",- index <= currentStep ? "bg-primary" : "bg-muted",- )}- />- ))}- </div>- );-}diff --git a/web/src/features/onboarding/components/SurveyStep.tsx b/web/src/features/onboarding/components/SurveyStep.tsxdeleted file mode 100644index 873af6eb6c..0000000000--- a/web/src/features/onboarding/components/SurveyStep.tsx+++ /dev/null@@ -1,119 +0,0 @@-import {- FormControl,- FormField,- FormItem,- FormLabel,- FormMessage,-} from "@/src/components/ui/form";-import { RadioGroup, RadioGroupItem } from "@/src/components/ui/radio-group";-import { Textarea } from "@/src/components/ui/textarea";-import { Input } from "@/src/components/ui/input";-import { Label } from "@/src/components/ui/label";-import type { Control, Path } from "react-hook-form";-import type { SurveyQuestion, SurveyFormData } from "../lib/surveyTypes";--const AUTO_ADVANCE_DELAY = 300;--interface SurveyStepProps {- question: SurveyQuestion;- control: Control<SurveyFormData>;- onAutoAdvance?: (selectedValue?: string) => void;- isLast?: boolean;-}--export function SurveyStep({- question,- control,- onAutoAdvance,- isLast = false,-}: SurveyStepProps) {- const fieldName = question.id as keyof SurveyFormData;-- const handleAutoAdvanceWithTimeout = (selectedValue?: string) => {- if (onAutoAdvance) {- // For signupReason question, ignore isLast and let the hook decide- // For other questions, respect the isLast prop- const shouldAutoAdvance = question.id === "signupReason" || !isLast;-- if (shouldAutoAdvance) {- setTimeout(() => {- onAutoAdvance(selectedValue);- }, AUTO_ADVANCE_DELAY);- }- }- };-- if (question.type === "radio") {- return (- <FormField- key={fieldName}- control={control}- name={fieldName as Path<SurveyFormData>}- render={({ field }) => (- <FormItem className="flex flex-col gap-2">- <FormLabel className="text-xl font-semibold">- {question.question}- </FormLabel>- <FormControl>- <RadioGroup- name={field.name}- ref={field.ref}- onValueChange={(value) => {- field.onChange(value);- setTimeout(() => {- handleAutoAdvanceWithTimeout(value);- }, 0);- }}- value={field.value as string}- className="grid gap-3"- >- {question.options.map((option) => (- <Label- key={option}- htmlFor={option}- className="border-border hover:bg-muted/50 flex flex-1 cursor-pointer items-center gap-3 rounded-lg border p-3 text-sm leading-none font-medium transition-colors peer-disabled:cursor-not-allowed peer-disabled:opacity-70"- >- <RadioGroupItem value={option} id={option} />- <span className="flex-1">{option}</span>- </Label>- ))}- </RadioGroup>- </FormControl>- <FormMessage />- </FormItem>- )}- />- );- }-- if (question.type === "text") {- return (- <FormField- key={fieldName}- control={control}- name={fieldName as Path<SurveyFormData>}- render={({ field }) => (- <FormItem className="flex flex-col gap-2">- <FormLabel className="text-xl font-semibold">- {question.question}- </FormLabel>- <FormControl>- {question.id === "referralSource" ? (- <Input placeholder={question.placeholder} {...field} />- ) : (- <Textarea- placeholder={question.placeholder}- className="min-h-[170px] resize-none"- {...field}- />- )}- </FormControl>- <FormMessage />- </FormItem>- )}- />- );- }-- return null;-}diff --git a/web/src/features/onboarding/hooks/useSurveyForm.ts b/web/src/features/onboarding/hooks/useSurveyForm.tsindex cc3d15c245..9fdd9daa04 100644--- a/web/src/features/onboarding/hooks/useSurveyForm.ts+++ b/web/src/features/onboarding/hooks/useSurveyForm.ts@@ -1,8 +1,6 @@import { useForm } from "react-hook-form";-import { useReducer, useCallback } from "react";+import { useCallback } from "react";import type { SurveyFormData } from "../lib/surveyTypes";-import { surveyReducer, initialSurveyState } from "../lib/surveyReducer";-import { SURVEY_QUESTIONS, TOTAL_STEPS } from "../lib/questions";import { api } from "@/src/utils/api";import { SurveyName } from "@prisma/client";import { useSession } from "next-auth/react";@@ -10,7 +8,6 @@ import { showErrorToast } from "@/src/features/notifications/showErrorToast";import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";export function useSurveyForm() {- const [state, dispatch] = useReducer(surveyReducer, initialSurveyState);const { data: session } = useSession();const createSurveyMutation = api.surveys.create.useMutation({onSuccess: () => {@@ -29,59 +26,13 @@ export function useSurveyForm() {const form = useForm<SurveyFormData>({defaultValues: {- role: undefined,- signupReason: undefined,referralSource: undefined,},});- // Check if we should skip the referral source question- const signupReason = form.watch("signupReason");- const shouldSkipReferralQuestion = signupReason === "Invited by team";-- // Get effective total steps (skip last question if invited by team)- const effectiveTotalSteps = shouldSkipReferralQuestion- ? TOTAL_STEPS - 1- : TOTAL_STEPS;-- // Get current question, but skip the referral question if "Invited by team" is selected- const currentQuestion = SURVEY_QUESTIONS[state.currentStep];-- const isLastStep = state.currentStep === effectiveTotalSteps - 1;- const isFirstStep = state.currentStep === 0;-- const goNext = useCallback(() => {- dispatch({ type: "next" });- }, []);-- const goBack = useCallback(() => {- dispatch({ type: "back" });- }, []);-- const goToStep = useCallback((step: number) => {- dispatch({ type: "goToStep", step });- }, []);-- const handleAutoAdvance = useCallback(- (selectedValue?: string) => {- // Special case: if we're on step 1 (signup reason) and "Invited by team" was selected,- // don't auto-advance, let the user click "Finish"- if (state.currentStep === 1 && selectedValue === "Invited by team") {- return;- }-- // For all other cases, advance to next step- goNext();- },- [state.currentStep, goNext],- );-const handleSubmit = useCallback(async (data: SurveyFormData) => {const transformedResponse: Record<string, string> = {};- if (data.role) transformedResponse["role"] = data.role;- if (data.signupReason)- transformedResponse["signupReason"] = data.signupReason;if (data.referralSource)transformedResponse["referralSource"] = data.referralSource.trim();@@ -101,15 +52,6 @@ export function useSurveyForm() {return {form,- state,- currentQuestion,- isLastStep,- isFirstStep,- goNext,- goBack,- goToStep,- handleAutoAdvance,handleSubmit,- totalSteps: effectiveTotalSteps,};}diff --git a/web/src/features/onboarding/lib/questions.ts b/web/src/features/onboarding/lib/questions.tsdeleted file mode 100644index 56173d802e..0000000000--- a/web/src/features/onboarding/lib/questions.ts+++ /dev/null@@ -1,38 +0,0 @@-import type { SurveyQuestion } from "./surveyTypes";--export const SURVEY_QUESTIONS: SurveyQuestion[] = [- {- id: "role",- type: "radio",- question: "What describes you best?",- options: [- "Software Engineer",- "ML Engineer / Data Scientist",- "Product Manager",- "Domain Expert",- "Executive or Manager",- "Other",- ],- },- {- id: "signupReason",- type: "radio",- question: "Why are you signing up?",- options: [- "Invited by team",- "Just looking around",- "Evaluating / Testing Langfuse",- "Start using Langfuse",- "Migrating from other solution",- "Migrating from self-hosted",- ],- },- {- id: "referralSource",- type: "text",- question: "Where did you hear about us?",- placeholder: "GitHub, X, Reddit, colleague etc.",- },-];--export const TOTAL_STEPS = SURVEY_QUESTIONS.length;diff --git a/web/src/features/onboarding/lib/surveyReducer.ts b/web/src/features/onboarding/lib/surveyReducer.tsdeleted file mode 100644index 80a1b854f1..0000000000--- a/web/src/features/onboarding/lib/surveyReducer.ts+++ /dev/null@@ -1,31 +0,0 @@-import type { SurveyState, SurveyAction } from "./surveyTypes";-import { TOTAL_STEPS } from "./questions";--export const initialSurveyState: SurveyState = {- currentStep: 0,-};--export function surveyReducer(- state: SurveyState,- action: SurveyAction,-): SurveyState {- switch (action.type) {- case "next":- return {- ...state,- currentStep: Math.min(state.currentStep + 1, TOTAL_STEPS - 1),- };- case "back":- return {- ...state,- currentStep: Math.max(state.currentStep - 1, 0),- };- case "goToStep":- return {- ...state,- currentStep: Math.max(0, Math.min(action.step, TOTAL_STEPS - 1)),- };- default:- return state;- }-}diff --git a/web/src/features/onboarding/lib/surveyTypes.ts b/web/src/features/onboarding/lib/surveyTypes.tsindex 8c7cc1441b..d47a9cd03f 100644--- a/web/src/features/onboarding/lib/surveyTypes.ts+++ b/web/src/features/onboarding/lib/surveyTypes.ts@@ -1,44 +1,3 @@-export type QuestionType = "radio" | "text";--export interface BaseQuestion {- id: string;- type: QuestionType;- question: string;- required?: boolean;-}--export interface RadioQuestion extends BaseQuestion {- type: "radio";- options: string[];-}--export interface TextQuestion extends BaseQuestion {- type: "text";- placeholder?: string;-}--export type SurveyQuestion = RadioQuestion | TextQuestion;--export interface SurveyState {- currentStep: number;-}--export type SurveyAction =- | { type: "next" }- | { type: "back" }- | { type: "goToStep"; step: number };-export interface SurveyFormData {- role?: string;- signupReason?: string;referralSource?: string;}--export interface SurveyStepProps {- question: SurveyQuestion;- value: unknown;- onChange: (value: unknown) => void;- onNext?: () => void;- showNext?: boolean;- isLast?: boolean;-}diff --git a/web/src/pages/onboarding.tsx b/web/src/pages/onboarding.tsxindex 60098873e0..7fad2ae08b 100644--- a/web/src/pages/onboarding.tsx+++ b/web/src/pages/onboarding.tsx@@ -1,5 +1,4 @@-// This page is currently only shown to Langfuse cloud users.-// It might be expanded to everyone in the future when it does not only ask for the referral source.+// This page is part of the cloud signup flow and can also be opened directly for local testing.import Head from "next/head";import { OnboardingSurvey } from "@/src/features/onboarding/components/OnboardingSurvey";