File tree Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ "use client" ;
2
+
3
+ import posthog from "posthog-js" ;
4
+ import { useEffect } from "react" ;
5
+
6
+ export function useIdentifyAccount ( opts ?: {
7
+ accountId : string ;
8
+ email ?: string ;
9
+ } ) {
10
+ // eslint-disable-next-line no-restricted-syntax
11
+ useEffect ( ( ) => {
12
+ if ( ! posthog . __loaded ) {
13
+ // posthog is not loaded yet, so we can't identify the account
14
+ return ;
15
+ }
16
+ // if no accountId, don't identify
17
+ if ( ! opts ?. accountId ) {
18
+ return ;
19
+ }
20
+
21
+ // if email is provided, add it to the identify
22
+ posthog . identify ( opts . accountId , opts . email ? { email : opts . email } : { } ) ;
23
+ } , [ opts ?. accountId , opts ?. email ] ) ;
24
+ }
Original file line number Diff line number Diff line change
1
+ "use client" ;
2
+
3
+ import posthog from "posthog-js" ;
4
+ import { useEffect } from "react" ;
5
+
6
+ export function useIdentifyTeam ( opts ?: {
7
+ teamId : string ;
8
+ } ) {
9
+ // eslint-disable-next-line no-restricted-syntax
10
+ useEffect ( ( ) => {
11
+ if ( ! posthog . __loaded ) {
12
+ // posthog is not loaded yet, so we can't identify the team
13
+ return ;
14
+ }
15
+ // if no teamId, don't identify
16
+ if ( ! opts ?. teamId ) {
17
+ return ;
18
+ }
19
+
20
+ // identify the team
21
+ posthog . group ( "team" , opts . teamId ) ;
22
+ } , [ opts ?. teamId ] ) ;
23
+ }
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ import type { ThirdwebClient } from "thirdweb";
13
13
import { useActiveWallet , useDisconnect } from "thirdweb/react" ;
14
14
import { doLogout } from "../../../login/auth-actions" ;
15
15
16
+ import { useIdentifyAccount } from "../../../../../@/analytics/hooks/identify-account" ;
17
+ import { useIdentifyTeam } from "../../../../../@/analytics/hooks/identify-team" ;
16
18
import {
17
19
type TeamHeaderCompProps ,
18
20
TeamHeaderDesktopUI ,
@@ -27,6 +29,16 @@ export function TeamHeaderLoggedIn(props: {
27
29
accountAddress : string ;
28
30
client : ThirdwebClient ;
29
31
} ) {
32
+ // identify the account
33
+ useIdentifyAccount ( {
34
+ accountId : props . account . id ,
35
+ email : props . account . email ,
36
+ } ) ;
37
+
38
+ // identify the team
39
+ useIdentifyTeam ( {
40
+ teamId : props . currentTeam . id ,
41
+ } ) ;
30
42
const [ createProjectDialogState , setCreateProjectDialogState ] = useState <
31
43
{ team : Team ; isOpen : true } | { isOpen : false }
32
44
> ( { isOpen : false } ) ;
You can’t perform that action at this time.
0 commit comments