Skip to content

Commit 4595e69

Browse files
committed
fix(posthog): fix workspace group via URL params, type errors, and clean up comments
1 parent 3e2f991 commit 4595e69

File tree

10 files changed

+32
-21
lines changed

10 files changed

+32
-21
lines changed

apps/sim/app/(auth)/signup/signup-form.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
'use client'
22

3-
import { Suspense, useMemo, useRef, useState } from 'react'
3+
import { Suspense, useEffect, useMemo, useRef, useState } from 'react'
44
import { Turnstile, type TurnstileInstance } from '@marsidev/react-turnstile'
55
import { createLogger } from '@sim/logger'
66
import { Eye, EyeOff, Loader2 } from 'lucide-react'
77
import Link from 'next/link'
88
import { useRouter, useSearchParams } from 'next/navigation'
9+
import { usePostHog } from 'posthog-js/react'
910
import { Input, Label } from '@/components/emcn'
1011
import { client, useSession } from '@/lib/auth/auth-client'
1112
import { getEnv, isFalsy, isTruthy } from '@/lib/core/config/env'
@@ -81,7 +82,12 @@ function SignupFormContent({
8182
const router = useRouter()
8283
const searchParams = useSearchParams()
8384
const { refetch: refetchSession } = useSession()
85+
const posthog = usePostHog()
8486
const [isLoading, setIsLoading] = useState(false)
87+
88+
useEffect(() => {
89+
posthog?.capture('signup_page_viewed', {})
90+
}, [posthog])
8591
const [showPassword, setShowPassword] = useState(false)
8692
const [password, setPassword] = useState('')
8793
const [passwordErrors, setPasswordErrors] = useState<string[]>([])

apps/sim/app/(home)/landing-analytics.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
import { useEffect } from 'react'
44
import { usePostHog } from 'posthog-js/react'
55

6-
/**
7-
* Fires a `landing_page_viewed` PostHog event on mount.
8-
* Renders nothing — exists only to bridge the server/client boundary
9-
* so the server-rendered landing page can emit analytics.
10-
*/
116
export function LandingAnalytics() {
127
const posthog = usePostHog()
138

apps/sim/app/(home)/landing.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
Templates,
1414
Testimonials,
1515
} from '@/app/(home)/components'
16+
import { LandingAnalytics } from '@/app/(home)/landing-analytics'
1617

1718
/**
1819
* Landing page root component.
@@ -45,6 +46,7 @@ export default async function Landing() {
4546
>
4647
Skip to main content
4748
</a>
49+
<LandingAnalytics />
4850
<StructuredData />
4951
<header>
5052
<Navbar blogPosts={blogPosts} />

apps/sim/app/_shell/providers/session-provider.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@ export function SessionProvider({ children }: { children: React.ReactNode }) {
9292
email_verified: data.user.emailVerified,
9393
created_at: data.user.createdAt,
9494
})
95-
96-
const workspaceId = data.session?.activeOrganizationId
97-
if (workspaceId && typeof posthog.group === 'function') {
98-
posthog.group('workspace', workspaceId)
99-
}
10095
} else {
10196
posthog.reset()
10297
}

apps/sim/app/api/knowledge/[id]/connectors/[connectorId]/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,16 +352,17 @@ export async function DELETE(request: NextRequest, { params }: RouteParams) {
352352
`[${requestId}] Deleted connector ${connectorId}${deleteDocuments ? ` and ${docCount} documents` : `, kept ${docCount} documents`}`
353353
)
354354

355+
const kbWorkspaceId = writeCheck.knowledgeBase.workspaceId ?? ''
355356
captureServerEvent(
356357
auth.userId,
357358
'knowledge_base_connector_removed',
358359
{
359360
knowledge_base_id: knowledgeBaseId,
360-
workspace_id: writeCheck.knowledgeBase.workspaceId,
361+
workspace_id: kbWorkspaceId,
361362
connector_type: existingConnector[0].connectorType,
362363
documents_deleted: deleteDocuments ? docCount : 0,
363364
},
364-
{ groups: { workspace: writeCheck.knowledgeBase.workspaceId } }
365+
kbWorkspaceId ? { groups: { workspace: kbWorkspaceId } } : undefined
365366
)
366367

367368
recordAudit({

apps/sim/app/api/knowledge/[id]/connectors/[connectorId]/sync/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
5656

5757
logger.info(`[${requestId}] Manual sync triggered for connector ${connectorId}`)
5858

59+
const kbWorkspaceId = writeCheck.knowledgeBase.workspaceId ?? ''
5960
captureServerEvent(
6061
auth.userId,
6162
'knowledge_base_connector_synced',
6263
{
6364
knowledge_base_id: knowledgeBaseId,
64-
workspace_id: writeCheck.knowledgeBase.workspaceId,
65+
workspace_id: kbWorkspaceId,
6566
connector_type: connectorRows[0].connectorType,
6667
},
67-
{ groups: { workspace: writeCheck.knowledgeBase.workspaceId } }
68+
kbWorkspaceId ? { groups: { workspace: kbWorkspaceId } } : undefined
6869
)
6970

7071
recordAudit({

apps/sim/app/api/knowledge/[id]/connectors/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,18 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
228228

229229
logger.info(`[${requestId}] Created connector ${connectorId} for KB ${knowledgeBaseId}`)
230230

231+
const kbWorkspaceId = writeCheck.knowledgeBase.workspaceId ?? ''
231232
captureServerEvent(
232233
auth.userId,
233234
'knowledge_base_connector_added',
234235
{
235236
knowledge_base_id: knowledgeBaseId,
236-
workspace_id: writeCheck.knowledgeBase.workspaceId,
237+
workspace_id: kbWorkspaceId,
237238
connector_type: connectorType,
238239
sync_interval_minutes: syncIntervalMinutes,
239240
},
240241
{
241-
groups: { workspace: writeCheck.knowledgeBase.workspaceId },
242+
groups: kbWorkspaceId ? { workspace: kbWorkspaceId } : undefined,
242243
setOnce: { first_connector_added_at: new Date().toISOString() },
243244
}
244245
)

apps/sim/app/workspace/[workspaceId]/providers/workspace-scope-sync.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useEffect } from 'react'
44
import { useParams } from 'next/navigation'
5+
import { usePostHog } from 'posthog-js/react'
56
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
67

78
/**
@@ -11,6 +12,12 @@ export function WorkspaceScopeSync() {
1112
const { workspaceId } = useParams<{ workspaceId: string }>()
1213
const hydrationWorkspaceId = useWorkflowRegistry((state) => state.hydration.workspaceId)
1314
const switchToWorkspace = useWorkflowRegistry((state) => state.switchToWorkspace)
15+
const posthog = usePostHog()
16+
17+
useEffect(() => {
18+
if (!workspaceId) return
19+
posthog?.group('workspace', workspaceId)
20+
}, [posthog, workspaceId])
1421

1522
useEffect(() => {
1623
if (!workspaceId || hydrationWorkspaceId === workspaceId) {

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table/table.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
44
import { GripVertical } from 'lucide-react'
55
import { useParams, useRouter } from 'next/navigation'
6+
import { usePostHog } from 'posthog-js/react'
67
import {
78
Button,
89
Checkbox,
@@ -177,6 +178,12 @@ export function Table({
177178
const router = useRouter()
178179
const workspaceId = propWorkspaceId || (params.workspaceId as string)
179180
const tableId = propTableId || (params.tableId as string)
181+
const posthog = usePostHog()
182+
183+
useEffect(() => {
184+
if (!tableId || !workspaceId) return
185+
posthog?.capture('table_opened', { table_id: tableId, workspace_id: workspaceId })
186+
}, [tableId, workspaceId, posthog])
180187

181188
const [queryOptions, setQueryOptions] = useState<QueryOptions>({
182189
filter: null,

apps/sim/lib/posthog/events.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ export interface PostHogEventMap {
9393
workspace_id: string
9494
}
9595

96-
/** Fired server-side when a user reverts a workflow canvas to a prior deployment snapshot. */
9796
workflow_deployment_reverted: {
9897
workflow_id: string
9998
workspace_id: string
@@ -105,7 +104,6 @@ export interface PostHogEventMap {
105104
workspace_id: string
106105
}
107106

108-
/** Fired server-side when a workflow is exposed as an A2A agent. */
109107
a2a_agent_created: {
110108
agent_id: string
111109
workflow_id: string
@@ -241,7 +239,6 @@ export interface PostHogEventMap {
241239
workspace_id: string
242240
}
243241

244-
/** Fired server-side when a custom tool is created or updated. */
245242
custom_tool_saved: {
246243
tool_id: string
247244
workspace_id: string
@@ -253,7 +250,6 @@ export interface PostHogEventMap {
253250
workspace_id: string
254251
}
255252

256-
/** Fired server-side when a new BYOK (bring-your-own-key) provider key is added. */
257253
byok_key_added: {
258254
workspace_id: string
259255
provider_id: string

0 commit comments

Comments
 (0)