Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
♻️ Move posthog identify to user provider (#2207)
Luke Vellab3edc713dd3d
diff --git a/apps/web/src/app/[locale]/layout.tsx b/apps/web/src/app/[locale]/layout.tsxindex c99255eeb..24386c7d4 100644--- a/apps/web/src/app/[locale]/layout.tsx+++ b/apps/web/src/app/[locale]/layout.tsx@@ -26,7 +26,6 @@ import { TRPCProvider } from "@/trpc/client/provider";import { getForegroundColor } from "@/utils/color";import { ConnectedDayjsProvider } from "@/utils/dayjs";import { PostHogPageView } from "../posthog-page-view";-import { PostHogIdentify } from "./posthog-identify";const inter = Inter({subsets: ["latin"],@@ -105,9 +104,6 @@ export default async function Root({<TRPCProvider><LazyMotion features={domAnimation}><PostHogProvider>- <PostHogIdentify- distinctId={user && !user.isGuest ? user.id : undefined}- /><PostHogPageView /><TooltipProvider><UserProvider user={user ?? undefined}>diff --git a/apps/web/src/app/[locale]/posthog-identify.tsx b/apps/web/src/app/[locale]/posthog-identify.tsxdeleted file mode 100644index f45c2db63..000000000--- a/apps/web/src/app/[locale]/posthog-identify.tsx+++ /dev/null@@ -1,18 +0,0 @@-"use client";-import { usePostHog } from "@rallly/posthog/client";-import useMount from "react-use/lib/useMount";-import { useTheme } from "@/features/theme/client";--export function PostHogIdentify({ distinctId }: { distinctId?: string }) {- const posthog = usePostHog();- const { theme } = useTheme();- useMount(() => {- if (posthog && distinctId) {- posthog.identify(distinctId, {- theme,- });- }- });-- return null;-}diff --git a/apps/web/src/components/user-provider.tsx b/apps/web/src/components/user-provider.tsxindex cbc55fafc..795cf49e3 100644--- a/apps/web/src/components/user-provider.tsx+++ b/apps/web/src/components/user-provider.tsx@@ -1,4 +1,5 @@"use client";+import { usePostHog } from "@rallly/posthog/client";import { useRouter } from "next/navigation";import React from "react";import type { UserAbility } from "@/features/user/ability";@@ -36,6 +37,17 @@ export const UserProvider = ({children?: React.ReactNode;user?: UserDTO;}) => {+ const posthog = usePostHog();++ const userId = user?.id;+ const isGuest = user?.isGuest;++ React.useEffect(() => {+ if (userId && !isGuest) {+ posthog.identify(userId);+ }+ }, [userId, isGuest, posthog]);+const router = useRouter();const value = React.useMemo<UserContextValue>(() => {return {