Files
tolaria/src/components/settingsPreferenceTracking.ts

65 lines
2.6 KiB
TypeScript
Raw Normal View History

2026-05-11 13:46:18 +02:00
import type { Settings, NoteWidthMode } from '../types'
import { trackEvent } from '../lib/telemetry'
import {
2026-05-12 22:30:24 +02:00
trackAiFeaturesEnabledChanged,
2026-05-11 13:46:18 +02:00
trackDateDisplayFormatChanged,
trackDefaultNoteWidthChanged,
2026-05-16 12:13:20 +02:00
trackGitFeaturesEnabledChanged,
2026-05-11 13:46:18 +02:00
trackSidebarTypePluralizationChanged,
} from '../lib/productAnalytics'
2026-05-12 22:30:24 +02:00
import { areAiFeaturesEnabled } from '../lib/aiFeatures'
2026-05-16 12:13:20 +02:00
import { areGitFeaturesEnabled } from '../lib/gitSettings'
2026-05-11 13:46:18 +02:00
import {
DEFAULT_DATE_DISPLAY_FORMAT,
normalizeDateDisplayFormat,
type DateDisplayFormat,
} from '../utils/dateDisplay'
import { DEFAULT_NOTE_WIDTH_MODE, normalizeNoteWidthMode } from '../utils/noteWidth'
export interface SettingsPreferenceDraft {
analytics: boolean
2026-05-12 22:30:24 +02:00
aiFeaturesEnabled: boolean
2026-05-11 13:46:18 +02:00
dateDisplayFormat: DateDisplayFormat
defaultNoteWidth: NoteWidthMode
2026-05-16 12:13:20 +02:00
gitFeaturesEnabled: boolean
2026-05-11 16:37:06 +02:00
multiWorkspaceEnabled: boolean
2026-05-11 13:46:18 +02:00
sidebarTypePluralizationEnabled: boolean
}
export function trackTelemetryConsentChange(previousAnalytics: boolean, nextAnalytics: boolean): void {
if (!previousAnalytics && nextAnalytics) trackEvent('telemetry_opted_in')
if (previousAnalytics && !nextAnalytics) trackEvent('telemetry_opted_out')
}
export function trackSettingsPreferenceChanges(settings: Settings, draft: SettingsPreferenceDraft): void {
2026-05-12 22:30:24 +02:00
const previousAiFeaturesEnabled = areAiFeaturesEnabled(settings)
if (previousAiFeaturesEnabled !== draft.aiFeaturesEnabled) {
trackAiFeaturesEnabledChanged(draft.aiFeaturesEnabled)
}
2026-05-16 12:13:20 +02:00
const previousGitFeaturesEnabled = areGitFeaturesEnabled(settings)
if (previousGitFeaturesEnabled !== draft.gitFeaturesEnabled) {
trackGitFeaturesEnabledChanged(draft.gitFeaturesEnabled)
}
2026-05-11 13:46:18 +02:00
const previousDateDisplayFormat = normalizeDateDisplayFormat(settings.date_display_format) ?? DEFAULT_DATE_DISPLAY_FORMAT
if (previousDateDisplayFormat !== draft.dateDisplayFormat) {
trackDateDisplayFormatChanged(draft.dateDisplayFormat)
}
const previousNoteWidth = normalizeNoteWidthMode(settings.note_width_mode) ?? DEFAULT_NOTE_WIDTH_MODE
if (previousNoteWidth !== draft.defaultNoteWidth) {
trackDefaultNoteWidthChanged(draft.defaultNoteWidth)
}
const previousPluralization = settings.sidebar_type_pluralization_enabled ?? true
if (previousPluralization !== draft.sidebarTypePluralizationEnabled) {
trackSidebarTypePluralizationChanged(draft.sidebarTypePluralizationEnabled)
}
2026-05-11 16:37:06 +02:00
const previousMultiWorkspaceEnabled = settings.multi_workspace_enabled === true
if (previousMultiWorkspaceEnabled !== draft.multiWorkspaceEnabled) {
trackEvent('multi_workspace_mode_changed', { enabled: draft.multiWorkspaceEnabled ? 1 : 0 })
}
2026-05-11 13:46:18 +02:00
}