Skip to content

πŸ™Œ OpenHands: AI-Driven Development

feat(posthog): Identify users logged in with GitHub (#4794)

sp.wack0335b1a63494
diff --git a/frontend/src/api/github.ts b/frontend/src/api/github.ts
index 7b8f20be50..a65c9e5f7b 100644
--- a/frontend/src/api/github.ts
+++ b/frontend/src/api/github.ts
@@ -122,6 +122,9 @@ export const retrieveGitHubUser = async (
id: data.id,
login: data.login,
avatar_url: data.avatar_url,
+ company: data.company,
+ name: data.name,
+ email: data.email,
};
return user;
diff --git a/frontend/src/mocks/handlers.ts b/frontend/src/mocks/handlers.ts
index 97a7f9cf9c..16f2f6972d 100644
--- a/frontend/src/mocks/handlers.ts
+++ b/frontend/src/mocks/handlers.ts
@@ -92,6 +92,9 @@ export const handlers = [
id: 1,
login: "octocat",
avatar_url: "https://avatars.githubusercontent.com/u/583231?v=4",
+ company: "GitHub",
+ email: "[email protected]",
+ name: "monalisa octocat",
};
return HttpResponse.json(user);
diff --git a/frontend/src/routes/_oh.tsx b/frontend/src/routes/_oh.tsx
index 022ad20d1e..0175104f5a 100644
--- a/frontend/src/routes/_oh.tsx
+++ b/frontend/src/routes/_oh.tsx
@@ -54,7 +54,7 @@ export const clientLoader = async ({ request }: ClientLoaderFunctionArgs) => {
if (!userConsents) {
posthog.opt_out_capturing();
- } else {
+ } else if (userConsents && !posthog.has_opted_in_capturing()) {
posthog.opt_in_capturing();
}
@@ -178,6 +178,16 @@ export default function MainApp() {
string | null
>(null);
+ React.useEffect(() => {
+ if (user && !isGitHubErrorReponse(user)) {
+ posthog.identify(user.login, {
+ company: user.company,
+ name: user.name,
+ email: user.email,
+ });
+ }
+ }, [user]);
+
React.useEffect(() => {
// We fetch this here instead of the data loader because the server seems to block
// the retrieval when the session is closing -- preventing the screen from rendering until
diff --git a/frontend/src/routes/logout.ts b/frontend/src/routes/logout.ts
index ffad4e9dd1..879f5118ed 100644
--- a/frontend/src/routes/logout.ts
+++ b/frontend/src/routes/logout.ts
@@ -1,8 +1,11 @@
import { json } from "@remix-run/react";
+import posthog from "posthog-js";
export const clientAction = () => {
const ghToken = localStorage.getItem("ghToken");
if (ghToken) localStorage.removeItem("ghToken");
+ posthog.reset();
+
return json({ success: true });
};
diff --git a/frontend/src/types/github.d.ts b/frontend/src/types/github.d.ts
index 682ecba5d5..20c395ce08 100644
--- a/frontend/src/types/github.d.ts
+++ b/frontend/src/types/github.d.ts
@@ -8,6 +8,9 @@ interface GitHubUser {
id: number;
login: string;
avatar_url: string;
+ company: string | null;
+ name: string | null;
+ email: string | null;
}
interface GitHubRepository {