From 6833be9e56716373e0b754bc8b1e55d904a40447 Mon Sep 17 00:00:00 2001 From: Konstantin Wohlwend Date: Tue, 20 Aug 2024 19:03:47 -0700 Subject: [PATCH] Add PostHog groups --- apps/dashboard/src/app/providers.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/src/app/providers.tsx b/apps/dashboard/src/app/providers.tsx index 0bde24c05..81859da7f 100644 --- a/apps/dashboard/src/app/providers.tsx +++ b/apps/dashboard/src/app/providers.tsx @@ -1,5 +1,5 @@ 'use client'; -import { useUser } from '@stackframe/stack'; +import { useStackApp, useUser } from '@stackframe/stack'; import posthog from 'posthog-js'; import { PostHogProvider } from 'posthog-js/react'; import { Suspense, useEffect, useState } from 'react'; @@ -25,6 +25,7 @@ export function UserIdentity() { function UserIdentityInner() { const [lastUserId, setLastUserId] = useState(null); + const app = useStackApp(); const user = useUser(); useEffect(() => { @@ -33,9 +34,11 @@ function UserIdentityInner() { primaryEmail: user.primaryEmail, displayName: user.displayName ?? user.primaryEmail ?? user.id, }); + posthog.group("projectId", app.projectId); setLastUserId(user.id); } else if (!user && lastUserId) { posthog.reset(); + posthog.resetGroups(); setLastUserId(null); } }, [user, lastUserId]);