UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

106 lines (105 loc) 3.62 kB
import type { TelemetryEventName, TelemetryPropertyKey, TelemetryMeasurementKey, TelemetrySeverityLevel } from "./TelemetryConstants"; /** * Telemetry event with strict type checking * Only accepts predefined event names, property keys, and measurement keys */ export interface TelemetryEvent { name: TelemetryEventName; properties?: Partial<Record<TelemetryPropertyKey, any>>; measurements?: Partial<Record<TelemetryMeasurementKey, number>>; } export interface TelemetryException { exception: Error; properties?: Partial<Record<TelemetryPropertyKey, any>>; severityLevel?: TelemetrySeverityLevel; } export interface TelemetryPageView { name: string; uri?: string; properties?: Partial<Record<TelemetryPropertyKey, any>>; measurements?: Partial<Record<TelemetryMeasurementKey, number>>; } declare class TelemetryService { private _isInitialized; private _oneDSInstance; private _activeProjectCount; private _mctoolsVersion; private window; /** * Whether telemetry is allowed by the compile-time ENABLE_ANALYTICS flag. * This is the primary gate — if false, no telemetry methods will do anything. */ private _analyticsAllowed; constructor(); /** * Load the version from constants */ private _loadVersion; /** * Set the active project count */ setActiveProjectCount(count: number): void; /** * Get common properties and measurements to include with every event */ private _getCommonPropertiesAndMeasurements; /** * Check if 1DS is initialized and available on the window object */ private _checkInitialization; /** * Get the 1DS instance, checking initialization if not already done. * Returns null immediately if ENABLE_ANALYTICS is false at compile time. */ private _getInstance; /** * Check if telemetry is enabled and available */ isEnabled(): boolean; /** * Track a custom event * Only accepts predefined event names, property keys, and measurement keys from TelemetryConstants * @param event Event with strictly typed properties and measurements */ trackEvent(event: TelemetryEvent): void; /** * Track a page view * @param pageView Page view name and optional properties */ trackPageView(pageView: TelemetryPageView): void; /** * Track an exception * @param exception Exception details */ trackException(exception: TelemetryException): void; /** * Track a metric/measurement * @param name Metric name from TelemetryMeasurements * @param value Metric value * @param properties Optional properties */ trackMetric(name: TelemetryMeasurementKey, value: number, properties?: Partial<Record<TelemetryPropertyKey, any>>): void; /** * Track a trace/log message * @param message Log message * @param severityLevel Severity level * @param properties Optional properties */ trackTrace(message: string, severityLevel?: TelemetrySeverityLevel, properties?: Partial<Record<TelemetryPropertyKey, any>>): void; /** * Flush any pending telemetry data */ flush(): void; /** * Set authenticated user context * @param authenticatedUserId User ID * @param accountId Optional account ID */ setAuthenticatedUserContext(authenticatedUserId: string, accountId?: string): void; /** * Clear authenticated user context */ clearAuthenticatedUserContext(): void; } declare const _default: TelemetryService; export default _default;