Skip to content

Commit 062504f

Browse files
committed
[TOOL-3569] Dashboard: Add acount.id to posthog identify calls (#6377)
1 parent 853ed47 commit 062504f

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

apps/dashboard/src/app/layout.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import NextTopLoader from "nextjs-toploader";
88
import { Suspense } from "react";
99
import { OrganizeContractsToProjectsBanner } from "../components/notices/AnnouncementBanner";
1010
import { OpCreditsGrantedModalWrapperServer } from "../components/onboarding/OpCreditsGrantedModalWrapperServer";
11+
import { PosthogIdentifierServer } from "../components/wallets/PosthogIdentifierServer";
1112
import { EnsureValidConnectedWalletLoginServer } from "./components/EnsureValidConnectedWalletLogin/EnsureValidConnectedWalletLoginServer";
1213
import { PostHogProvider } from "./components/root-providers";
1314
import { AppRouterProviders } from "./providers";
@@ -80,6 +81,9 @@ export default function RootLayout({
8081
<Suspense fallback={null}>
8182
<EnsureValidConnectedWalletLoginServer />
8283
</Suspense>
84+
<Suspense fallback={null}>
85+
<PosthogIdentifierServer />
86+
</Suspense>
8387
</AppRouterProviders>
8488
<DashboardRouterTopProgressBar />
8589
<NextTopLoader

apps/dashboard/src/app/providers.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
useConnectionManager,
1212
} from "thirdweb/react";
1313
import { CustomConnectWallet } from "../@3rdweb-sdk/react/components/connect-wallet";
14-
import { PosthogIdentifier } from "../components/wallets/PosthogIdentifier";
1514
import { isSanctionedAddress } from "../data/eth-sanctioned-addresses";
1615
import { useAllChainsData } from "../hooks/chains/allChains";
1716
import { SyncChainStores } from "../stores/chainStores";
@@ -27,7 +26,6 @@ export function AppRouterProviders(props: { children: React.ReactNode }) {
2726
<ThirdwebProvider>
2827
<SyncChainDefinitionsToConnectionManager />
2928
<TWAutoConnect />
30-
<PosthogIdentifier />
3129
<ThemeProvider
3230
attribute="class"
3331
disableTransitionOnChange

apps/dashboard/src/components/wallets/PosthogIdentifier.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ const walletIdToPHName: Record<string, string> = {
1919
injected: "Injected",
2020
};
2121

22-
export const PosthogIdentifier: React.FC = () => {
22+
export const PosthogIdentifierClient: React.FC<{
23+
accountId: string | undefined;
24+
accountAddress: string | undefined;
25+
}> = ({ accountId, accountAddress }) => {
2326
const client = useThirdwebClient();
2427
const account = useActiveAccount();
2528
const chain = useActiveWalletChain();
@@ -43,10 +46,17 @@ export const PosthogIdentifier: React.FC = () => {
4346
// legitimate use-case
4447
// eslint-disable-next-line no-restricted-syntax
4548
useEffect(() => {
46-
if (account?.address) {
47-
posthog.identify(account.address);
49+
if (accountAddress) {
50+
posthog.identify(accountAddress);
4851
}
49-
}, [account?.address]);
52+
}, [accountAddress]);
53+
54+
// eslint-disable-next-line no-restricted-syntax
55+
useEffect(() => {
56+
if (accountId) {
57+
posthog.identify(accountId);
58+
}
59+
}, [accountId]);
5060

5161
// legitimate use-case
5262
// eslint-disable-next-line no-restricted-syntax
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { getRawAccount } from "../../app/account/settings/getAccount";
2+
import { getAuthTokenWalletAddress } from "../../app/api/lib/getAuthToken";
3+
import { PosthogIdentifierClient } from "./PosthogIdentifier";
4+
5+
export async function PosthogIdentifierServer() {
6+
const [account, accountAddress] = await Promise.all([
7+
getRawAccount(),
8+
getAuthTokenWalletAddress(),
9+
]);
10+
11+
return (
12+
<PosthogIdentifierClient
13+
accountId={account?.id}
14+
accountAddress={accountAddress || undefined}
15+
/>
16+
);
17+
}

0 commit comments

Comments
 (0)