UNPKG

npaw-plugin-nwf

Version:
184 lines (183 loc) 10.1 kB
import Session from '../sessions/Session'; export default class AppAnalytics { private session; private appAnalyticsStarted; private appAnalyticsStopped; constructor(session: Session); destroy(): void; setOptions(options: any): void; getOptions(): any; newSession(options?: object, dimensions?: object): void; begin(dimensions?: object): void; endSession(params?: object): void; /** * @deprecated The new method is begin(dimensions) */ fireSessionStart(dimensions?: object): void; /** * @deprecated The new method is endSession(params) */ fireSessionStop(params?: object): void; fireEvent(eventName?: string, dimensions?: object, values?: object, topLevelDimensions?: object, hasEndDatetime?: boolean): void; fireEventEnd(eventName?: string): void; fireError(code: string, msg: string, errorType?: string, metadata?: any, duration?: number, dimensions?: object, values?: object): void; /** * Tracks an application error or crash and forwards it to the App Analytics session. * The helper wraps {@link fireError} and builds the expected dimensions payload internally. * * @param errorCode - Unique identifier that categorises the error. * @param errorMessage - Human readable description for the error. * @param errorType - Optional error classification (for example `crash`, `exception`). * @param errorSource - Optional component or module where the error originated. * @param metadata - Optional JSON string with additional diagnostic information. * @param page - Optional page or section where the issue was detected. * @param fatal - Optional flag indicating whether the error is fatal. * @param duration - Optional duration in milliseconds associated with the error context. * @example * npawPlugin.appAnalytics.trackAppError( * 'AUTH_001', * 'Login request timed out', * 'exception', * 'AuthService', * JSON.stringify({ attempt: 2 }), * 'login', * false, * 1500 * ); */ trackAppError(errorCode: string, errorMessage: string, errorType?: string, errorSource?: string, metadata?: string, page?: string, fatal?: boolean, duration?: number): void; /** * Tracks a log entry for debugging or monitoring purposes. * The helper uses {@link fireEvent} with the predefined `logEvent` name. * * @param logLevel - Severity level (for example `debug`, `info`, `warning`). * @param logCategory - Logical grouping or module that produced the log. * @param errorSource - Optional component that originated the log. * @param page - Optional page or section where the log was generated. * @param metadata - Optional JSON string with additional details. * @example * npawPlugin.appAnalytics.trackLogEvent('info', 'player', 'PlaybackEngine', 'player', JSON.stringify({ state: 'buffering' })); */ trackLogEvent(logLevel: string, logCategory: string, errorSource?: string, page?: string, metadata?: string): void; /** * Tracks an Application Not Responding (ANR) incident via `anrEvent`. * * @param anrType - Identifies the ANR type (for example `main_thread`, `background`). * @param page - Optional page or section where the ANR occurred. * @param duration - Optional ANR duration in milliseconds. * @example * npawPlugin.appAnalytics.trackANREvent('main_thread', 'player', 2100); */ trackANREvent(anrType: string, page?: string, duration?: number): void; /** * Tracks the outcome of a login attempt with the `appLoginResult` event name. * * @param authType - Authentication method (for example `email`, `social`). * @param authStatus - Result of the attempt (`success`, `failed`, `cancelled`). * @param retryCounter - Optional number of retries executed before this attempt. * @param page - Optional page or screen where the login was performed. * @param profileId - Optional profile identifier associated with the user. * @param username - Optional username used during the login attempt. * @example * npawPlugin.appAnalytics.trackLoginResult('email', 'success', 1, 'login', 'profile-42', 'user@example.com'); */ trackLoginResult(authType: string, authStatus: string, retryCounter?: number, page?: string, profileId?: string, username?: string): void; /** * Tracks the outcome of a user registration attempt with the `appSignupResult` event name. * * @param authType - Registration mechanism (for example `email`, `social`). * @param authStatus - Result of the signup (`success`, `failed`, `cancelled`). * @param retryCounter - Optional number of retries executed before this attempt. * @param page - Optional page or screen where the signup was performed. * @param profileId - Optional profile identifier assigned after signup. * @param username - Optional username collected during signup. * @example * npawPlugin.appAnalytics.trackSignupResult('email', 'failed', 3, 'signup', undefined, 'user@example.com'); */ trackSignupResult(authType: string, authStatus: string, retryCounter?: number, page?: string, profileId?: string, username?: string): void; /** * Reports application health and resource information through the `appStatusMonitoring` event. * * @param batteryLevel - Optional textual battery level (`low`, `medium`, `high`). * @param availableMemory - Optional textual descriptor of free memory (`low`, `normal`). * @param networkType - Optional network type (`wifi`, `cellular`). * @param appForegroundBackground - Optional state describing whether the app is in foreground/background. * @param diskSpace - Optional textual descriptor of disk availability. * @param batteryPercentage - Optional numeric battery percentage. * @param memoryMB - Optional numeric available memory (in MB). * @param diskMB - Optional numeric available disk space (in MB). * @example * npawPlugin.appAnalytics.trackAppStatus('medium', 'normal', 'wifi', 'foreground', 'normal', 78, 2048, 10240); */ trackAppStatus(batteryLevel?: string, availableMemory?: string, networkType?: string, appForegroundBackground?: string, diskSpace?: string, batteryPercentage?: number, memoryMB?: number, diskMB?: number): void; /** * Tracks API request performance metrics through the `apiResponsePerformance` event. * * @param apiProvider - Name of the service or provider handling the request. * @param apiEndpoint - Endpoint path that was called. * @param method - HTTP method used (for example `GET`, `POST`). * @param apiResponseCode - Business response code returned by the API. * @param httpStatus - HTTP status code. * @param page - Optional page or section that triggered the request. * @param responseTime - Optional response time in milliseconds. * @example * npawPlugin.appAnalytics.trackAPIResponse('AuthService', '/v1/login', 'POST', 'OK', 200, 'login', 120); */ trackAPIResponse(apiProvider: string, apiEndpoint: string, method: string, apiResponseCode: string, httpStatus: number, page?: string, responseTime?: number): void; /** * Tracks Electronic Program Guide (EPG) refresh metrics with the `epgPerformance` event. * * @param epgProvider - Name of the EPG data provider. * @param refreshStatus - Status of the refresh (`success`, `failed`, `partial`). * @param page - Optional page or screen where the EPG was accessed. * @param refreshDuration - Optional duration of the refresh in milliseconds. * @param channelsLoaded - Optional number of channels loaded. * @example * npawPlugin.appAnalytics.trackEPGPerformance('GridService', 'success', 'guide', 350, 120); */ trackEPGPerformance(epgProvider: string, refreshStatus: string, page?: string, refreshDuration?: number, channelsLoaded?: number): void; /** * Tracks remote control interactions with the `remoteControlEvent` event name. * * @param rcuButton - Button pressed on the remote control (`up`, `down`, `select`, etc.). * @param actionTaken - Action triggered as a consequence of the button press. * @param eventSuccess - Indicates whether the action succeeded (`true` / `false` string). * @param page - Optional page or section where the interaction occurred. * @example * npawPlugin.appAnalytics.trackRemoteControlEvent('select', 'openDetails', 'true', 'player'); */ trackRemoteControlEvent(rcuButton: string, actionTaken: string, eventSuccess: string, page?: string): void; fireCrashError(code: string, msg: string, metadata?: string, duration?: number, dimensions?: object, values?: object): void; fireNavigation(dimensions?: object): void; /** * @deprecated The new method is fireNavigation(dimensions) */ fireNav(dimensions?: object): void; isActive(): boolean; isStarted(): boolean; getSessionRoot(): string | null; getSessionHost(): string | null; private _logBeginEvent; private _logFireNewSessionListener; private onRequestQueued; private onRequestWillSend; private onRequestSent; private ensureSessionStarted; private buildDimensionMap; private buildMetricsMap; private processSessionEvent; /** * Register a callback to be executed when the session successfully starts. * The callback fires after the /infinity/session/start request receives a 200 OK response. * * @param callback - Function to execute when session starts */ onSessionStart(callback: () => void): void; /** * Register a callback to be executed when the session successfully stops. * The callback fires after the /infinity/session/stop request receives a 200 OK response. * * @param callback - Function to execute when session stops */ onSessionStop(callback: () => void): void; }