Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TOOL-3569] Dashboard: Add acount.id to posthog identify calls #6377

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/dashboard/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import NextTopLoader from "nextjs-toploader";
import { Suspense } from "react";
import { OrganizeContractsToProjectsBanner } from "../components/notices/AnnouncementBanner";
import { OpCreditsGrantedModalWrapperServer } from "../components/onboarding/OpCreditsGrantedModalWrapperServer";
import { PosthogIdentifierServer } from "../components/wallets/PosthogIdentifierServer";
import { EnsureValidConnectedWalletLoginServer } from "./components/EnsureValidConnectedWalletLogin/EnsureValidConnectedWalletLoginServer";
import { PostHogProvider } from "./components/root-providers";
import { AppRouterProviders } from "./providers";
Expand Down Expand Up @@ -80,6 +81,9 @@ export default function RootLayout({
<Suspense fallback={null}>
<EnsureValidConnectedWalletLoginServer />
</Suspense>
<Suspense fallback={null}>
<PosthogIdentifierServer />
</Suspense>
</AppRouterProviders>
<DashboardRouterTopProgressBar />
<NextTopLoader
Expand Down
2 changes: 0 additions & 2 deletions apps/dashboard/src/app/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
useConnectionManager,
} from "thirdweb/react";
import { CustomConnectWallet } from "../@3rdweb-sdk/react/components/connect-wallet";
import { PosthogIdentifier } from "../components/wallets/PosthogIdentifier";
import { isSanctionedAddress } from "../data/eth-sanctioned-addresses";
import { useAllChainsData } from "../hooks/chains/allChains";
import { SyncChainStores } from "../stores/chainStores";
Expand All @@ -27,7 +26,6 @@ export function AppRouterProviders(props: { children: React.ReactNode }) {
<ThirdwebProvider>
<SyncChainDefinitionsToConnectionManager />
<TWAutoConnect />
<PosthogIdentifier />
<ThemeProvider
attribute="class"
disableTransitionOnChange
Expand Down
18 changes: 14 additions & 4 deletions apps/dashboard/src/components/wallets/PosthogIdentifier.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const walletIdToPHName: Record<string, string> = {
injected: "Injected",
};

export const PosthogIdentifier: React.FC = () => {
export const PosthogIdentifierClient: React.FC<{
accountId: string | undefined;
accountAddress: string | undefined;
}> = ({ accountId, accountAddress }) => {
const client = useThirdwebClient();
const account = useActiveAccount();
const chain = useActiveWalletChain();
Expand All @@ -43,10 +46,17 @@ export const PosthogIdentifier: React.FC = () => {
// legitimate use-case
// eslint-disable-next-line no-restricted-syntax
useEffect(() => {
if (account?.address) {
posthog.identify(account.address);
if (accountAddress) {
posthog.identify(accountAddress);
}
}, [account?.address]);
}, [accountAddress]);

// eslint-disable-next-line no-restricted-syntax
useEffect(() => {
if (accountId) {
posthog.identify(accountId);
}
}, [accountId]);

// legitimate use-case
// eslint-disable-next-line no-restricted-syntax
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getRawAccount } from "../../app/account/settings/getAccount";
import { getAuthTokenWalletAddress } from "../../app/api/lib/getAuthToken";
import { PosthogIdentifierClient } from "./PosthogIdentifier";

export async function PosthogIdentifierServer() {
const [account, accountAddress] = await Promise.all([
getRawAccount(),
getAuthTokenWalletAddress(),
]);

return (
<PosthogIdentifierClient
accountId={account?.id}
accountAddress={accountAddress || undefined}
/>
);
}
Loading