🚧 basic posthog setup

This commit is contained in:
Nate Sesti 2023-12-10 16:20:05 -08:00
parent a1ef91c535
commit 65bd09b49a
2 changed files with 18 additions and 1 deletions

View file

@ -12,11 +12,15 @@ const CustomPostHogProvider = ({ children }: PropsWithChildren) => {
const [client, setClient] = React.useState<any>(undefined);
useEffect(() => {
if (allowAnonymousTelemetry) {
if (
allowAnonymousTelemetry === true ||
allowAnonymousTelemetry === undefined
) {
posthog.init("phc_JS6XFROuNbhJtVCEdTSYk6gl5ArRrTNMpCcguAXlSPs", {
api_host: "https://app.posthog.com",
disable_session_recording: true,
});
posthog.identify((window as any).vscMachineId);
setClient(client);
} else {
setClient(undefined);

View file

@ -4,6 +4,7 @@ import { SlashCommand } from "core/commands";
import { ExtensionIde } from "core/ide";
import { constructMessages } from "core/llm/constructMessages";
import { ChatHistory, ChatHistoryItem, ChatMessage } from "core/llm/types";
import { usePostHog } from "posthog-js/react";
import { useEffect, useRef } from "react";
import { useSelector } from "react-redux";
import { defaultModelSelector } from "../redux/selectors/modelSelectors";
@ -17,6 +18,8 @@ import {
import { RootStore } from "../redux/store";
function useChatHandler(dispatch: Dispatch) {
const posthog = usePostHog();
const defaultModel = useSelector(defaultModelSelector);
const slashCommands = useSelector(
@ -86,6 +89,16 @@ function useChatHandler(dispatch: Dispatch) {
}
async function streamResponse(input: string, index?: number) {
posthog.capture("step run", {
step_name: "User Input",
params: {
user_input: input,
},
});
posthog.capture("userInput", {
input,
});
const message: ChatMessage = {
role: "user",
content: input,