Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(cloud): new onboarding survey to better understand our users (#8374)

Leo Weigand07469c928d47
diff --git a/packages/shared/prisma/generated/types.ts b/packages/shared/prisma/generated/types.ts
index 14940064bf..6f65f1f704 100644
--- a/packages/shared/prisma/generated/types.ts
+++ b/packages/shared/prisma/generated/types.ts
@@ -150,6 +150,11 @@ export const ActionExecutionStatus = {
} as const;
export type ActionExecutionStatus =
(typeof ActionExecutionStatus)[keyof typeof ActionExecutionStatus];
+export const SurveyName = {
+ ORG_ONBOARDING: "org_onboarding",
+ USER_ONBOARDING: "user_onboarding",
+} as const;
+export type SurveyName = (typeof SurveyName)[keyof typeof SurveyName];
export type Account = {
id: string;
user_id: string;
@@ -749,6 +754,15 @@ export type SsoConfig = {
auth_provider: string;
auth_config: unknown | null;
};
+export type Survey = {
+ id: string;
+ created_at: Generated<Timestamp>;
+ survey_name: SurveyName;
+ response: unknown;
+ user_id: string | null;
+ user_email: string | null;
+ org_id: string | null;
+};
export type TableViewPreset = {
id: string;
created_at: Generated<Timestamp>;
@@ -858,6 +872,7 @@ export type DB = {
Session: Session;
slack_integrations: SlackIntegration;
sso_configs: SsoConfig;
+ surveys: Survey;
table_view_presets: TableViewPreset;
trace_media: TraceMedia;
trace_sessions: TraceSession;
diff --git a/packages/shared/prisma/migrations/20250808081624_add_surveys_table/migration.sql b/packages/shared/prisma/migrations/20250808081624_add_surveys_table/migration.sql
new file mode 100644
index 0000000000..4794e1bbc5
--- /dev/null
+++ b/packages/shared/prisma/migrations/20250808081624_add_surveys_table/migration.sql
@@ -0,0 +1,24 @@
+-- CreateEnum
+CREATE TYPE "SurveyName" AS ENUM ('org_onboarding', 'user_onboarding');
+
+-- CreateTable
+CREATE TABLE "surveys" (
+ "id" TEXT NOT NULL,
+ "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ "survey_name" "SurveyName" NOT NULL,
+ "response" JSONB NOT NULL,
+ "user_id" TEXT,
+ "user_email" TEXT,
+ "org_id" TEXT,
+
+ CONSTRAINT "surveys_pkey" PRIMARY KEY ("id")
+);
+
+-- AddForeignKey
+ALTER TABLE "surveys" ADD CONSTRAINT "surveys_org_id_fkey" FOREIGN KEY ("org_id") REFERENCES "organizations"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "surveys" ADD CONSTRAINT "surveys_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+
+-- RenameIndex
+ALTER INDEX "annotation_queue_assignments_project_id_queue_id_key" RENAME TO "annotation_queue_assignments_project_id_queue_id_user_id_key";
diff --git a/packages/shared/prisma/schema.prisma b/packages/shared/prisma/schema.prisma
index f9deb05b77..61d50ccc97 100644
--- a/packages/shared/prisma/schema.prisma
+++ b/packages/shared/prisma/schema.prisma
@@ -89,6 +89,7 @@ model User {
tableViewPresetCreated TableViewPreset[] @relation("CreatedByUser")
tableViewPresetUpdated TableViewPreset[] @relation("UpdatedByUser")
annotationQueueAssignment AnnotationQueueAssignment[]
+ surveys Survey[]
@@map("users")
}
@@ -113,6 +114,7 @@ model Organization {
projects Project[]
MembershipInvitation MembershipInvitation[]
ApiKey ApiKey[]
+ surveys Survey[]
@@map("organizations")
}
@@ -1397,3 +1399,24 @@ model PendingDeletion {
@@index([objectId, object])
@@map("pending_deletions")
}
+
+model Survey {
+ id String @id @default(cuid())
+ createdAt DateTime @default(now()) @map("created_at")
+ surveyName SurveyName @map("survey_name")
+ response Json
+ userId String? @map("user_id")
+ userEmail String? @map("user_email")
+ orgId String? @map("org_id")
+ org Organization? @relation(fields: [orgId], references: [id], onDelete: Cascade)
+ user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
+
+ @@map("surveys")
+}
+
+enum SurveyName {
+ ORG_ONBOARDING @map("org_onboarding")
+ USER_ONBOARDING @map("user_onboarding")
+
+ @@map("SurveyName")
+}
diff --git a/web/src/components/ui/radio-group.tsx b/web/src/components/ui/radio-group.tsx
index ab86655d5c..21a5a5acbe 100644
--- a/web/src/components/ui/radio-group.tsx
+++ b/web/src/components/ui/radio-group.tsx
@@ -3,7 +3,6 @@
import * as React from "react";
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
import { cn } from "@/src/utils/tailwind";
-import { Check } from "lucide-react";
const RadioGroup = React.forwardRef<
React.ElementRef<typeof RadioGroupPrimitive.Root>,
@@ -33,7 +32,7 @@ const RadioGroupItem = React.forwardRef<
{...props}
>
<RadioGroupPrimitive.Indicator className="flex items-center justify-center">
- <Check className="h-3.5 w-3.5 fill-primary" />
+ <div className="h-2 w-2 rounded-full bg-primary" />
</RadioGroupPrimitive.Indicator>
</RadioGroupPrimitive.Item>
);
diff --git a/web/src/features/onboarding/components/OnboardingSurvey.tsx b/web/src/features/onboarding/components/OnboardingSurvey.tsx
new file mode 100644
index 0000000000..d87c96b20f
--- /dev/null
+++ b/web/src/features/onboarding/components/OnboardingSurvey.tsx
@@ -0,0 +1,132 @@
+import { useCallback, useEffect } from "react";
+import { useRouter } from "next/router";
+import { Button } from "@/src/components/ui/button";
+import { Form } from "@/src/components/ui/form";
+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 onSubmit = useCallback(
+ async (data: SurveyFormData) => {
+ await handleSubmit(data);
+ void router.push("/");
+ },
+ [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,
+ ]);
+
+ const handleSkip = () => {
+ if (isLastStep) {
+ form.handleSubmit(onSubmit)();
+ } else {
+ goNext();
+ }
+ };
+
+ 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">
+ <div className="flex items-center justify-center gap-2 sm:mx-auto sm:w-full sm:max-w-md">
+ <LangfuseIcon className="h-8 w-8" />
+ </div>
+
+ <div className="mt-6 rounded-lg bg-background px-6 py-6 shadow sm:mx-auto sm:mt-16 sm:w-full sm:max-w-[480px] sm:px-12 sm:py-10">
+ <Form {...form}>
+ <form
+ className="flex h-full flex-col"
+ onSubmit={form.handleSubmit(onSubmit)}
+ >
+ <div className="flex-1">
+ {currentQuestion && (
+ <SurveyStep
+ question={currentQuestion}
+ control={form.control}
+ onAutoAdvance={handleAutoAdvance}
+ isLast={isLastStep}
+ />
+ )}
+ </div>
+
+ <div className="flex flex-row-reverse items-center justify-between pt-6">
+ <Button
+ type="button"
+ onClick={handleSkip}
+ variant={isLastStep ? "default" : "ghost"}
+ className="w-20"
+ >
+ {isLastStep ? "Finish" : "Skip"}
+ </Button>
+
+ <div className="basis-[10rem] 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>
+ </div>
+ </div>
+ );
+}
diff --git a/web/src/features/onboarding/components/SurveyProgress.tsx b/web/src/features/onboarding/components/SurveyProgress.tsx
new file mode 100644
index 0000000000..b0341a76a1
--- /dev/null
+++ b/web/src/features/onboarding/components/SurveyProgress.tsx
@@ -0,0 +1,27 @@
+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.tsx
new file mode 100644
index 0000000000..0cc771f7bd
--- /dev/null
+++ b/web/src/features/onboarding/components/SurveyStep.tsx
@@ -0,0 +1,112 @@
+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 { 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
+ 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="flex flex-1 cursor-pointer items-center gap-3 rounded-lg border border-border p-3 text-sm font-medium leading-none transition-colors hover:bg-muted/50 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>
+ <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.ts
new file mode 100644
index 0000000000..1dbbf0b3c2
--- /dev/null
+++ b/web/src/features/onboarding/hooks/useSurveyForm.ts
@@ -0,0 +1,115 @@
+import { useForm } from "react-hook-form";
+import { useReducer, 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";
+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: () => {
+ showSuccessToast({
+ title: "Survey submitted",
+ description: "Thank you for your feedback!",
+ });
+ },
+ onError: (error) => {
+ showErrorToast(
+ "Failed to submit survey",
+ error.message || "Please try again later.",
+ );
+ },
+ });
+
+ 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();
+
+ try {
+ await createSurveyMutation.mutateAsync({
+ surveyName: SurveyName.USER_ONBOARDING,
+ response: transformedResponse,
+ orgId: session?.user?.organizations?.[0]?.id,
+ });
+ } catch (error) {
+ // Error handling is done in the mutation callbacks
+ // This catch block is for any additional error handling if needed
+ }
+ },
+ [createSurveyMutation, session],
+ );
+
+ 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.ts
new file mode 100644
index 0000000000..676cfe9702
--- /dev/null
+++ b/web/src/features/onboarding/lib/questions.ts
@@ -0,0 +1,39 @@
+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:
+ "We're curious to know how you discovered the project! Thanks for sharing.",
+ },
+];
+
+export const TOTAL_STEPS = SURVEY_QUESTIONS.length;
diff --git a/web/src/features/onboarding/lib/surveyReducer.ts b/web/src/features/onboarding/lib/surveyReducer.ts
new file mode 100644
index 0000000000..80a1b854f1
--- /dev/null
+++ b/web/src/features/onboarding/lib/surveyReducer.ts
@@ -0,0 +1,31 @@
+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.ts
new file mode 100644
index 0000000000..8c7cc1441b
--- /dev/null
+++ b/web/src/features/onboarding/lib/surveyTypes.ts
@@ -0,0 +1,44 @@
+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/features/organizations/components/NewOrganizationForm.tsx b/web/src/features/organizations/components/NewOrganizationForm.tsx
index 8094219d76..52a92bb473 100644
--- a/web/src/features/organizations/components/NewOrganizationForm.tsx
+++ b/web/src/features/organizations/components/NewOrganizationForm.tsx
@@ -9,12 +9,21 @@ import {
FormItem,
FormLabel,
FormMessage,
+ FormDescription,
} from "@/src/components/ui/form";
import { Input } from "@/src/components/ui/input";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/src/components/ui/select";
import { api } from "@/src/utils/api";
import { useSession } from "next-auth/react";
import { organizationNameSchema } from "@/src/features/organizations/utils/organizationNameSchema";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
+import { SurveyName } from "@prisma/client";
export const NewOrganizationForm = ({
onSuccess,
@@ -27,12 +36,15 @@ export const NewOrganizationForm = ({
resolver: zodResolver(organizationNameSchema),
defaultValues: {
name: "",
+ type: undefined,
+ size: undefined,
},
});
const capture = usePostHogClientCapture();
const createOrgMutation = api.organizations.create.useMutation({
onError: (error) => form.setError("name", { message: error.message }),
});
+ const createSurveyMutation = api.surveys.create.useMutation();
function onSubmit(values: z.infer<typeof organizationNameSchema>) {
capture("organizations:new_form_submit");
@@ -40,7 +52,28 @@ export const NewOrganizationForm = ({
.mutateAsync({
name: values.name,
})
- .then((org) => {
+ .then(async (org) => {
+ // Submit survey with organization data if type is provided
+ if (values.type) {
+ const surveyResponse: Record<string, string> = {
+ type: values.type,
+ };
+ if (values.size) {
+ surveyResponse.size = values.size;
+ }
+
+ try {
+ await createSurveyMutation.mutateAsync({
+ surveyName: SurveyName.ORG_ONBOARDING,
+ response: surveyResponse,
+ orgId: org.id,
+ });
+ } catch (error) {
+ console.error("Failed to submit survey:", error);
+ // Continue with organization creation even if survey fails
+ }
+ }
+
void updateSession();
onSuccess(org.id);
form.reset();
@@ -50,6 +83,8 @@ export const NewOrganizationForm = ({
});
}
+ const watchedType = form.watch("type");
+
return (
<Form {...form}>
<form
@@ -75,6 +110,68 @@ export const NewOrganizationForm = ({
</FormItem>
)}
/>
+ <FormField
+ control={form.control}
+ name="type"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Type</FormLabel>
+ <FormDescription>
+ What would best describe your organization?
+ </FormDescription>
+ <Select onValueChange={field.onChange} defaultValue={field.value}>
+ <FormControl>
+ <SelectTrigger>
+ <SelectValue placeholder="Select organization type" />
+ </SelectTrigger>
+ </FormControl>
+ <SelectContent>
+ <SelectItem value="Personal">Personal</SelectItem>
+ <SelectItem value="Educational">Educational</SelectItem>
+ <SelectItem value="Company">Company</SelectItem>
+ <SelectItem value="Startup">Startup</SelectItem>
+ <SelectItem value="Agency">Agency</SelectItem>
+ <SelectItem value="N/A">N/A</SelectItem>
+ </SelectContent>
+ </Select>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ {(watchedType === "Company" ||
+ watchedType === "Startup" ||
+ watchedType === "Agency") && (
+ <FormField
+ control={form.control}
+ name="size"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>{watchedType} size</FormLabel>
+ <FormDescription>
+ How many people are in your {watchedType}?
+ </FormDescription>
+ <Select
+ onValueChange={field.onChange}
+ defaultValue={field.value}
+ >
+ <FormControl>
+ <SelectTrigger>
+ <SelectValue placeholder="Select organization size" />
+ </SelectTrigger>
+ </FormControl>
+ <SelectContent>
+ <SelectItem value="1-10">1-10</SelectItem>
+ <SelectItem value="10-49">10-49</SelectItem>
+ <SelectItem value="50-99">50-99</SelectItem>
+ <SelectItem value="100-299">100-299</SelectItem>
+ <SelectItem value="More than 300">More than 300</SelectItem>
+ </SelectContent>
+ </Select>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ )}
<Button type="submit" loading={createOrgMutation.isLoading}>
Create
</Button>
diff --git a/web/src/features/organizations/utils/organizationNameSchema.ts b/web/src/features/organizations/utils/organizationNameSchema.ts
index 5449e5db66..11955850d7 100644
--- a/web/src/features/organizations/utils/organizationNameSchema.ts
+++ b/web/src/features/organizations/utils/organizationNameSchema.ts
@@ -1,9 +1,28 @@
import { StringNoHTML } from "@langfuse/shared";
import * as z from "zod/v4";
+const organizationTypeOptions = [
+ "Personal",
+ "Educational",
+ "Company",
+ "Startup",
+ "Agency",
+ "N/A",
+] as const;
+
+const organizationSizeOptions = [
+ "1-10",
+ "10-49",
+ "50-99",
+ "100-299",
+ "More than 300",
+] as const;
+
export const organizationNameSchema = z.object({
name: StringNoHTML.min(3, "Must have at least 3 characters").max(
60,
"Must have at most 60 characters",
),
+ type: z.enum(organizationTypeOptions).optional(),
+ size: z.enum(organizationSizeOptions).optional(),
});
diff --git a/web/src/pages/onboarding.tsx b/web/src/pages/onboarding.tsx
index 9aa3c4f85f..60098873e0 100644
--- a/web/src/pages/onboarding.tsx
+++ b/web/src/pages/onboarding.tsx
@@ -1,93 +1,16 @@
// 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.
-import { useForm } from "react-hook-form";
-import { zodResolver } from "@hookform/resolvers/zod";
-import { z } from "zod/v4";
-import { Button } from "@/src/components/ui/button";
-import {
- Form,
- FormControl,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
-} from "@/src/components/ui/form";
-import { usePostHog } from "posthog-js/react";
-import { useRouter } from "next/router";
-import { LangfuseIcon } from "@/src/components/LangfuseLogo";
-import { Textarea } from "@/src/components/ui/textarea";
-
-const referralSourceSchema = z.object({
- referralSource: z.string().optional(),
-});
-
-export default function ReferralSource() {
- const posthog = usePostHog();
- const router = useRouter();
- const form = useForm({
- resolver: zodResolver(referralSourceSchema),
- defaultValues: {
- referralSource: "",
- },
- });
-
- function onSubmit(values: z.infer<typeof referralSourceSchema>) {
- if (values.referralSource && values.referralSource !== "") {
- posthog.capture("survey sent", {
- $survey_id: "018ade05-4d8c-0000-36b7-fc390b221590",
- $survey_name: "Referral source",
- $survey_response: values.referralSource,
- });
- }
- void router.push("/");
- }
+import Head from "next/head";
+import { OnboardingSurvey } from "@/src/features/onboarding/components/OnboardingSurvey";
+export default function OnboardingPage() {
return (
- <div className="flex flex-1 flex-col py-6 sm:min-h-full sm:justify-center sm:px-6 sm:py-12 lg:px-8">
- <div className="sm:mx-auto sm:w-full sm:max-w-md">
- <LangfuseIcon className="mx-auto" />
- <h2 className="mt-4 text-center text-2xl font-bold leading-9 tracking-tight text-primary">
- Welcome to Langfuse
- </h2>
- </div>
- <div className="mt-14 bg-background px-6 py-10 shadow sm:mx-auto sm:w-full sm:max-w-[480px] sm:rounded-lg sm:px-12">
- <Form {...form}>
- <form
- className="space-y-6"
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
- onSubmit={form.handleSubmit(onSubmit)}
- >
- <FormField
- control={form.control}
- name="referralSource"
- render={({ field }) => (
- <FormItem>
- <FormLabel>
- Where did you hear about us?{" "}
- <span className="font-normal">(optional)</span>
- </FormLabel>
- <FormControl>
- <Textarea
- placeholder="We're curious to know how you discovered the project! Thanks for sharing."
- {...field}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- <Button
- type="submit"
- variant={form.formState.isDirty ? "default" : "secondary"}
- className="w-full"
- loading={form.formState.isSubmitting}
- >
- {form.formState.isDirty ? "Continue" : "Skip"}
- </Button>
- </form>
- </Form>
- </div>
- </div>
+ <>
+ <Head>
+ <title>Onboarding | Langfuse</title>
+ </Head>
+ <OnboardingSurvey />
+ </>
);
}
diff --git a/web/src/server/api/root.ts b/web/src/server/api/root.ts
index 864e32ed0e..1c10f56651 100644
--- a/web/src/server/api/root.ts
+++ b/web/src/server/api/root.ts
@@ -43,6 +43,7 @@ import { defaultEvalModelRouter } from "@/src/features/evals/server/defaultEvalM
import { plainRouter } from "@/src/features/support-chat/trpc/plain";
import { slackRouter } from "@/src/features/slack/server/router";
import { queueAssignmentRouter } from "@/src/features/annotation-queues/server/annotationQueueAssignments";
+import { surveysRouter } from "@/src/server/api/routers/surveys";
/**
* This is the primary router for your server.
@@ -94,6 +95,7 @@ export const appRouter = createTRPCRouter({
automations: automationsRouter,
slack: slackRouter,
plain: plainRouter,
+ surveys: surveysRouter,
});
// export type definition of API
diff --git a/web/src/server/api/routers/surveys.ts b/web/src/server/api/routers/surveys.ts
new file mode 100644
index 0000000000..2d5c47e1d9
--- /dev/null
+++ b/web/src/server/api/routers/surveys.ts
@@ -0,0 +1,40 @@
+import { z } from "zod/v4";
+import { createTRPCRouter, protectedProcedure } from "@/src/server/api/trpc";
+import { TRPCError } from "@trpc/server";
+import { SurveyName } from "@prisma/client";
+import { logger } from "@langfuse/shared/src/server";
+
+const surveyResponseSchema = z.object({
+ surveyName: z.nativeEnum(SurveyName),
+ response: z.record(z.string(), z.string()),
+ orgId: z.string().optional(),
+});
+
+export const surveysRouter = createTRPCRouter({
+ create: protectedProcedure
+ .input(surveyResponseSchema)
+ .mutation(async ({ ctx, input }) => {
+ try {
+ const survey = await ctx.prisma.survey.create({
+ data: {
+ surveyName: input.surveyName,
+ response: input.response,
+ userId: ctx.session.user.id,
+ userEmail: ctx.session.user.email ?? undefined,
+ orgId: input.orgId,
+ },
+ });
+
+ return survey;
+ } catch (error) {
+ logger.error("Failed to call surveys.create", error);
+ if (error instanceof TRPCError) {
+ throw error;
+ }
+ throw new TRPCError({
+ code: "INTERNAL_SERVER_ERROR",
+ message: "Failed to save survey response",
+ });
+ }
+ }),
+});