Skip to content

Commit 3d8eba4

Browse files
committed
posthog migration part 2
1 parent ab980d8 commit 3d8eba4

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}

apps/dashboard/src/app/(app)/team/components/TeamHeader/team-header-logged-in.client.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import type { ThirdwebClient } from "thirdweb";
1313
import { useActiveWallet, useDisconnect } from "thirdweb/react";
1414
import { doLogout } from "../../../login/auth-actions";
1515

16+
import { useIdentifyAccount } from "../../../../../@/analytics/hooks/identify-account";
17+
import { useIdentifyTeam } from "../../../../../@/analytics/hooks/identify-team";
1618
import {
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 });

0 commit comments

Comments
 (0)