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";
1313import { useActiveWallet , useDisconnect } from "thirdweb/react" ;
1414import { doLogout } from "../../../login/auth-actions" ;
1515
16+ import { useIdentifyAccount } from "../../../../../@/analytics/hooks/identify-account" ;
17+ import { useIdentifyTeam } from "../../../../../@/analytics/hooks/identify-team" ;
1618import {
1719 type TeamHeaderCompProps ,
1820 TeamHeaderDesktopUI ,
@@ -27,6 +29,16 @@ export function TeamHeaderLoggedIn(props: {
2729 accountAddress : string ;
2830 client : ThirdwebClient ;
2931} ) {
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+ } ) ;
3042 const [ createProjectDialogState , setCreateProjectDialogState ] = useState <
3143 { team : Team ; isOpen : true } | { isOpen : false }
3244 > ( { isOpen : false } ) ;
You can’t perform that action at this time.
0 commit comments