🪢 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
Ask for referral source when signing up (cloud) (#287)
Marc Klingenfe33bd7c5b1a
diff --git a/.env.cloud.example b/.env.cloud.exampleindex a14f811cf7..f2cfec8f4c 100644--- a/.env.cloud.example+++ b/.env.cloud.example@@ -23,7 +23,7 @@ NEXTAUTH_SECRET="secret"# NEXT_SENTRY_PROJECT=# SENTRY_AUTH_TOKEN=-# SLACK_WEBHOOK_FEEDBACK_URL=+# LANGFUSE_TEAM_SLACK_WEBHOOK=# Posthog (optional for analytics of web ui)# NEXT_PUBLIC_POSTHOG_HOST=diff --git a/src/env.mjs b/src/env.mjsindex 2f8bb7d848..83f7be3b4a 100644--- a/src/env.mjs+++ b/src/env.mjs@@ -24,6 +24,7 @@ export const env = createEnv({// VERCEL_URL doesn't include `https` so it can't be validated as a URLprocess.env.VERCEL ? z.string().min(1) : z.string().url(),),+ LANGFUSE_TEAM_SLACK_WEBHOOK: z.string().url().optional(),// Add `.min(1) on ID and SECRET if you want to make sure they're not empty},@@ -58,5 +59,6 @@ export const env = createEnv({NEXT_PUBLIC_SIGN_UP_DISABLED: process.env.NEXT_PUBLIC_SIGN_UP_DISABLED,NEXT_PUBLIC_ENABLE_EXPERIMENTAL_FEATURES:process.env.NEXT_PUBLIC_ENABLE_EXPERIMENTAL_FEATURES,+ LANGFUSE_TEAM_SLACK_WEBHOOK: process.env.LANGFUSE_TEAM_SLACK_WEBHOOK,},});diff --git a/src/features/auth/lib/signupSchema.ts b/src/features/auth/lib/signupSchema.tsindex 7f05eeb0e8..2fa33dcb45 100644--- a/src/features/auth/lib/signupSchema.ts+++ b/src/features/auth/lib/signupSchema.ts@@ -6,4 +6,5 @@ export const signupSchema = z.object({password: z.string().min(8, {message: "Password must be at least 8 characters long",}),+ referralSource: z.string().optional(),});diff --git a/src/features/feedback/server/feedbackHandler.ts b/src/features/feedback/server/feedbackHandler.tsindex 6b53818d6e..e235af4ee0 100644--- a/src/features/feedback/server/feedbackHandler.ts+++ b/src/features/feedback/server/feedbackHandler.ts@@ -1,3 +1,4 @@+import { env } from "@/src/env.mjs";import { runFeedbackCorsMiddleware } from "@/src/features/feedback/server/corsMiddleware";import { type NextApiRequest, type NextApiResponse } from "next";@@ -9,10 +10,10 @@ export default async function feedbackApiHandler(await runFeedbackCorsMiddleware(req, res);try {- if (!process.env.SLACK_WEBHOOK_FEEDBACK_URL)- throw new Error("SLACK_WEBHOOK_FEEDBACK_URL is not set");+ if (!env.LANGFUSE_TEAM_SLACK_WEBHOOK)+ throw new Error("LANGFUSE_TEAM_SLACK_WEBHOOK is not set");- const slackResponse = await fetch(process.env.SLACK_WEBHOOK_FEEDBACK_URL, {+ const slackResponse = await fetch(env.LANGFUSE_TEAM_SLACK_WEBHOOK, {method: "POST",body: JSON.stringify({ rawBody: JSON.stringify(req.body, null, 2) }),headers: {diff --git a/src/pages/api/auth/signup.ts b/src/pages/api/auth/signup.tsindex 9c4d59e192..dfb7a9b392 100644--- a/src/pages/api/auth/signup.ts+++ b/src/pages/api/auth/signup.ts@@ -23,6 +23,31 @@ export default async function handler(const body = validBody.data;+ // Track referral source+ if (+ env.LANGFUSE_TEAM_SLACK_WEBHOOK &&+ env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION &&+ body.referralSource &&+ body.referralSource !== ""+ ) {+ await fetch(env.LANGFUSE_TEAM_SLACK_WEBHOOK, {+ method: "POST",+ body: JSON.stringify({+ rawBody: JSON.stringify(+ {+ email: body.email,+ referralSource: body.referralSource,+ },+ null,+ 2,+ ),+ }),+ headers: {+ "Content-Type": "application/json",+ },+ });+ }+// create the usertry {await createUserEmailPassword(body.email, body.password, body.name);diff --git a/src/pages/auth/sign-up.tsx b/src/pages/auth/sign-up.tsxindex ec782f30ea..372a85c4f9 100644--- a/src/pages/auth/sign-up.tsx+++ b/src/pages/auth/sign-up.tsx@@ -18,8 +18,10 @@ import type * as z from "zod";import { env } from "@/src/env.mjs";import { useState } from "react";import { LangfuseIcon } from "@/src/components/LangfuseLogo";+import { usePostHog } from "posthog-js/react";export default function SignIn() {+ const posthog = usePostHog();const [formError, setFormError] = useState<string | null>(null);const form = useForm<z.infer<typeof signupSchema>>({resolver: zodResolver(signupSchema),@@ -27,12 +29,20 @@ export default function SignIn() {name: "",email: "",password: "",+ referralSource: "",},});async function onSubmit(values: z.infer<typeof signupSchema>) {try {setFormError(null);+ if (values.referralSource !== "") {+ posthog.capture("survey sent", {+ $survey_id: "018ade05-4d8c-0000-36b7-fc390b221590",+ $survey_name: "Referral source",+ $survey_response: values.referralSource,+ });+ }const res = await fetch("/api/auth/signup", {method: "POST",headers: { "Content-Type": "application/json" },@@ -125,6 +135,24 @@ export default function SignIn() {</FormItem>)}/>+ {env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION !== undefined ? (+ <FormField+ control={form.control}+ name="referralSource"+ render={({ field }) => (+ <FormItem>+ <FormLabel>+ Where did you hear about us?{" "}+ <span className="font-normal">(optional)</span>+ </FormLabel>+ <FormControl>+ <Input type="referralSource" {...field} />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ ) : null}<Buttontype="submit"className="w-full"