🪢 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
chore: add sign up event (#11473)
Nimar240d4d7def6a
diff --git a/web/src/features/auth/lib/createProjectMembershipsOnSignup.ts b/web/src/features/auth/lib/createProjectMembershipsOnSignup.tsindex c323be464a..f008359af3 100644--- a/web/src/features/auth/lib/createProjectMembershipsOnSignup.ts+++ b/web/src/features/auth/lib/createProjectMembershipsOnSignup.ts@@ -1,12 +1,19 @@import { env } from "@/src/env.mjs";import { prisma, Role } from "@langfuse/shared/src/db";import { logger } from "@langfuse/shared/src/server";+import { ServerPosthog } from "@/src/features/posthog-analytics/ServerPosthog";export async function createProjectMembershipsOnSignup(user: {id: string;email: string | null;}) {try {+ // in no case do we want to send duplicate sign up events to posthog+ const isNewUser = !(await prisma.organizationMembership.findFirst({+ where: { userId: user.id },+ select: { id: true },+ }));+// Langfuse Cloud: provide view-only access to the demo project, none access to the demo orgconst demoProject =env.NEXT_PUBLIC_DEMO_ORG_ID && env.NEXT_PUBLIC_DEMO_PROJECT_ID@@ -100,6 +107,26 @@ export async function createProjectMembershipsOnSignup(user: {// Invites do not work for users without emails (some future SSO users)if (user.email) await processMembershipInvitations(user.email, user.id);++ // for conversion metric tracking in posthog: did a new user sign up?+ if (isNewUser && env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION) {+ try {+ const posthog = new ServerPosthog();+ posthog.capture({+ distinctId: user.id,+ event: "cloud_signup_complete",+ properties: {+ cloudRegion: env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION,+ hasDemoAccess: demoProject !== undefined,+ hasDefaultOrg: defaultOrg !== undefined,+ hasDefaultProject: defaultProject !== undefined,+ },+ });+ await posthog.shutdown();+ } catch {+ // analytics tracking failure is not critical, just fail+ }+ }} catch (e) {logger.error("Error assigning project access to new user", e);}diff --git a/web/src/features/posthog-analytics/ServerPosthog.ts b/web/src/features/posthog-analytics/ServerPosthog.tsindex dd28dfe56c..9162879417 100644--- a/web/src/features/posthog-analytics/ServerPosthog.ts+++ b/web/src/features/posthog-analytics/ServerPosthog.ts@@ -1,18 +1,39 @@import { env } from "@/src/env.mjs";-import { PostHog as OriginalPosthog } from "posthog-node";+import { PostHog } from "posthog-node";-// Safe as it is intended to be public-const PUBLIC_POSTHOG_API_KEY =- env.NEXT_PUBLIC_POSTHOG_KEY ||- "phc_zkMwFajk8ehObUlMth0D7DtPItFnxETi3lmSvyQDrwB";-const POSTHOG_HOST = env.NEXT_PUBLIC_POSTHOG_HOST || "https://eu.posthog.com";+const FALLBACK_POSTHOG_KEY = "phc_zkMwFajk8ehObUlMth0D7DtPItFnxETi3lmSvyQDrwB";+const FALLBACK_POSTHOG_HOST = "https://eu.posthog.com";++export class ServerPosthog {+ private posthog: PostHog | null;-export class ServerPosthog extends OriginalPosthog {constructor() {- super(PUBLIC_POSTHOG_API_KEY, {- host: POSTHOG_HOST,- });+ const telemetryEnabled = env.TELEMETRY_ENABLED !== "false";++ const apiKey =+ env.NEXT_PUBLIC_POSTHOG_KEY ??+ (telemetryEnabled ? FALLBACK_POSTHOG_KEY : null);+ const host =+ env.NEXT_PUBLIC_POSTHOG_HOST ??+ (telemetryEnabled ? FALLBACK_POSTHOG_HOST : null);++ if (apiKey && host) {+ this.posthog = new PostHog(apiKey, { host });+ if (process.env.NODE_ENV === "development") this.posthog.debug();+ } else {+ this.posthog = null;+ }+ }++ capture(...args: Parameters<PostHog["capture"]>) {+ this.posthog?.capture(...args);+ }++ async shutdown() {+ await this.posthog?.shutdown();+ }- if (process.env.NODE_ENV === "development") this.debug();+ async flush() {+ await this.posthog?.flush();}}diff --git a/web/src/pages/_app.tsx b/web/src/pages/_app.tsxindex f43a249dc1..1752783003 100644--- a/web/src/pages/_app.tsx+++ b/web/src/pages/_app.tsx@@ -100,6 +100,7 @@ if (},autocapture: false,enable_heatmaps: false,+ persistence: "cookie",});}