Skip to content

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

chore: Track v4 beta flag on PostHog person and super property (#12522)

Max Deichmannc409ced370a7
diff --git a/web/src/features/events/hooks/useV4Beta.ts b/web/src/features/events/hooks/useV4Beta.ts
index d3fca56580..59e922b083 100644
--- a/web/src/features/events/hooks/useV4Beta.ts
+++ b/web/src/features/events/hooks/useV4Beta.ts
@@ -1,6 +1,8 @@
import { useSession } from "next-auth/react";
import { api } from "@/src/utils/api";
import { useCallback } from "react";
+import posthog from "posthog-js";
+import { V4_BETA_ENABLED_POSTHOG_PROPERTY } from "@/src/features/posthog-analytics/usePostHogClientCapture";
type SetV4BetaEnabledOptions = {
onSuccess?: () => void | Promise<void>;
@@ -18,7 +20,13 @@ export function useV4Beta() {
mutation.mutate(
{ enabled },
{
- onSuccess: async () => {
+ onSuccess: async ({ v4BetaEnabled }) => {
+ posthog.setPersonProperties({
+ [V4_BETA_ENABLED_POSTHOG_PROPERTY]: v4BetaEnabled,
+ });
+ posthog.register({
+ [V4_BETA_ENABLED_POSTHOG_PROPERTY]: v4BetaEnabled,
+ });
await updateSession();
await options?.onSuccess?.();
},
diff --git a/web/src/features/posthog-analytics/usePostHogClientCapture.ts b/web/src/features/posthog-analytics/usePostHogClientCapture.ts
index 199124349b..c79afaf6d2 100644
--- a/web/src/features/posthog-analytics/usePostHogClientCapture.ts
+++ b/web/src/features/posthog-analytics/usePostHogClientCapture.ts
@@ -1,6 +1,8 @@
import { type CaptureResult, type CaptureOptions } from "posthog-js";
import { usePostHog } from "posthog-js/react";
+export const V4_BETA_ENABLED_POSTHOG_PROPERTY = "v4BetaEnabled";
+
// resource:action, only use snake_case
// Exported to silence @typescript-eslint/no-unused-vars v8 warning
// (used for type extraction via typeof, which is a legitimate pattern)
diff --git a/web/src/pages/_app.tsx b/web/src/pages/_app.tsx
index f9b0c5dfe6..5c6f39166d 100644
--- a/web/src/pages/_app.tsx
+++ b/web/src/pages/_app.tsx
@@ -77,6 +77,7 @@ import { SupportDrawerProvider } from "@/src/features/support-chat/SupportDrawer
import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";
import { ScoreCacheProvider } from "@/src/features/scores/contexts/ScoreCacheContext";
import { CorrectionCacheProvider } from "@/src/features/corrections/contexts/CorrectionCacheContext";
+import { V4_BETA_ENABLED_POSTHOG_PROPERTY } from "@/src/features/posthog-analytics/usePostHogClientCapture";
// Check that PostHog is client-side (used to handle Next.js SSR) and that env vars are set
if (
@@ -184,13 +185,12 @@ function UserTracking() {
) {
lastIdentifiedUser.current = JSON.stringify(sessionUser);
// PostHog
- if (env.NEXT_PUBLIC_POSTHOG_KEY && env.NEXT_PUBLIC_POSTHOG_HOST)
+ if (env.NEXT_PUBLIC_POSTHOG_KEY && env.NEXT_PUBLIC_POSTHOG_HOST) {
posthog.identify(sessionUser.id ?? undefined, {
environment: process.env.NODE_ENV,
email: sessionUser.email ?? undefined,
name: sessionUser.name ?? undefined,
featureFlags: sessionUser.featureFlags ?? undefined,
- v4BetaEnabled: sessionUser.v4BetaEnabled ?? false,
projects:
sessionUser.organizations.flatMap((org) =>
org.projects.map((project) => ({
@@ -199,7 +199,14 @@ function UserTracking() {
})),
) ?? undefined,
LANGFUSE_CLOUD_REGION: region,
+ [V4_BETA_ENABLED_POSTHOG_PROPERTY]:
+ sessionUser.v4BetaEnabled ?? false,
});
+ posthog.register({
+ [V4_BETA_ENABLED_POSTHOG_PROPERTY]:
+ sessionUser.v4BetaEnabled ?? false,
+ });
+ }
// Sentry
setUser({
@@ -208,6 +215,7 @@ function UserTracking() {
});
} else if (session.status === "unauthenticated") {
lastIdentifiedUser.current = null;
+ posthog.unregister(V4_BETA_ENABLED_POSTHOG_PROPERTY);
// Sentry
setUser(null);
}