UNPKG

@microsoft/applicationinsights-react-native

Version:
126 lines (117 loc) 5.4 kB
/* * Microsoft Application Insights react native plugin, 4.3.8 * Copyright (c) Microsoft and contributors. All rights reserved. * * Microsoft Application Insights Team * https://github.com/microsoft/applicationinsights-react-native#readme */ declare namespace ApplicationInsights { import { BaseTelemetryPlugin } from '@microsoft/applicationinsights-core-js'; import { IAppInsightsCore } from '@microsoft/applicationinsights-core-js'; import { IPlugin } from '@microsoft/applicationinsights-core-js'; import { IProcessTelemetryContext } from '@microsoft/applicationinsights-core-js'; import { ITelemetryItem } from '@microsoft/applicationinsights-core-js'; import { ITelemetryPlugin } from '@microsoft/applicationinsights-core-js'; /** * Returns the "react-native-device-info" as the Device Info Module * @returns */ function getReactNativeDeviceInfo(): IDeviceInfoModule; /** * Interface to abstract how the plugin can access the Device Info, this is a stripped * down version of the "react-native-device-info" interface and is mostly supplied for * testing. */ interface IDeviceInfoModule { /** * Returns the Device Model */ getModel: () => string; /** * Returns the device type */ getDeviceType: () => string; /** * Returns the unique Id for the device, to support both the current version and previous * versions react-native-device-info, this may return either a `string` or `Promise<string>`, * when a promise is returned the plugin will "wait" for the promise to `resolve` or `reject` * before processing any events. This WILL cause telemetry to be BLOCKED until either of these * states, so when returning a Promise it MUST `resolve` or `reject` it can't just never resolve. * There is a default timeout configured via `uniqueIdPromiseTimeout` to automatically unblock * event processing when this issue occurs. */ getUniqueId: () => Promise<string> | string; } interface INativeDevice { /** * Device type, e.g. Handset, Tablet, Tv */ deviceClass?: string; /** * Unique installation ID */ id?: string; /** * The device model: iPhone XS Max, Galaxy S10, etc */ model?: string; } interface IReactNativePluginConfig { /** * Disable automatic device collection */ disableDeviceCollection?: boolean; /** * Disable automatic exception collection */ disableExceptionCollection?: boolean; /** * Timeout value to unblock the processing of events if the DeviceInfoModule * returns a Promise. */ uniqueIdPromiseTimeout?: number; } class ReactNativeManualDevicePlugin extends BaseTelemetryPlugin { identifier: string; priority: number; _nextPlugin?: ITelemetryPlugin; private _setExceptionHandler; private _collectDeviceInfo; constructor(config?: IReactNativePluginConfig); protected getDeviceInfoModule(_deviceInfoModule: any): IDeviceInfoModule; initialize(config?: IReactNativePluginConfig | object, // need `| object` to coerce to interface core?: IAppInsightsCore, extensions?: IPlugin[]): void; processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void; /** * Set the module that will be used during initialization when collecting device is enabled * (the default), automatic collection can be disabled via the `disableDeviceCollection` * config. If no `deviceInfoModule` is set and collection is enabled, an error will be thrown. * @param deviceInfoModule */ setDeviceInfoModule(deviceInfoModule: IDeviceInfoModule): void; /** * Manually set the deviceId, if set before initialization and automatic device info collection * is enabled this value may get overwritten. If you want to keep this value disable auto * collection by setting the `disableDeviceCollection` config to true. * @param newId - The value to use as the device Id. */ setDeviceId(newId: string): void; /** * Manually set the device model, if set before initialization and automatic device info * collection is enabled this value may get overwritten. If you want to keep this value * disable auto collection by setting the `disableDeviceCollection` config to true. * @param newModel - The value to use as the device model. */ setDeviceModel(newModel: string): void; /** * Manually set the device type (class), if set before initialization and automatic device * info collection is enabled this value may get overwritten. If you want to keep this value * disable auto collection by setting the `disableDeviceCollection` config to true. * @param newType - The value to use as the device type */ setDeviceType(newType: string): void; } class ReactNativePlugin extends ReactNativeManualDevicePlugin { protected getDeviceInfoModule(_deviceInfoModule: any): IDeviceInfoModule; } }