Skip to content

Commit

Permalink
Add comprehensive analytics tracking (#5271)
Browse files Browse the repository at this point in the history
Co-authored-by: openhands <[email protected]>
  • Loading branch information
xingyaoww and openhands-agent authored Dec 2, 2024
1 parent 871c544 commit 2f11634
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions frontend/__tests__/components/browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { describe, it, expect } from "vitest";
import { renderWithProviders } from "../../test-utils";
import { BrowserPanel } from "#/components/features/browser/browser";


describe("Browser", () => {
it("renders a message if no screenshotSrc is provided", () => {
renderWithProviders(<BrowserPanel />, {
Expand Down
31 changes: 27 additions & 4 deletions frontend/src/components/features/chat/chat-interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ import { ContinueButton } from "#/components/shared/buttons/continue-button";
import { ScrollToBottomButton } from "#/components/shared/buttons/scroll-to-bottom-button";
import { LoadingSpinner } from "#/components/shared/loading-spinner";

function getEntryPoint(
hasRepository: boolean | null,
hasImportedProjectZip: boolean | null,
): string {
if (hasRepository) return "github";
if (hasImportedProjectZip) return "zip";
return "direct";
}

export function ChatInterface() {
const { send, isLoadingMessages } = useWsClient();
const dispatch = useDispatch();

const scrollRef = React.useRef<HTMLDivElement>(null);
const { scrollDomToBottom, onChatBodyScroll, hitBottom } =
useScrollToBottom(scrollRef);
Expand All @@ -36,11 +44,26 @@ export function ChatInterface() {
>("positive");
const [feedbackModalIsOpen, setFeedbackModalIsOpen] = React.useState(false);
const [messageToSend, setMessageToSend] = React.useState<string | null>(null);
const { selectedRepository, importedProjectZip } = useSelector(
(state: RootState) => state.initalQuery,
);

const handleSendMessage = async (content: string, files: File[]) => {
posthog.capture("user_message_sent", {
current_message_count: messages.length,
});
if (messages.length === 0) {
posthog.capture("initial_query_submitted", {
entry_point: getEntryPoint(
selectedRepository !== null,
importedProjectZip !== null,
),
query_character_length: content.length,
uploaded_zip_size: importedProjectZip?.length,
});
} else {
posthog.capture("user_message_sent", {
session_message_count: messages.length,
current_message_length: content.length,
});
}
const promises = files.map((file) => convertImageToBase64(file));
const imageUrls = await Promise.all(promises);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Autocomplete, AutocompleteItem } from "@nextui-org/react";
import { useDispatch } from "react-redux";
import posthog from "posthog-js";
import { setSelectedRepository } from "#/state/initial-query-slice";

interface GitHubRepositorySelectorProps {
Expand All @@ -18,6 +19,7 @@ export function GitHubRepositorySelector({
if (repo) {
// set query param
dispatch(setSelectedRepository(repo.full_name));
posthog.capture("repository_selected");
onSelect();
}
};
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/shared/task-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ export const TaskForm = React.forwardRef<HTMLFormElement>((_, ref) => {
if (q) dispatch(setInitialQuery(q));

posthog.capture("initial_query_submitted", {
entry_point: "task_form",
query_character_length: q?.length,
has_repository: !!selectedRepository,
has_files: files.length > 0,
});

navigate("/app");
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/routes/_oh._index/route.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useLocation, useNavigate } from "react-router";
import React from "react";
import { useDispatch } from "react-redux";
import posthog from "posthog-js";
import { setImportedProjectZip } from "#/state/initial-query-slice";
import { convertZipToBase64 } from "#/utils/convert-zip-to-base64";
import { useUserRepositories } from "#/hooks/query/use-user-repositories";
Expand Down Expand Up @@ -61,6 +62,7 @@ function Home() {
if (event.target.files) {
const zip = event.target.files[0];
dispatch(setImportedProjectZip(await convertZipToBase64(zip)));
posthog.capture("zip_file_uploaded");
formRef.current?.requestSubmit();
} else {
// TODO: handle error
Expand Down

0 comments on commit 2f11634

Please sign in to comment.