feat: implement PostHog event tracking plan

Add trackEvent() calls for all user actions in the tracking plan:
- Vault: vault_opened (with has_git, note_count), vault_switched
- Notes: note_created (with has_type, creation_path), note_deleted,
  note_trashed, note_archived, note_favorited, note_unfavorited
- Git: commit_made, sync_triggered
- Search: search_used
- Editor: raw_mode_toggled, wikilink_inserted
- Types & Views: type_created, view_created
- Telemetry: telemetry_opted_in, telemetry_opted_out

All events gated by PostHog initialization (only fires when opted in).
No PII in any event properties — counts, booleans, and enums only.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Test
2026-04-03 20:42:43 +02:00
parent 9b93a17cec
commit 3172425a16
13 changed files with 66 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
import { useRef, useState, useCallback, useEffect, useMemo } from 'react'
import { trackEvent } from '../lib/telemetry'
import type { EditorView } from '@codemirror/view'
import { preFilterWikilinks, deduplicateByPath, MIN_QUERY_LENGTH } from '../utils/wikilinkSuggestions'
import { attachClickHandlers, enrichSuggestionItems } from '../utils/suggestionEnrichment'
@@ -136,6 +137,7 @@ export function RawEditorView({ content, path, entries, onContentChange, onSave,
changes: { from: 0, to: doc.length, insert: newText },
selection: { anchor: newCursor },
})
trackEvent('wikilink_inserted')
setAutocomplete(null)
if (debounceRef.current) clearTimeout(debounceRef.current)

View File

@@ -2,6 +2,7 @@ import { useState, useRef, useCallback, useEffect } from 'react'
import { X, Eye, EyeSlash, GithubLogo, SignOut } from '@phosphor-icons/react'
import { GitHubDeviceFlow } from './GitHubDeviceFlow'
import type { Settings } from '../types'
import { trackEvent } from '../lib/telemetry'
interface SettingsPanelProps {
open: boolean
@@ -152,6 +153,10 @@ function SettingsPanelInner({ settings, onSave, onClose }: Omit<SettingsPanelPro
}), [openaiKey, googleKey, githubToken, githubUsername, pullInterval, updateChannel, crashReporting, analytics, settings.telemetry_consent, settings.anonymous_id])
const handleSave = () => {
const prevAnalytics = settings.analytics_enabled ?? false
const newAnalytics = analytics
if (!prevAnalytics && newAnalytics) trackEvent('telemetry_opted_in')
if (prevAnalytics && !newAnalytics) trackEvent('telemetry_opted_out')
onSave(buildSettings())
onClose()
}

View File

@@ -1,4 +1,5 @@
import { useEffect, useCallback, useMemo, useRef } from 'react'
import { trackEvent } from '../lib/telemetry'
import { useCreateBlockNote, SuggestionMenuController } from '@blocknote/react'
import { BlockNoteView } from '@blocknote/mantine'
import { useEditorTheme } from '../hooks/useTheme'
@@ -87,6 +88,7 @@ export function SingleEditorView({ editor, entries, onNavigateWikilink, onChange
{ type: 'wikilink' as const, props: { target } },
" ",
])
trackEvent('wikilink_inserted')
}, [editor])
const getWikilinkItems = useCallback(async (query: string): Promise<WikilinkSuggestionItem[]> => {