File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 11"use client" ;
22
3- import { useEffect } from "react" ;
43import posthog from "posthog-js" ;
54import { PostHogProvider as PHProvider } from "posthog-js/react" ;
5+ import { useEffect } from "react" ;
6+
7+ import UserIdentification from "./user-identification" ;
68
79import { env } from "~/env" ;
810
@@ -16,5 +18,10 @@ export function PostHogProvider({ children }: { children: React.ReactNode }) {
1618 } ) ;
1719 } , [ ] ) ;
1820
19- return < PHProvider client = { posthog } > { children } </ PHProvider > ;
21+ return (
22+ < PHProvider client = { posthog } >
23+ < UserIdentification />
24+ { children }
25+ </ PHProvider >
26+ ) ;
2027}
Original file line number Diff line number Diff line change 1+ import { useUser } from "@clerk/nextjs" ;
2+ import { usePostHog } from "posthog-js/react" ;
3+ import { useEffect } from "react" ;
4+
5+ export default function UserIdentification ( ) {
6+ const posthog = usePostHog ( ) ;
7+ const { user } = useUser ( ) ;
8+
9+ useEffect ( ( ) => {
10+ if ( user ) {
11+ posthog . identify ( user . id , {
12+ email : user . emailAddresses [ 0 ] ?. emailAddress ,
13+ } ) ;
14+ } else {
15+ posthog . reset ( ) ;
16+ }
17+ } , [ posthog , user ] ) ;
18+
19+ return null ; // Do not render anything
20+ }
You can’t perform that action at this time.
0 commit comments