Skip to content

Commit

Permalink
Identify users based on clerk id (#179)
Browse files Browse the repository at this point in the history
* Added identify user

* Don't mask searches
  • Loading branch information
Xavilien authored Nov 10, 2024
1 parent 1402d71 commit 15072a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 7 additions & 1 deletion apps/frontend/src/app/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ export function PHProvider({
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY || "", {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
person_profiles: 'identified_only',
capture_pageview: false // Disable automatic pageview capture, as we capture manually
capture_pageview: false, // Disable automatic pageview capture, as we capture manually
session_recording: {
maskAllInputs: false,
maskInputOptions: {
password: true,
}
}
})
}, []);

Expand Down
13 changes: 12 additions & 1 deletion apps/frontend/src/components/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { SideNav } from "./SideNav";
import Link from "./Link";
import { useAuth } from "@clerk/nextjs";
import { userSlice } from "~/app/user";
import { usePostHog } from "posthog-js/react";

type Props = {
sidebar?: React.ReactNode;
Expand All @@ -23,7 +24,7 @@ export const Page = ({ sidebar, content, activePage }: Props) => {
);
const dispatch = useAppDispatch();

const { isLoaded, userId, sessionId, getToken } = useAuth();
const { isLoaded, isSignedIn, userId, sessionId, getToken } = useAuth();

useEffect(() => {
if (isLoaded && userId && sessionId) {
Expand All @@ -50,6 +51,16 @@ export const Page = ({ sidebar, content, activePage }: Props) => {
}
}, [dispatch, loggedIn, modalShown]);

const posthog = usePostHog();

useEffect(() => {
if (isSignedIn && userId) {
posthog?.identify(userId);
} else {
posthog?.reset();
}
}, [posthog, isSignedIn, userId]);

return (
<div className="accent-blue-600 dark:accent-blue-800">
<LoginModal />
Expand Down

0 comments on commit 15072a3

Please sign in to comment.