Skip to content

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

Add new user signup event

Marc Klingena7be70cbf070
diff --git a/.env.cloud.example b/.env.cloud.example
index f2cfec8f4c..26ca0d56e9 100644
--- a/.env.cloud.example
+++ b/.env.cloud.example
@@ -24,6 +24,7 @@ NEXTAUTH_SECRET="secret"
# SENTRY_AUTH_TOKEN=
# LANGFUSE_TEAM_SLACK_WEBHOOK=
+# LANGFUSE_NEW_USER_SIGNUP_WEBHOOK=
# Posthog (optional for analytics of web ui)
# NEXT_PUBLIC_POSTHOG_HOST=
diff --git a/src/env.mjs b/src/env.mjs
index 685a9e07fa..203797fd30 100644
--- a/src/env.mjs
+++ b/src/env.mjs
@@ -25,6 +25,7 @@ export const env = createEnv({
process.env.VERCEL ? z.string().min(1) : z.string().url(),
),
LANGFUSE_TEAM_SLACK_WEBHOOK: z.string().url().optional(),
+ LANGFUSE_NEW_USER_SIGNUP_WEBHOOK: z.string().url().optional(),
// Add `.min(1) on ID and SECRET if you want to make sure they're not empty
LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES: z.enum(["true", "false"]).optional(),
},
@@ -58,5 +59,7 @@ export const env = createEnv({
LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES:
process.env.LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES,
LANGFUSE_TEAM_SLACK_WEBHOOK: process.env.LANGFUSE_TEAM_SLACK_WEBHOOK,
+ LANGFUSE_NEW_USER_SIGNUP_WEBHOOK:
+ process.env.LANGFUSE_NEW_USER_SIGNUP_WEBHOOK,
},
});
diff --git a/src/pages/api/auth/signup.ts b/src/pages/api/auth/signup.ts
index dfb7a9b392..f6bda2570d 100644
--- a/src/pages/api/auth/signup.ts
+++ b/src/pages/api/auth/signup.ts
@@ -23,34 +23,14 @@ 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 user
+ let userId: string;
try {
- await createUserEmailPassword(body.email, body.password, body.name);
+ userId = await createUserEmailPassword(
+ body.email,
+ body.password,
+ body.name,
+ );
} catch (error) {
if (error instanceof Error) {
console.log(
@@ -64,5 +44,25 @@ export default async function handler(
return;
}
+ // Trigger new user signup event
+ if (
+ env.LANGFUSE_NEW_USER_SIGNUP_WEBHOOK &&
+ env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION
+ ) {
+ await fetch(env.LANGFUSE_NEW_USER_SIGNUP_WEBHOOK, {
+ method: "POST",
+ body: JSON.stringify({
+ name: body.name,
+ email: body.email,
+ referralSource: body.referralSource,
+ cloudRegion: env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION,
+ userId: userId,
+ }),
+ headers: {
+ "Content-Type": "application/json",
+ },
+ });
+ }
+
res.status(200).json({ message: "User created" });
}