Skip to content

Commit 171cd31

Browse files
committed
chore: enhanced posthog tracking
1 parent 5bd250d commit 171cd31

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/client/app/chat/page.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export default function ChatPage() {
129129
const ringtoneAudioRef = useRef(null)
130130
const connectedAudioRef = useRef(null)
131131
const remoteAudioRef = useRef(null)
132+
const voiceModeStartTimeRef = useRef(null)
132133

133134
const fetchInitialMessages = useCallback(async () => {
134135
setIsLoading(true)
@@ -848,6 +849,16 @@ export default function ChatPage() {
848849

849850
webrtcClientRef.current?.disconnect()
850851

852+
// --- ADD POSTHOG EVENT TRACKING ---
853+
if (voiceModeStartTimeRef.current) {
854+
const duration_seconds = Math.round(
855+
(Date.now() - voiceModeStartTimeRef.current) / 1000
856+
)
857+
posthog?.capture("voice_mode_used", { duration_seconds })
858+
voiceModeStartTimeRef.current = null // Reset after tracking
859+
}
860+
// --- END POSTHOG EVENT TRACKING ---
861+
851862
// 2. Immediately stop any playing audio.
852863
if (ringtoneAudioRef.current) {
853864
ringtoneAudioRef.current.pause()
@@ -872,6 +883,10 @@ export default function ChatPage() {
872883
// Switching TO voice mode, first get permissions
873884
const permissionsGranted = await initializeVoiceMode()
874885
if (permissionsGranted) {
886+
// --- ADD POSTHOG EVENT TRACKING ---
887+
posthog?.capture("voice_mode_activated")
888+
voiceModeStartTimeRef.current = Date.now() // Set start time
889+
// --- END POSTHOG EVENT TRACKING ---
875890
setIsVoiceMode(true)
876891
}
877892
}

src/client/app/settings/page.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
} from "@tabler/icons-react"
2424
import { useState, useEffect, useCallback, Fragment } from "react"
2525
import { Tooltip } from "react-tooltip"
26+
import { usePostHog } from "posthog-js/react"
2627
import { cn } from "@utils/cn"
2728
import { Switch } from "@headlessui/react"
2829

@@ -686,6 +687,7 @@ const TestingTools = () => {
686687
const ProactivitySettings = () => {
687688
const [isEnabled, setIsEnabled] = useState(false)
688689
const [isLoading, setIsLoading] = useState(true)
690+
const posthog = usePostHog()
689691

690692
useEffect(() => {
691693
const fetchStatus = async () => {
@@ -709,6 +711,12 @@ const ProactivitySettings = () => {
709711
const toastId = toast.loading(
710712
enabled ? "Enabling proactivity..." : "Disabling proactivity..."
711713
)
714+
715+
// --- ADD POSTHOG EVENT TRACKING ---
716+
if (enabled) {
717+
posthog?.capture("proactive_assistance_enabled")
718+
}
719+
// --- END POSTHOG EVENT TRACKING ---
712720
try {
713721
const response = await fetch("/api/settings/proactivity", {
714722
method: "POST",

src/server/main/proactivity/routes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from main.proactivity.models import SuggestionActionRequest
88
from main.proactivity.learning import record_user_feedback
99
from workers.tasks import create_task_from_suggestion
10+
from main.analytics import capture_event
1011

1112
logger = logging.getLogger(__name__)
1213
router = APIRouter(
@@ -45,6 +46,13 @@ async def handle_suggestion_action(
4546
if request.user_action == "approved":
4647
logger.info(f"User '{user_id}' approved suggestion '{request.notification_id}' of type '{suggestion_type}'.")
4748

49+
# --- ADD POSTHOG EVENT TRACKING ---
50+
capture_event(
51+
user_id,
52+
"proactive_suggestion_approved",
53+
{"suggestion_type": suggestion_type}
54+
)
55+
# --- END POSTHOG EVENT TRACKING ---
4856
# Re-extract with default for robustness, as suggested by diff
4957
suggestion_payload = notification.get("suggestion_payload", {})
5058
gathered_context = suggestion_payload.get("gathered_context")
@@ -64,6 +72,13 @@ async def handle_suggestion_action(
6472
elif request.user_action == "dismissed":
6573
logger.info(f"User '{user_id}' dismissed suggestion '{request.notification_id}' of type '{suggestion_type}'.")
6674

75+
# --- ADD POSTHOG EVENT TRACKING ---
76+
capture_event(
77+
user_id,
78+
"proactive_suggestion_dismissed",
79+
{"suggestion_type": suggestion_type}
80+
)
81+
# --- END POSTHOG EVENT TRACKING ---
6782
# 3c. Record negative feedback
6883
await record_user_feedback(user_id, suggestion_type, "negative")
6984

src/server/workers/tasks.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,15 @@ async def async_refine_and_plan_ai_task(task_id: str, user_id: str):
229229
parsed_data = JsonExtractor.extract_valid_json(clean_llm_output(response_str))
230230
if parsed_data:
231231
# Safeguard: never allow the refiner to nullify or change the user_id
232+
# --- ADD POSTHOG EVENT TRACKING ---
233+
schedule_type = parsed_data.get("schedule", {}).get("type", "once")
234+
capture_event(
235+
user_id,
236+
"task_created",
237+
{"task_id": task_id, "schedule_type": schedule_type, "source": "prompt"}
238+
)
239+
# --- END POSTHOG EVENT TRACKING ---
240+
232241
if "user_id" in parsed_data:
233242
del parsed_data["user_id"]
234243

0 commit comments

Comments
 (0)