interface InstanceProperties { loader: string game_version: string } interface ProjectProperties extends InstanceProperties { id: string project_type: string } type AnalyticsEventMap = { Launched: { version: string; dev: boolean; onboarded: boolean } PageView: { path: string; fromPath: string; failed: unknown } InstanceCreate: { source: string } InstanceCreateStart: { source: string } InstanceStart: InstanceProperties & { source: string } InstanceStop: Partial & { source?: string } InstanceDuplicate: InstanceProperties InstanceRepair: InstanceProperties InstanceSetIcon: Record InstanceRemoveIcon: Record InstanceUpdateAll: InstanceProperties & { count: number; selected: boolean } InstanceProjectUpdate: InstanceProperties & { id: string; name: string; project_type: string } InstanceProjectDisable: InstanceProperties & { id: string name: string project_type: string disabled: boolean } InstanceProjectRemove: InstanceProperties & { id: string; name: string; project_type: string } ProjectInstall: ProjectProperties & { version_id: string; title: string; source: string } ProjectInstallStart: { source: string } PackInstall: { id: string; version_id: string; title: string; source: string } PackInstallStart: Record AccountLogIn: { source?: string } AccountLogOut: Record JavaTest: { path: string; success: boolean } JavaManualSelect: { version: string } JavaAutoDetect: { path: string; version: string } GalleryImageNext: { project_id: string; url: string } GalleryImagePrevious: { project_id: string; url: unknown } GalleryImageExpand: { project_id: string; url: string } } export type AnalyticsEvent = keyof AnalyticsEventMap let optedIn = false let debugEnabled = false export const initAnalytics = () => { optedIn = true } export const debugAnalytics = () => { debugEnabled = true } export const optOutAnalytics = () => { optedIn = false } export const optInAnalytics = () => { optedIn = true } type OptionalArgs = Record extends T ? [properties?: T] : [properties: T] export const trackEvent = ( eventName: E, ...args: OptionalArgs ) => { if (optedIn && debugEnabled) { console.debug('[Starlight telemetry disabled]', eventName, args[0]) } }