Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"monaco-editor": "^0.55.1",
"ox": "^0.11.3",
"posthog-js": "^1.333.0",
"posthog-node": "^5.24.15",
"prool": "^0.2.2",
"react": "^19.2.3",
"react-dom": "^19.2.3",
Expand Down
19 changes: 19 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/components/PostHogSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ function PostHogInitializer() {
defaults: '2025-11-30',
capture_exceptions: true,
debug: import.meta.env.MODE === 'development',
session_recording: {
maskAllInputs: false,
maskInputOptions: {
password: true,
},
},
})

posthog.register({ site: 'docs' })
Expand Down
70 changes: 70 additions & 0 deletions src/lib/feedback-adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { PostHog } from 'posthog-node'
import { Feedback } from 'vocs/config'
import { POSTHOG_EVENTS, POSTHOG_PROPERTIES } from './posthog'

type FeedbackData = {
helpful: boolean
category?: string | undefined
message?: string | undefined
pageUrl: string
timestamp: string
}

export function createFeedbackAdapter() {
const slackAdapter = Feedback.slack()

const posthogKey = process.env.VITE_POSTHOG_KEY
const posthogHost = process.env.VITE_POSTHOG_HOST || 'https://us.i.posthog.com'

const posthog = posthogKey ? new PostHog(posthogKey, { host: posthogHost }) : null

return Feedback.from({
type: 'slack+posthog',
async submit(data: FeedbackData) {
const slackPromise = slackAdapter.submit(data)

const posthogPromise = (async () => {
if (!posthog) return

let pagePath: string | undefined
try {
pagePath = new URL(data.pageUrl).pathname
} catch {
pagePath = undefined
}

const distinctId = `docs_feedback_${Date.now()}_${Math.random().toString(36).slice(2)}`
const ts = data.timestamp ? new Date(data.timestamp) : undefined

const commonProperties = {
[POSTHOG_PROPERTIES.FEEDBACK_HELPFUL]: data.helpful,
[POSTHOG_PROPERTIES.FEEDBACK_CATEGORY]: data.category,
[POSTHOG_PROPERTIES.FEEDBACK_MESSAGE]: data.message,
[POSTHOG_PROPERTIES.FEEDBACK_PAGE_URL]: data.pageUrl,
[POSTHOG_PROPERTIES.PAGE_PATH]: pagePath,
[POSTHOG_PROPERTIES.SITE]: 'docs',
}

posthog.capture({
distinctId,
event: POSTHOG_EVENTS.FEEDBACK_SUBMITTED,
properties: commonProperties,
timestamp: ts,
})

posthog.capture({
distinctId,
event: data.helpful
? POSTHOG_EVENTS.FEEDBACK_HELPFUL
: POSTHOG_EVENTS.FEEDBACK_NOT_HELPFUL,
properties: commonProperties,
timestamp: ts,
})

await posthog.flush()
})().catch(() => {})

await Promise.allSettled([slackPromise, posthogPromise])
},
})
}
11 changes: 11 additions & 0 deletions src/lib/posthog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export const POSTHOG_EVENTS = {
// Code interactions
CODE_EXAMPLE_VIEW: 'docs_code_example_view',
CODE_EXAMPLE_COPY: 'docs_code_example_copy',

// Feedback
FEEDBACK_SUBMITTED: 'docs_feedback_submitted',
FEEDBACK_HELPFUL: 'docs_feedback_helpful',
FEEDBACK_NOT_HELPFUL: 'docs_feedback_not_helpful',
} as const

/**
Expand Down Expand Up @@ -68,6 +73,12 @@ export const POSTHOG_PROPERTIES = {
SEARCH_QUERY: 'search_query',
SEARCH_RESULT_TITLE: 'search_result_title',
SEARCH_RESULT_URL: 'search_result_url',

// Feedback properties
FEEDBACK_HELPFUL: 'feedback_helpful',
FEEDBACK_CATEGORY: 'feedback_category',
FEEDBACK_MESSAGE: 'feedback_message',
FEEDBACK_PAGE_URL: 'feedback_page_url',
} as const

/**
Expand Down
5 changes: 3 additions & 2 deletions vocs.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Changelog, defineConfig, Feedback, McpSource } from 'vocs/config'
import { Changelog, defineConfig, McpSource } from 'vocs/config'
import { createFeedbackAdapter } from './src/lib/feedback-adapter'

const baseUrl = (() => {
if (URL.canParse(process.env.VITE_BASE_URL)) return process.env.VITE_BASE_URL
Expand All @@ -19,7 +20,7 @@ export default defineConfig({
title: 'Tempo',
titleTemplate: '%s ⋅ Tempo',
description: 'Documentation for the Tempo network and protocol specifications',
feedback: Feedback.slack(),
feedback: createFeedbackAdapter(),
mcp: {
enabled: true,
sources: [
Expand Down