Skip to content

Automate browser based workflows with AI

Add PostHog custom events for builder interactions (SKY-8413) (#5179)

Shuchang Zheng59c28ae36c3d
diff --git a/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx b/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
index ef14e8221..902c570ea 100644
--- a/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
@@ -1,3 +1,4 @@
+import { usePostHog } from "posthog-js/react";
import { LogoMinimized } from "@/components/LogoMinimized";
import { Button } from "@/components/ui/button";
import {
@@ -321,6 +322,7 @@ function FlowRenderer({
}: Props) {
const { blockLabel: targettedBlockLabel } = useParams();
const reactFlowInstance = useReactFlow();
+ const postHog = usePostHog();
const debugStore = useDebugStore();
const { title, initializeTitle } = useWorkflowTitleStore();
// const [parameters] = useState<ParametersState>(initialParameters);
@@ -636,10 +638,21 @@ function FlowRenderer({
);
workflowChangesStore.setHasChanges(true);
+ postHog.capture("builder.block.removed", {
+ org_id: workflow.organization_id,
+ block_type: node.type,
+ });
doLayout(newNodesWithUpdatedParameters, newEdges);
},
- [nodes, edges, doLayout, workflowChangesStore],
+ [
+ nodes,
+ edges,
+ doLayout,
+ workflowChangesStore,
+ postHog,
+ workflow.organization_id,
+ ],
);
// Use a ref to always have access to the latest deleteNode without causing re-renders
diff --git a/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx b/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx
index 0480ce557..a87c88c45 100644
--- a/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/Workspace.tsx
@@ -26,6 +26,7 @@ import {
Edge,
} from "@xyflow/react";
import { useMutation, useQueryClient } from "@tanstack/react-query";
+import { usePostHog } from "posthog-js/react";
import { getClient } from "@/api/AxiosClient";
import { DebugSessionApiResponse } from "@/api/types";
@@ -241,6 +242,7 @@ function Workspace({
const [nudge, setNudge] = useState(false);
const { workflowPanelState, setWorkflowPanelState, closeWorkflowPanel } =
useWorkflowPanelStore();
+ const postHog = usePostHog();
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
const { getNodes, getEdges } = useReactFlow();
@@ -996,6 +998,11 @@ function Workspace({
...nodes.slice(previousNodeIndex + 1),
];
workflowChangesStore.setHasChanges(true);
+ postHog.capture("builder.block.added", {
+ org_id: workflow.organization_id,
+ block_type: nodeType,
+ position: previousNodeIndex + 1,
+ });
doLayout(newNodesAfter, [...editedEdges, ...newEdges]);
}
diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunRecording.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunRecording.tsx
index b57e246a2..aa5eb45f1 100644
--- a/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunRecording.tsx
+++ b/skyvern-frontend/src/routes/workflows/workflowRun/WorkflowRunRecording.tsx
@@ -1,14 +1,32 @@
+import { usePostHog } from "posthog-js/react";
import { useWorkflowRunWithWorkflowQuery } from "../hooks/useWorkflowRunWithWorkflowQuery";
import { artifactApiBaseUrl } from "@/util/env";
function WorkflowRunRecording() {
+ const postHog = usePostHog();
const { data: workflowRun } = useWorkflowRunWithWorkflowQuery();
let recordingURL = workflowRun?.recording_url;
if (recordingURL?.startsWith("file://")) {
recordingURL = `${artifactApiBaseUrl}/artifact/recording?path=${recordingURL.slice(7)}`;
}
+
+ function handlePlay() {
+ if (!workflowRun) {
+ return;
+ }
+ postHog.capture("run.recording.viewed", {
+ org_id: workflowRun.workflow.organization_id,
+ run_id: workflowRun.workflow_run_id,
+ });
+ }
+
return recordingURL ? (
- <video src={recordingURL} controls className="w-full rounded-md" />
+ <video
+ src={recordingURL}
+ controls
+ className="w-full rounded-md"
+ onPlay={handlePlay}
+ />
) : (
<div>No recording available for this workflow</div>
);
diff --git a/skyvern-frontend/src/store/WorkflowHasChangesStore.ts b/skyvern-frontend/src/store/WorkflowHasChangesStore.ts
index 1fdf74dd2..a298a8d30 100644
--- a/skyvern-frontend/src/store/WorkflowHasChangesStore.ts
+++ b/skyvern-frontend/src/store/WorkflowHasChangesStore.ts
@@ -3,6 +3,7 @@ import { useEffect } from "react";
import { create } from "zustand";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { stringify as convertToYAML } from "yaml";
+import { usePostHog } from "posthog-js/react";
import { getClient } from "@/api/AxiosClient";
import { toast } from "@/components/ui/use-toast";
@@ -84,6 +85,7 @@ const useWorkflowHasChangesStore = create<WorkflowHasChangesStore>((set) => {
const useWorkflowSave = (opts?: WorkflowSaveOpts) => {
const credentialGetter = useCredentialGetter();
const queryClient = useQueryClient();
+ const postHog = usePostHog();
const {
getSaveData,
saidOkToCodeCacheDeletion,
@@ -193,6 +195,13 @@ const useWorkflowSave = (opts?: WorkflowSaveOpts) => {
return;
}
+ postHog.capture("builder.workflow.saved", {
+ org_id: saveData.workflow.organization_id,
+ workflow_permanent_id: saveData.workflow.workflow_permanent_id,
+ block_count: saveData.blocks.length,
+ block_types: saveData.blocks.map((b) => b.block_type),
+ });
+
toast({
title: "Changes saved",
description: "Your changes have been saved",