Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

feat(analytics): instrument pipe-generation funnel (north-star metric)

Louis Beaumont1d834d146793
diff --git a/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx b/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx
index 755750d16..c1e48fe66 100644
--- a/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx
@@ -2690,6 +2690,31 @@ export function PipesSection() {
if (!value) return;
input.value = "";
+ // North-star funnel: mark the generation attempt so standalone-chat
+ // can fire `pipe_generation_completed` when a new pipe lands.
+ // Baseline captures the current installed list so we can detect the
+ // delta even if the user already has pipes installed.
+ const generationId = crypto.randomUUID();
+ const baseline = pipes.map((p: any) => p?.config?.name).filter(Boolean);
+ try {
+ sessionStorage.setItem(
+ "pipeGenerationContext",
+ JSON.stringify({
+ generation_id: generationId,
+ started_at: Date.now(),
+ prompt_length: value.length,
+ baseline_pipes: baseline,
+ })
+ );
+ } catch {
+ // sessionStorage unavailable — funnel will miss this attempt, not fatal
+ }
+ posthog.capture("pipe_generation_started", {
+ generation_id: generationId,
+ prompt_length: value.length,
+ baseline_pipe_count: baseline.length,
+ });
+
navigateHomeAndPrefill({
context: PIPE_CREATION_PROMPT,
prompt: value,
diff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
index 38d15c496..9783ec0ba 100644
--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx
+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
@@ -1349,9 +1349,78 @@ export function StandaloneChat({ className }: { className?: string } = {}) {
setTimeout(() => emit("chat-prefill", data), 500);
} catch {}
}
+ // Clean up stale pipe-generation markers (>30 min old) so they don't
+ // leak into a future unrelated chat session.
+ try {
+ const raw = sessionStorage.getItem("pipeGenerationContext");
+ if (raw) {
+ const ctx = JSON.parse(raw);
+ if (!ctx?.started_at || Date.now() - ctx.started_at > 30 * 60 * 1000) {
+ sessionStorage.removeItem("pipeGenerationContext");
+ if (ctx?.generation_id) {
+ posthog.capture("pipe_generation_abandoned", {
+ generation_id: ctx.generation_id,
+ age_ms: Date.now() - (ctx.started_at ?? Date.now()),
+ });
+ }
+ }
+ }
+ } catch {}
return () => { unlisten.then((fn) => fn()); };
}, []);
+ // Pipe-generation funnel completion detector.
+ // Fires `pipe_generation_completed` the first time Pi's message stream
+ // ends (isLoading: true → false) AFTER we see a new pipe installed
+ // compared to the baseline captured when the user submitted the
+ // "describe a pipe to create" form. Single-shot per generation_id.
+ const prevIsLoadingRef = useRef(isLoading);
+ useEffect(() => {
+ const wasLoading = prevIsLoadingRef.current;
+ prevIsLoadingRef.current = isLoading;
+ if (!wasLoading || isLoading) return; // only fire on true → false edge
+
+ let cancelled = false;
+ (async () => {
+ let ctx: { generation_id: string; started_at: number; baseline_pipes: string[] } | null = null;
+ try {
+ const raw = sessionStorage.getItem("pipeGenerationContext");
+ if (!raw) return;
+ ctx = JSON.parse(raw);
+ } catch {
+ return;
+ }
+ if (!ctx?.generation_id) return;
+
+ try {
+ const res = await localFetch("/pipes");
+ if (!res.ok) return;
+ const data = await res.json();
+ if (cancelled) return;
+ const installedNames: string[] = (data?.data ?? [])
+ .map((p: any) => p?.config?.name ?? p?.name)
+ .filter((n: unknown): n is string => typeof n === "string");
+ const baseline = new Set(ctx.baseline_pipes ?? []);
+ const newPipes = installedNames.filter((n) => !baseline.has(n));
+ if (newPipes.length === 0) return;
+
+ posthog.capture("pipe_generation_completed", {
+ generation_id: ctx.generation_id,
+ pipe_name: newPipes[0],
+ new_pipes_count: newPipes.length,
+ duration_ms: Date.now() - ctx.started_at,
+ });
+ sessionStorage.removeItem("pipeGenerationContext");
+ } catch {
+ // Leave context in place — maybe the next assistant turn installs the pipe.
+ }
+ })();
+
+ return () => {
+ cancelled = true;
+ };
+ }, [isLoading]);
+
// Guard against duplicate chat-prefill processing. The listener below
// re-subscribes when piInfo changes; during the brief overlap window
// (async unlisten hasn't resolved yet) both old and new listeners can