Skip to content

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

feat(web): ask new users what they will use Langfuse for (#18356)

Abdallah Othman25edc58f71c9
diff --git a/web/src/__tests__/server/onboarding-router.servertest.ts b/web/src/__tests__/server/onboarding-router.servertest.ts
index 97c9a495a8..4e82a4ac05 100644
--- a/web/src/__tests__/server/onboarding-router.servertest.ts
+++ b/web/src/__tests__/server/onboarding-router.servertest.ts
@@ -139,6 +139,7 @@ describe("onboarding router", () => {
expect(result).toEqual({
redirectTo: `/project/${starterProjectId}/traces`,
+ surveyCreated: true,
});
expect(organizationMembership.role).toBe(Role.OWNER);
expect(organizationMembership.organization.projects).toHaveLength(1);
@@ -171,6 +172,7 @@ describe("onboarding router", () => {
expect(result).toEqual({
redirectTo: "/setup",
+ surveyCreated: true,
});
});
@@ -224,6 +226,7 @@ describe("onboarding router", () => {
expect(result).toEqual({
redirectTo: `/project/${project.id}`,
+ surveyCreated: true,
});
const projectCount = await prisma.project.count({
@@ -311,6 +314,7 @@ describe("onboarding router", () => {
expect(result).toEqual({
redirectTo: `/project/${project.id}`,
+ surveyCreated: true,
});
const organizationMemberships =
@@ -435,6 +439,7 @@ describe("onboarding router", () => {
);
expect(result).toEqual({
redirectTo: `/project/${starterOrganizationMembership?.organization.projects[0]?.id}/traces`,
+ surveyCreated: true,
});
});
@@ -478,6 +483,90 @@ describe("onboarding router", () => {
expect(result).toEqual({
redirectTo: createProjectRoute(organization.id),
+ surveyCreated: true,
+ });
+ });
+ describe("build intent answers", () => {
+ const createCallerForNewUser = async () => {
+ const userId = randomUUID();
+ const email = `build-intent-${userId}@example.com`;
+ createdUserIds.push(userId);
+ await prisma.user.create({ data: { id: userId, email } });
+
+ const caller = appRouter.createCaller({
+ ...createInnerTRPCContext({
+ session: makeSession({ userId, email }),
+ headers: {},
+ }),
+ prisma,
+ });
+
+ return { caller, userId };
+ };
+
+ it("stores trimmed answers with their shown positions", async () => {
+ const { caller, userId } = await createCallerForNewUser();
+
+ await caller.onboarding.complete({
+ buildIntents: ["rag", "other"],
+ buildIntentPositions: [2, 6],
+ buildIntentOther: " voice agent ",
+ });
+
+ const survey = await prisma.survey.findFirstOrThrow({
+ where: { userId },
+ });
+ expect(survey.response).toEqual({
+ buildIntents: ["rag", "other"],
+ buildIntentOther: "voice agent",
+ buildIntentPositions: [2, 6],
+ });
+ });
+
+ it.each([
+ [
+ "duplicate picks",
+ { buildIntents: ["rag", "rag"], buildIntentPositions: [0, 0] },
+ ],
+ [
+ "just exploring with another pick",
+ {
+ buildIntents: ["just_exploring", "rag"],
+ buildIntentPositions: [5, 0],
+ },
+ ],
+ [
+ "more than three picks",
+ {
+ buildIntents: ["rag", "chat_agent", "coding_agents", "other"],
+ buildIntentPositions: [0, 1, 2, 6],
+ },
+ ],
+ [
+ "an unknown id",
+ { buildIntents: ["unknown"], buildIntentPositions: [0] },
+ ],
+ [
+ "other text over 500 characters",
+ {
+ buildIntents: ["other"],
+ buildIntentPositions: [6],
+ buildIntentOther: "x".repeat(501),
+ },
+ ],
+ [
+ "positions that don't match the picks",
+ { buildIntents: ["rag", "other"], buildIntentPositions: [2] },
+ ],
+ ])("rejects %s", async (_case, input) => {
+ const { caller, userId } = await createCallerForNewUser();
+
+ await expect(
+ caller.onboarding.complete(
+ input as Parameters<typeof caller.onboarding.complete>[0],
+ ),
+ ).rejects.toThrow();
+ expect(await prisma.survey.count({ where: { userId } })).toBe(0);
});
});
});
diff --git a/web/src/__tests__/server/unit/onboardingService.servertest.ts b/web/src/__tests__/server/unit/onboardingService.servertest.ts
index 3204e06f47..61df7470d7 100644
--- a/web/src/__tests__/server/unit/onboardingService.servertest.ts
+++ b/web/src/__tests__/server/unit/onboardingService.servertest.ts
@@ -215,6 +215,7 @@ describe("completeCloudSignupOnboarding", () => {
}),
).resolves.toEqual({
redirectTo: "/project/project-1/traces",
+ surveyCreated: true,
});
expect(tx.$queryRaw).toHaveBeenCalledTimes(1);
@@ -248,7 +249,7 @@ describe("completeCloudSignupOnboarding", () => {
tx.survey.findFirst.mockResolvedValue({ id: "survey-1" });
- await completeCloudSignupOnboarding({
+ const repeatResult = await completeCloudSignupOnboarding({
prisma,
userId: "user-1",
userEmail: "[email protected]",
@@ -257,10 +258,64 @@ describe("completeCloudSignupOnboarding", () => {
aiFeaturesEnabled: false,
});
+ expect(repeatResult.surveyCreated).toBe(false);
+
expect(tx.survey.create).toHaveBeenCalledTimes(1);
expect(tx.organization.update).toHaveBeenCalledTimes(1);
});
+ it("stores each pick with the position it was shown at", async () => {
+ const { prisma, tx } = makeCompletionPrisma({
+ memberships: [
+ makeMembership({ orgId: "org-1", projects: [{ id: "project-1" }] }),
+ ],
+ });
+
+ await completeCloudSignupOnboarding({
+ prisma,
+ userId: "user-1",
+ userEmail: "[email protected]",
+ canCreateOrganizations: true,
+ referralSource: "Reddit",
+ buildIntents: ["rag", "other"],
+ buildIntentPositions: [2, 6],
+ buildIntentOther: "eval pipeline",
+ });
+
+ expect(tx.survey.create).toHaveBeenCalledWith(
+ expect.objectContaining({
+ data: expect.objectContaining({
+ response: {
+ referralSource: "Reddit",
+ buildIntents: ["rag", "other"],
+ buildIntentPositions: [2, 6],
+ buildIntentOther: "eval pipeline",
+ },
+ }),
+ }),
+ );
+ });
+
+ it("stores an empty response when the survey is skipped", async () => {
+ const { prisma, tx } = makeCompletionPrisma({
+ memberships: [
+ makeMembership({ orgId: "org-1", projects: [{ id: "project-1" }] }),
+ ],
+ });
+
+ await completeCloudSignupOnboarding({
+ prisma,
+ userId: "user-1",
+ canCreateOrganizations: true,
+ });
+
+ expect(tx.survey.create).toHaveBeenCalledWith(
+ expect.objectContaining({
+ data: expect.objectContaining({ response: {} }),
+ }),
+ );
+ });
+
it("does not update AI features for an existing organization", async () => {
const { prisma, tx } = makeCompletionPrisma({
memberships: [
diff --git a/web/src/features/onboarding/components/BuildIntentFieldset.tsx b/web/src/features/onboarding/components/BuildIntentFieldset.tsx
new file mode 100644
index 0000000000..a57f7c3886
--- /dev/null
+++ b/web/src/features/onboarding/components/BuildIntentFieldset.tsx
@@ -0,0 +1,100 @@
+import type { ReactNode } from "react";
+import { Checkbox } from "@/src/components/design-system/Checkbox/Checkbox";
+import {
+ BUILD_INTENT_MAX_SELECTIONS,
+ EXCLUSIVE_BUILD_INTENT,
+ OTHER_BUILD_INTENT,
+ toggleBuildIntent,
+ type BuildIntentId,
+ type BuildIntentOption,
+} from "../lib/buildIntent";
+
+type BuildIntentFieldsetProps = {
+ options: BuildIntentOption[];
+ value: BuildIntentId[];
+ onChange: (value: BuildIntentId[]) => void;
+ otherInput: ReactNode;
+};
+
+export function BuildIntentFieldset({
+ options,
+ value,
+ onChange,
+ otherInput,
+}: BuildIntentFieldsetProps) {
+ const isAtLimit = value.length >= BUILD_INTENT_MAX_SELECTIONS;
+
+ const handleOptionToggle = (id: BuildIntentId, isChecked: boolean) =>
+ onChange(toggleBuildIntent(value, id, isChecked));
+
+ return (
+ <fieldset>
+ <legend className="text-xl font-bold">
+ What will you use Langfuse for?
+ </legend>
+ <div className="mt-1 flex flex-col gap-3">
+ <p className="text-muted-foreground text-sm">
+ Pick up to {BUILD_INTENT_MAX_SELECTIONS}
+ </p>
+ {options.map((option) => (
+ <BuildIntentOptionRow
+ key={option.id}
+ option={option}
+ isChecked={value.includes(option.id)}
+ isDisabled={
+ isAtLimit &&
+ !value.includes(option.id) &&
+ option.id !== EXCLUSIVE_BUILD_INTENT
+ }
+ onToggle={handleOptionToggle}
+ >
+ {option.id === OTHER_BUILD_INTENT ? otherInput : null}
+ </BuildIntentOptionRow>
+ ))}
+ </div>
+ </fieldset>
+ );
+}
+
+type BuildIntentOptionRowProps = {
+ option: BuildIntentOption;
+ isChecked: boolean;
+ isDisabled: boolean;
+ onToggle: (id: BuildIntentId, isChecked: boolean) => void;
+ children: ReactNode;
+};
+
+function BuildIntentOptionRow({
+ option,
+ isChecked,
+ isDisabled,
+ onToggle,
+ children,
+}: BuildIntentOptionRowProps) {
+ const checkboxId = `build-intent-${option.id}`;
+
+ const handleCheckedChange = (checked: boolean | "indeterminate") =>
+ onToggle(option.id, checked === true);
+
+ return (
+ <div className="flex flex-col gap-2">
+ <div className="flex items-start gap-3">
+ <div className="pt-0.5">
+ <Checkbox
+ id={checkboxId}
+ checked={isChecked}
+ disabled={isDisabled}
+ onCheckedChange={handleCheckedChange}
+ />
+ </div>
+ <label htmlFor={checkboxId} className="flex cursor-pointer flex-col">
+ <span className="text-sm">{option.label}</span>
+ {option.hint ? (
+ <span className="text-muted-foreground text-sm">{option.hint}</span>
+ ) : null}
+ </label>
+ </div>
+ {isChecked && children ? <div className="pl-7">{children}</div> : null}
+ </div>
+ );
+}
diff --git a/web/src/features/onboarding/components/ConnectedOnboardingSurvey.tsx b/web/src/features/onboarding/components/ConnectedOnboardingSurvey.tsx
index 5b874435d2..56ec80d3bd 100644
--- a/web/src/features/onboarding/components/ConnectedOnboardingSurvey.tsx
+++ b/web/src/features/onboarding/components/ConnectedOnboardingSurvey.tsx
@@ -2,15 +2,21 @@ import { useCallback, useEffect, useState } from "react";
import { useRouter } from "next/router";
import { useSession } from "next-auth/react";
import { showErrorToast } from "@/src/features/notifications";
+import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
import { useWatchedPromiseCallback } from "@/src/hooks/useWatchedPromiseCallback";
import { api } from "@/src/utils/api";
import { getDemoCallbackRedirectPath } from "../lib/demoCallbackRedirect";
+import {
+ getSurveySubmittedEvent,
+ shuffleBuildIntentOptions,
+} from "../lib/buildIntent";
import type { SurveyFormData } from "../lib/surveyTypes";
import { OnboardingSurvey } from "./OnboardingSurvey";
export function ConnectedOnboardingSurvey() {
const router = useRouter();
const { update: updateSession } = useSession();
+ const capture = usePostHogClientCapture();
const utils = api.useUtils();
const onboardingStatus = api.onboarding.status.useQuery();
const completeOnboardingMutation = api.onboarding.complete.useMutation();
@@ -20,6 +26,8 @@ export function ConnectedOnboardingSurvey() {
: undefined;
const [hasStartedOnboardingCompletion, setHasStartedOnboardingCompletion] =
useState(false);
+ const [onboardingOpenedAt] = useState(() => Date.now());
+ const [buildIntentOptions] = useState(shuffleBuildIntentOptions);
const [finishOnboarding, isFinishingOnboarding] = useWatchedPromiseCallback(
async (data: SurveyFormData) => {
@@ -30,16 +38,36 @@ export function ConnectedOnboardingSurvey() {
const canConfigureAiFeatures =
onboardingStatus.data?.completed === false &&
onboardingStatus.data.canConfigureAiFeatures;
- const onboardingResult = await completeOnboardingMutation.mutateAsync(
- referralSource || canConfigureAiFeatures
+ const buildIntents = data.buildIntents;
+ const buildIntentOther = data.buildIntentOther?.trim();
+ const onboardingResult = await completeOnboardingMutation.mutateAsync({
+ ...(referralSource ? { referralSource } : {}),
+ ...(canConfigureAiFeatures
+ ? { aiFeaturesEnabled: data.aiFeaturesEnabled }
+ : {}),
+ ...(buildIntents.length > 0
? {
- ...(referralSource ? { referralSource } : {}),
- ...(canConfigureAiFeatures
- ? { aiFeaturesEnabled: data.aiFeaturesEnabled }
- : {}),
+ buildIntents,
+ buildIntentPositions: buildIntents.map((id) =>
+ buildIntentOptions.findIndex((option) => option.id === id),
+ ),
}
- : undefined,
- );
+ : {}),
+ ...(buildIntentOther ? { buildIntentOther } : {}),
+ });
+ const surveySubmittedEvent = getSurveySubmittedEvent({
+ surveyCreated: onboardingResult.surveyCreated,
+ buildIntents,
+ hasReferralSource: Boolean(referralSource),
+ surveyDurationMs: Date.now() - onboardingOpenedAt,
+ });
+ if (surveySubmittedEvent) {
+ capture(
+ "onboarding:signup_survey_submitted",
+ surveySubmittedEvent.properties,
+ surveySubmittedEvent.options,
+ );
+ }
const redirectTo = queryRedirectPath ?? onboardingResult.redirectTo;
utils.onboarding.status.setData(undefined, {
completed: true,
@@ -56,6 +84,9 @@ export function ConnectedOnboardingSurvey() {
}
},
[
+ capture,
+ onboardingOpenedAt,
+ buildIntentOptions,
completeOnboardingMutation,
onboardingStatus.data,
queryRedirectPath,
@@ -127,6 +158,7 @@ export function ConnectedOnboardingSurvey() {
return (
<OnboardingSurvey
state="form"
+ buildIntentOptions={buildIntentOptions}
canConfigureAiFeatures={
onboardingStatus.data?.completed === false
? onboardingStatus.data.canConfigureAiFeatures
diff --git a/web/src/features/onboarding/components/OnboardingSurvey.stories.tsx b/web/src/features/onboarding/components/OnboardingSurvey.stories.tsx
index 51af728ba8..8c1772d4bc 100644
--- a/web/src/features/onboarding/components/OnboardingSurvey.stories.tsx
+++ b/web/src/features/onboarding/components/OnboardingSurvey.stories.tsx
@@ -1,7 +1,10 @@
import { expect, fn, userEvent, within } from "storybook/test";
import preview from "../../../../.storybook/preview";
+import { shuffleBuildIntentOptions } from "../lib/buildIntent";
import { OnboardingSurvey } from "./OnboardingSurvey";
+const buildIntentOptions = shuffleBuildIntentOptions();
+
const meta = preview.meta({
component: OnboardingSurvey,
parameters: { layout: "fullscreen" },
@@ -10,6 +13,7 @@ const meta = preview.meta({
export const Default = meta.story({
args: {
state: "form",
+ buildIntentOptions,
canConfigureAiFeatures: true,
onSubmit: fn(async () => undefined),
},
@@ -19,6 +23,7 @@ export const WithoutAiFeaturesChoice = meta.story({
name: "(Test) Without AI Features Choice",
args: {
state: "form",
+ buildIntentOptions,
canConfigureAiFeatures: false,
onSubmit: fn(async () => undefined),
},
@@ -52,6 +57,7 @@ export const SubmitsAiFeaturesDefault = meta.story({
name: "(Test) Submits AI Features Default",
args: {
state: "form",
+ buildIntentOptions,
canConfigureAiFeatures: true,
onSubmit: defaultSubmit,
},
@@ -66,6 +72,8 @@ export const SubmitsAiFeaturesDefault = meta.story({
await expect(defaultSubmit).toHaveBeenCalledWith({
referralSource: undefined,
aiFeaturesEnabled: true,
+ buildIntents: [],
+ buildIntentOther: undefined,
});
},
});
@@ -76,6 +84,7 @@ export const SubmitsAiFeaturesOptOut = meta.story({
name: "(Test) Submits AI Features Opt-Out",
args: {
state: "form",
+ buildIntentOptions,
canConfigureAiFeatures: true,
onSubmit: optOutSubmit,
},
@@ -90,6 +99,57 @@ export const SubmitsAiFeaturesOptOut = meta.story({
await expect(optOutSubmit).toHaveBeenCalledWith({
referralSource: undefined,
aiFeaturesEnabled: false,
+ buildIntents: [],
+ buildIntentOther: undefined,
+ });
+ },
+});
+
+const buildIntentSubmit = fn(async () => undefined);
+
+export const SubmitsBuildIntents = meta.story({
+ name: "(Test) Submits Build Intents",
+ args: {
+ state: "form",
+ buildIntentOptions,
+ canConfigureAiFeatures: false,
+ onSubmit: buildIntentSubmit,
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ await userEvent.click(
+ canvas.getByRole("checkbox", { name: /Just exploring/ }),
+ );
+ await userEvent.click(canvas.getByRole("checkbox", { name: /RAG/ }));
+ await expect(
+ canvas.getByRole("checkbox", { name: /Just exploring/ }),
+ ).not.toBeChecked();
+
+ await userEvent.click(canvas.getByRole("checkbox", { name: /Other/ }));
+ await userEvent.type(
+ canvas.getByRole("textbox", {
+ name: "What else will you use Langfuse for?",
+ }),
+ "Eval pipeline",
+ );
+ await userEvent.click(
+ canvas.getByRole("checkbox", { name: /coding agents/ }),
+ );
+ await expect(
+ canvas.getByRole("checkbox", { name: /Autonomous agents/ }),
+ ).toBeDisabled();
+ await expect(
+ canvas.getByRole("checkbox", { name: /Just exploring/ }),
+ ).toBeEnabled();
+
+ await userEvent.click(canvas.getByRole("button", { name: "Next" }));
+
+ await expect(buildIntentSubmit).toHaveBeenCalledWith({
+ referralSource: undefined,
+ aiFeaturesEnabled: true,
+ buildIntents: ["rag", "other", "coding_agents"],
+ buildIntentOther: "Eval pipeline",
});
},
});
diff --git a/web/src/features/onboarding/components/OnboardingSurvey.tsx b/web/src/features/onboarding/components/OnboardingSurvey.tsx
index 7256972368..ff00ad780c 100644
--- a/web/src/features/onboarding/components/OnboardingSurvey.tsx
+++ b/web/src/features/onboarding/components/OnboardingSurvey.tsx
@@ -2,6 +2,7 @@ import { useForm } from "react-hook-form";
import { ExternalLink } from "lucide-react";
import { Button } from "@/src/components/ui/button";
import { Switch } from "@/src/components/design-system/Switch/Switch";
+import { Input as DesignSystemInput } from "@/src/components/design-system/Input/Input";
import { LangfuseIcon } from "@/src/components/design-system/LangfuseIcon/LangfuseIcon";
import { Spinner } from "@/src/components/design-system/Spinner/Spinner";
import {
@@ -13,13 +14,19 @@ import {
FormMessage,
} from "@/src/components/ui/form";
import { Input } from "@/src/components/ui/input";
+import {
+ BUILD_INTENT_OTHER_MAX_LENGTH,
+ type BuildIntentOption,
+} from "../lib/buildIntent";
import type { SurveyFormData } from "../lib/surveyTypes";
+import { BuildIntentFieldset } from "./BuildIntentFieldset";
type OnboardingSurveyProps =
| { state: "completing" }
| { state: "error" }
| {
state: "form";
+ buildIntentOptions: BuildIntentOption[];
canConfigureAiFeatures: boolean;
onSubmit: (data: SurveyFormData) => Promise<void>;
};
@@ -29,6 +36,8 @@ export function OnboardingSurvey(props: OnboardingSurveyProps) {
defaultValues: {
referralSource: undefined,
aiFeaturesEnabled: true,
+ buildIntents: [],
+ buildIntentOther: undefined,
},
});
@@ -89,6 +98,27 @@ export function OnboardingSurvey(props: OnboardingSurveyProps) {
<Form {...form}>
<form className="flex h-full flex-col" onSubmit={submitForm}>
<div className="flex-1">
+ <FormField
+ control={form.control}
+ name="buildIntents"
+ render={({ field }) => (
+ <div className="mb-6 border-b pb-6">
+ <BuildIntentFieldset
+ options={props.buildIntentOptions}
+ value={field.value}
+ onChange={field.onChange}
+ otherInput={
+ <DesignSystemInput
+ {...form.register("buildIntentOther")}
+ aria-label="What else will you use Langfuse for?"
+ maxLength={BUILD_INTENT_OTHER_MAX_LENGTH}
+ placeholder="Tell us briefly"
+ />
+ }
+ />
+ </div>
+ )}
+ />
<FormField
control={form.control}
name="referralSource"
@@ -99,7 +129,6 @@ export function OnboardingSurvey(props: OnboardingSurveyProps) {
</FormLabel>
<FormControl>
<Input
- autoFocus
maxLength={500}
placeholder="Colleague, Word of Mouth, X, Reddit, Event"
{...field}
diff --git a/web/src/features/onboarding/lib/buildIntent.clienttest.ts b/web/src/features/onboarding/lib/buildIntent.clienttest.ts
new file mode 100644
index 0000000000..70819e3dff
--- /dev/null
+++ b/web/src/features/onboarding/lib/buildIntent.clienttest.ts
@@ -0,0 +1,89 @@
+import {
+ BUILD_INTENT_IDS,
+ type BuildIntentId,
+ getSurveySubmittedEvent,
+ shuffleBuildIntentOptions,
+ toggleBuildIntent,
+} from "./buildIntent";
+
+describe("shuffleBuildIntentOptions", () => {
+ it("keeps every option once and pins exploring and other last", () => {
+ const ids = shuffleBuildIntentOptions().map((option) => option.id);
+
+ expect([...ids].sort()).toEqual([...BUILD_INTENT_IDS].sort());
+ expect(ids.slice(-2)).toEqual(["just_exploring", "other"]);
+ });
+});
+
+describe("toggleBuildIntent", () => {
+ it("adds and removes picks", () => {
+ expect(toggleBuildIntent(["rag"], "chat_agent", true)).toEqual([
+ "rag",
+ "chat_agent",
+ ]);
+ expect(toggleBuildIntent(["rag", "chat_agent"], "rag", false)).toEqual([
+ "chat_agent",
+ ]);
+ });
+
+ it("ignores a fourth pick", () => {
+ const threePicks = toggleBuildIntent(
+ toggleBuildIntent(["rag"], "chat_agent", true),
+ "other",
+ true,
+ );
+
+ expect(toggleBuildIntent(threePicks, "coding_agents", true)).toEqual(
+ threePicks,
+ );
+ });
+
+ it("makes just exploring exclusive in both directions", () => {
+ expect(
+ toggleBuildIntent(["rag", "chat_agent"], "just_exploring", true),
+ ).toEqual(["just_exploring"]);
+ expect(toggleBuildIntent(["just_exploring"], "rag", true)).toEqual(["rag"]);
+ });
+});
+
+describe("getSurveySubmittedEvent", () => {
+ const submit = {
+ surveyCreated: true,
+ buildIntents: ["rag"] as BuildIntentId[],
+ hasReferralSource: true,
+ surveyDurationMs: 4200,
+ };
+
+ it("sends metadata and sets the picks once on the person", () => {
+ expect(
+ getSurveySubmittedEvent({ ...submit, buildIntents: ["rag", "other"] }),
+ ).toEqual({
+ properties: {
+ buildIntents: ["rag", "other"],
+ buildIntentCount: 2,
+ hasReferralSource: true,
+ surveyDurationMs: 4200,
+ },
+ options: { $set_once: { onboardingBuildIntents: ["rag", "other"] } },
+ });
+ });
+
+ it("records a skip without setting the person property", () => {
+ expect(
+ getSurveySubmittedEvent({ ...submit, buildIntents: [] }),
+ ).toMatchObject({
+ properties: { buildIntents: [], buildIntentCount: 0 },
+ options: undefined,
+ });
+ });
+
+ it("sends nothing when an earlier submit already stored the survey", () => {
+ expect(
+ getSurveySubmittedEvent({
+ ...submit,
+ buildIntents: ["rag"],
+ surveyCreated: false,
+ }),
+ ).toBeNull();
+ });
+});
diff --git a/web/src/features/onboarding/lib/buildIntent.ts b/web/src/features/onboarding/lib/buildIntent.ts
new file mode 100644
index 0000000000..7eeb074994
--- /dev/null
+++ b/web/src/features/onboarding/lib/buildIntent.ts
@@ -0,0 +1,114 @@
+/** Temporary onboarding question; remove with `BuildIntentFieldset` and the `buildIntent*` fields and event props. */
+
+const USE_CASE_OPTIONS = [
+ {
+ id: "chat_agent",
+ label: "Chat or support agent",
+ hint: "Customer-facing assistant or bot",
+ },
+ {
+ id: "rag",
+ label: "Q&A over documents (RAG)",
+ hint: "Search your docs, knowledge base",
+ },
+ {
+ id: "workflow_automation",
+ label: "AI workflow automation",
+ hint: "Extraction, n8n / Temporal",
+ },
+ {
+ id: "autonomous_agents",
+ label: "Autonomous agents",
+ hint: "Multi-step or long-running tasks",
+ },
+ {
+ id: "coding_agents",
+ label: "Trace my coding agents",
+ hint: "Claude Code, Cursor, Codex",
+ },
+] as const;
+
+const PINNED_BUILD_INTENT_OPTIONS = [
+ { id: "just_exploring", label: "Just exploring", hint: undefined },
+ { id: "other", label: "Other", hint: undefined },
+] as const;
+
+export type BuildIntentId =
+ | (typeof USE_CASE_OPTIONS)[number]["id"]
+ | (typeof PINNED_BUILD_INTENT_OPTIONS)[number]["id"];
+
+export type BuildIntentOption = {
+ id: BuildIntentId;
+ label: string;
+ hint: string | undefined;
+};
+
+export const BUILD_INTENT_IDS = [
+ ...USE_CASE_OPTIONS,
+ ...PINNED_BUILD_INTENT_OPTIONS,
+].map((option) => option.id) as [BuildIntentId, ...BuildIntentId[]];
+
+export const BUILD_INTENT_MAX_SELECTIONS = 3;
+export const BUILD_INTENT_OTHER_MAX_LENGTH = 500;
+export const EXCLUSIVE_BUILD_INTENT: BuildIntentId = "just_exploring";
+export const OTHER_BUILD_INTENT: BuildIntentId = "other";
+
+/** Use cases in random order, then "Just exploring" and "Other". */
+export const shuffleBuildIntentOptions = (): BuildIntentOption[] => {
+ const shuffled: BuildIntentOption[] = [...USE_CASE_OPTIONS];
+
+ for (let index = shuffled.length - 1; index > 0; index--) {
+ const swapIndex = Math.floor(Math.random() * (index + 1));
+ [shuffled[index], shuffled[swapIndex]] = [
+ shuffled[swapIndex],
+ shuffled[index],
+ ];
+ }
+
+ return [...shuffled, ...PINNED_BUILD_INTENT_OPTIONS];
+};
+
+/** Applies one toggle: "Just exploring" is exclusive and picks past the cap are ignored. */
+export const toggleBuildIntent = (
+ current: BuildIntentId[],
+ id: BuildIntentId,
+ isChecked: boolean,
+): BuildIntentId[] => {
+ if (!isChecked) return current.filter((picked) => picked !== id);
+ if (id === EXCLUSIVE_BUILD_INTENT) return [id];
+
+ const withoutExclusive = current.filter(
+ (picked) => picked !== EXCLUSIVE_BUILD_INTENT && picked !== id,
+ );
+ if (withoutExclusive.length >= BUILD_INTENT_MAX_SELECTIONS) return current;
+
+ return [...withoutExclusive, id];
+};
+
+/** Event payload for a submit that stored the survey; metadata only, so free text never reaches PostHog. */
+export const getSurveySubmittedEvent = ({
+ surveyCreated,
+ buildIntents,
+ hasReferralSource,
+ surveyDurationMs,
+}: {
+ surveyCreated: boolean;
+ buildIntents: BuildIntentId[];
+ hasReferralSource: boolean;
+ surveyDurationMs: number;
+}) => {
+ if (!surveyCreated) return null;
+
+ return {
+ properties: {
+ buildIntents,
+ buildIntentCount: buildIntents.length,
+ hasReferralSource,
+ surveyDurationMs,
+ },
+ options:
+ buildIntents.length > 0
+ ? { $set_once: { onboardingBuildIntents: buildIntents } }
+ : undefined,
+ };
+};
diff --git a/web/src/features/onboarding/lib/surveyTypes.ts b/web/src/features/onboarding/lib/surveyTypes.ts
index 913a2de2b1..9b572e4eb7 100644
--- a/web/src/features/onboarding/lib/surveyTypes.ts
+++ b/web/src/features/onboarding/lib/surveyTypes.ts
@@ -1,4 +1,8 @@
+import type { BuildIntentId } from "./buildIntent";
+
export interface SurveyFormData {
referralSource?: string;
aiFeaturesEnabled: boolean;
+ buildIntents: BuildIntentId[];
+ buildIntentOther?: string;
}
diff --git a/web/src/features/onboarding/server/onboardingRouter.ts b/web/src/features/onboarding/server/onboardingRouter.ts
index 62d9366334..f053e7c2da 100644
--- a/web/src/features/onboarding/server/onboardingRouter.ts
+++ b/web/src/features/onboarding/server/onboardingRouter.ts
@@ -7,6 +7,12 @@ import {
createTRPCRouter,
authenticatedProcedure,
} from "@/src/server/api/trpc";
+import {
+ BUILD_INTENT_IDS,
+ BUILD_INTENT_MAX_SELECTIONS,
+ BUILD_INTENT_OTHER_MAX_LENGTH,
+ EXCLUSIVE_BUILD_INTENT,
+} from "@/src/features/onboarding/lib/buildIntent";
export const onboardingRouter = createTRPCRouter({
status: authenticatedProcedure.query(async ({ ctx }) => {
@@ -23,7 +29,40 @@ export const onboardingRouter = createTRPCRouter({
.object({
referralSource: z.string().trim().max(500).optional(),
aiFeaturesEnabled: z.boolean().optional(),
+ buildIntents: z
+ .array(z.enum(BUILD_INTENT_IDS))
+ .min(1)
+ .max(BUILD_INTENT_MAX_SELECTIONS)
+ .optional(),
+ buildIntentPositions: z
+ .array(
+ z
+ .number()
+ .int()
+ .min(0)
+ .max(BUILD_INTENT_IDS.length - 1),
+ )
+ .max(BUILD_INTENT_MAX_SELECTIONS)
+ .optional(),
+ buildIntentOther: z
+ .string()
+ .trim()
+ .max(BUILD_INTENT_OTHER_MAX_LENGTH)
+ .optional(),
})
+ .refine(
+ ({ buildIntents }) =>
+ !buildIntents ||
+ (new Set(buildIntents).size === buildIntents.length &&
+ (!buildIntents.includes(EXCLUSIVE_BUILD_INTENT) ||
+ buildIntents.length === 1)),
+ { message: "Build intents must be unique; exploring is exclusive" },
+ )
+ .refine(
+ ({ buildIntents, buildIntentPositions }) =>
+ buildIntentPositions?.length === buildIntents?.length,
+ { message: "Each build intent needs its shown position" },
+ )
.optional(),
)
.mutation(async ({ ctx, input }) => {
@@ -34,6 +73,9 @@ export const onboardingRouter = createTRPCRouter({
canCreateOrganizations: ctx.session.user.canCreateOrganizations,
referralSource: input?.referralSource,
aiFeaturesEnabled: input?.aiFeaturesEnabled,
+ buildIntents: input?.buildIntents,
+ buildIntentPositions: input?.buildIntentPositions,
+ buildIntentOther: input?.buildIntentOther,
});
}),
});
diff --git a/web/src/features/onboarding/server/onboardingService.ts b/web/src/features/onboarding/server/onboardingService.ts
index 29adccc875..09964ceb68 100644
--- a/web/src/features/onboarding/server/onboardingService.ts
+++ b/web/src/features/onboarding/server/onboardingService.ts
@@ -16,6 +16,7 @@ import {
} from "@/src/features/rbac";
import { projectRoleAccessRights } from "@langfuse/shared";
import { createProjectRoute } from "@/src/features/setup";
+import { type BuildIntentId } from "@/src/features/onboarding/lib/buildIntent";
const DEFAULT_STARTER_PROJECT_NAME = "My Project";
const STARTER_ORGANIZATION_METADATA = {
@@ -277,6 +278,9 @@ export const completeCloudSignupOnboarding = async ({
canCreateOrganizations,
referralSource,
aiFeaturesEnabled,
+ buildIntents,
+ buildIntentPositions,
+ buildIntentOther,
}: {
prisma: PrismaClient;
userId: string;
@@ -284,6 +288,9 @@ export const completeCloudSignupOnboarding = async ({
canCreateOrganizations: boolean;
referralSource?: string;
aiFeaturesEnabled?: boolean;
+ buildIntents?: BuildIntentId[];
+ buildIntentPositions?: number[];
+ buildIntentOther?: string;
}) =>
prisma.$transaction(async (tx) => {
await tx.$queryRaw`
@@ -326,11 +333,18 @@ export const completeCloudSignupOnboarding = async ({
await tx.survey.create({
data: {
surveyName: SurveyName.USER_ONBOARDING,
- response: normalizedReferralSource
- ? {
- referralSource: normalizedReferralSource,
- }
- : {},
+ response: {
+ ...(normalizedReferralSource
+ ? { referralSource: normalizedReferralSource }
+ : {}),
+ ...(buildIntents && buildIntents.length > 0
+ ? {
+ buildIntents,
+ buildIntentPositions: buildIntentPositions ?? [],
+ ...(buildIntentOther ? { buildIntentOther } : {}),
+ }
+ : {}),
+ },
userId,
userEmail: userEmail ?? undefined,
orgId: redirectTarget.orgId,
@@ -340,6 +354,7 @@ export const completeCloudSignupOnboarding = async ({
return {
redirectTo: redirectTarget.redirectTo,
+ surveyCreated: !existingSurvey,
};
});
diff --git a/web/src/features/posthog-analytics/usePostHogClientCapture.ts b/web/src/features/posthog-analytics/usePostHogClientCapture.ts
index 73330866d1..795c9e74fd 100644
--- a/web/src/features/posthog-analytics/usePostHogClientCapture.ts
+++ b/web/src/features/posthog-analytics/usePostHogClientCapture.ts
@@ -394,6 +394,7 @@ const events = {
"tracing_api_key_create_clicked",
"tracing_agent_prompt_copy_clicked",
"tracing_manual_docs_link_clicked",
+ "signup_survey_submitted",
],
user_settings: ["theme_changed", "feature_preview_toggled"],
project_settings: [