@dynatrace/react-native-plugin
Version:
This plugin gives you the ability to use the Dynatrace Mobile agent in your react native application.
1,215 lines (1,196 loc) • 95.2 kB
TypeScript
/// <reference types="react" />
/**
* Platform enum for targeting specific mobile platforms.
* Use this when you want platform-specific behavior, ensuring commands are only sent to Android or iOS.
*/
declare enum Platform {
/**
* Restricts the command to the Android platform only.
*
* @example
* ```ts
* import { Dynatrace, Platform } from '@dynatrace/react-native-plugin';
*
* // This action will only be tracked on Android devices
* const myAction = Dynatrace.enterAutoAction('MyButton tapped', Platform.Android);
* // Perform the action and whatever else is needed
* myAction.leaveAction();
* ```
*/
Android,
/**
* Restricts the command to the iOS platform only.
*
* @example
* ```ts
* import { Dynatrace, Platform } from '@dynatrace/react-native-plugin';
*
* // This action will only be tracked on iOS devices
* const myAction = Dynatrace.enterAutoAction('MyButton tapped', Platform.Ios);
* // Perform the action and whatever else is needed
* myAction.leaveAction();
* ```
*/
Ios
}
/**
* Enum representing different data collection and privacy levels. Each level determines
* the amount of monitoring data collected and sent by the Dynatrace agent.
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#user-privacy-options
* @see https://docs.dynatrace.com/docs/platform-modules/digital-experience/mobile-applications/additional-configuration/configure-rum-privacy-mobile#data-collection-levels
*/
declare enum DataCollectionLevel {
/**
* No monitoring data is sent to Dynatrace.
*
* **Characteristics:**
* - No personal data is sent
* - All identifiers are randomized on every app launch
* - A single "Loading <App>" event is sent to track the number of users who opted out
*
* Use this level when users have not consented to any data collection.
*
* @example
* ```ts
* import { DataCollectionLevel, Dynatrace, UserPrivacyOptions } from '@dynatrace/react-native-plugin';
*
* const privacyConfig = new UserPrivacyOptions(DataCollectionLevel.Off, false);
* Dynatrace.applyUserPrivacyOptions(privacyConfig);
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#user-privacy-options
* @see https://docs.dynatrace.com/docs/platform-modules/digital-experience/mobile-applications/additional-configuration/configure-rum-privacy-mobile#data-collection-levels
*/
Off,
/**
* Only performance and automatically captured data is sent to Dynatrace.
*
* **Characteristics:**
* - No personal data is sent
* - All identifiers are randomized on every app launch
* - Performance metrics and crash data are collected
* - User-specific data and custom events are not tracked
*
* Use this level when users consent to performance monitoring but not personal data collection.
*
* @example
* ```ts
* import { DataCollectionLevel, Dynatrace, UserPrivacyOptions } from '@dynatrace/react-native-plugin';
*
* const privacyConfig = new UserPrivacyOptions(DataCollectionLevel.Performance, true);
* Dynatrace.applyUserPrivacyOptions(privacyConfig);
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#user-privacy-options
* @see https://docs.dynatrace.com/docs/platform-modules/digital-experience/mobile-applications/additional-configuration/configure-rum-privacy-mobile#data-collection-levels
*/
Performance,
/**
* @deprecated Replaced by `DataCollectionLevel.UserBehavior`
*/
User,
/**
* Both performance data and user behavior data are sent to Dynatrace.
*
* **Characteristics:**
* - Personal data may be sent (depending on configuration)
* - OneAgent recognizes and tracks returning users across sessions
* - User tagging, custom events, and custom values are enabled
* - Full monitoring capabilities are available
*
* **Note:** If you haven't configured user tagging or custom event/value reporting,
* this level functions similarly to the Performance level.
*
* Use this level when users have consented to full monitoring and analytics.
*
* @example
* ```ts
* import { DataCollectionLevel, Dynatrace, UserPrivacyOptions } from '@dynatrace/react-native-plugin';
*
* const privacyConfig = new UserPrivacyOptions(DataCollectionLevel.UserBehavior, true);
* Dynatrace.applyUserPrivacyOptions(privacyConfig);
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#user-privacy-options
* @see https://docs.dynatrace.com/docs/platform-modules/digital-experience/mobile-applications/additional-configuration/configure-rum-privacy-mobile#data-collection-levels
*/
UserBehavior
}
/**
* Represents user privacy settings for data collection and crash reporting.
* Use this class to configure privacy options and apply them via `Dynatrace.applyUserPrivacyOptions(userPrivacyOptions)`.
*/
declare class UserPrivacyOptions {
private _dataCollectionLevel;
private _crashReportingOptedIn;
/**
* Creates a new UserPrivacyOptions instance with the specified privacy settings.
*
* @param {DataCollectionLevel} dataCollectionLevel The level of data collection to allow
* @param {boolean} crashReportingOptedIn Whether crash reporting should be enabled
*
* @example
* ```ts
* import { DataCollectionLevel, Dynatrace, UserPrivacyOptions } from '@dynatrace/react-native-plugin';
*
* // Create privacy options with no data collection
* const privacyConfig = new UserPrivacyOptions(DataCollectionLevel.Off, false);
* Dynatrace.applyUserPrivacyOptions(privacyConfig);
*
* // Create privacy options with full monitoring
* const fullPrivacyConfig = new UserPrivacyOptions(DataCollectionLevel.UserBehavior, true);
* Dynatrace.applyUserPrivacyOptions(fullPrivacyConfig);
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#user-privacy-options
*/
constructor(dataCollectionLevel: DataCollectionLevel, crashReportingOptedIn: boolean);
/**
* Gets the current data collection level.
*
* @returns {DataCollectionLevel} The configured data collection level
*
* @example
* ```ts
* import { DataCollectionLevel, UserPrivacyOptions } from '@dynatrace/react-native-plugin';
*
* const privacyConfig = new UserPrivacyOptions(DataCollectionLevel.Performance, false);
* const level = privacyConfig.dataCollectionLevel;
* console.log(level); // DataCollectionLevel.Performance
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#user-privacy-options
*/
get dataCollectionLevel(): DataCollectionLevel;
/**
* Returns the opt-in value for crash reporting.
*
* @return {boolean} the opt-in value for crash reporting
*
* Usage:
*
* ```ts
* import { DataCollectionLevel, UserPrivacyOptions } from '@dynatrace/react-native-plugin';
*
* const privacyConfig = new UserPrivacyOptions(DataCollectionLevel.Off, false);
* const crashReporting = privacyConfig.crashReportingOptedIn;
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#user-privacy-options
*/
get crashReportingOptedIn(): boolean;
/**
* Sets the crash reporting opt-in preference.
*
* @param {boolean} crashReportingOptedIn Set to `true` to enable crash reporting, `false` to disable it
*
* @example
* ```ts
* import { DataCollectionLevel, Dynatrace, UserPrivacyOptions } from '@dynatrace/react-native-plugin';
*
* const privacyConfig = new UserPrivacyOptions(DataCollectionLevel.Performance, false);
* privacyConfig.crashReportingOptedIn = true; // Enable crash reporting
* Dynatrace.applyUserPrivacyOptions(privacyConfig);
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#user-privacy-options
*/
set crashReportingOptedIn(crashReportingOptedIn: boolean);
/**
* Sets the data collection level.
*
* @param {DataCollectionLevel} dataCollectionLevel The data collection level to apply
*
* @example
* ```ts
* import { DataCollectionLevel, Dynatrace, UserPrivacyOptions } from '@dynatrace/react-native-plugin';
*
* const privacyConfig = new UserPrivacyOptions(DataCollectionLevel.Off, false);
* privacyConfig.dataCollectionLevel = DataCollectionLevel.Performance; // Change to Performance level
* Dynatrace.applyUserPrivacyOptions(privacyConfig);
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#user-privacy-options
*/
set dataCollectionLevel(dataCollectionLevel: DataCollectionLevel);
}
/**
* Interface for Action
*/
interface IDynatraceAction {
/**
* Reports an error event with an error code. The key-value pair is marked as an error type.
*
* **Note:** The error will not be reported if the action is already closed or if the errorName
* is null or empty. String values are limited to 250 characters and will be truncated if they
* exceed this limit.
*
* @param {string} errorName Name of the error event (limited to 250 characters)
* @param {number} errorCode The error code to report
* @param {Platform} platform Optional platform filter. Defaults to both Android and iOS.
*
* @example
* ```ts
* import { Dynatrace, Platform } from '@dynatrace/react-native-plugin';
*
* const action = Dynatrace.enterAutoAction('User Login');
* action.reportError('Page Not Found', 404);
* action.leaveAction();
*
* // With platform-specific error
* const platformAction = Dynatrace.enterAutoAction('API Call');
* platformAction.reportError('Connection Failed', 500, Platform.Android);
* platformAction.leaveAction();
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#report-values
*/
reportError(errorName: string, errorCode: number, platform?: Platform): void;
/**
* Reports a timestamped event to track when a user passes through a specific part of your application.
* This method provides a simple way to monitor user behavior and application flow.
*
* **Note:** The event will not be reported if the action is already closed or if the eventName
* is null or empty. String values are limited to 250 characters and will be truncated if they
* exceed this limit.
*
* @param eventName Name of the event to report (limited to 250 characters)
* @param platform Optional platform filter. Defaults to both Android and iOS.
*
* @example
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* const action = Dynatrace.enterAutoAction('Checkout Process');
* action.reportEvent('Payment Method Selected');
* action.reportEvent('Order Confirmed');
* action.leaveAction();
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#report-values
*/
reportEvent(eventName: string, platform?: Platform): void;
/**
* Reports a timestamped string key-value pair for tracking important measurement data.
*
* **Note:** The event will not be reported if the action is already closed, or if either
* valueName or value is null or empty. String values are limited to 250 characters and will
* be truncated if they exceed this limit.
*
* @param valueName Name of the value being reported (limited to 250 characters)
* @param value String value to report (limited to 250 characters)
* @param platform Optional platform filter. Defaults to both Android and iOS.
*
* @example
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* const action = Dynatrace.enterAutoAction('User Profile Update');
* action.reportStringValue('User Tier', 'Premium');
* action.reportStringValue('Selected Theme', 'Dark Mode');
* action.leaveAction();
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#report-values
*/
reportStringValue(valueName: string, value: string, platform?: Platform): void;
/**
* Reports a timestamped integer key-value pair for tracking important measurement data.
*
* **Note:** The event will not be reported if the action is already closed or if
* valueName is null or empty. The valueName is limited to 250 characters and will be
* truncated if it exceeds this limit.
*
* @param valueName Name of the value being reported (limited to 250 characters)
* @param value Integer value to report
* @param platform Optional platform filter. Defaults to both Android and iOS.
*
* @example
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* const action = Dynatrace.enterAutoAction('Shopping Cart');
* action.reportIntValue('Items Count', 5);
* action.reportIntValue('Total Quantity', 12);
* action.leaveAction();
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#report-values
*/
reportIntValue(valueName: string, value: number, platform?: Platform): void;
/**
* Reports a timestamped double (floating-point) key-value pair for tracking important measurement data.
*
* **Note:** The event will not be reported if the action is already closed or if
* valueName is null or empty. The valueName is limited to 250 characters and will be
* truncated if it exceeds this limit.
*
* @param valueName Name of the value being reported (limited to 250 characters)
* @param value Double (floating-point) value to report
* @param platform Optional platform filter. Defaults to both Android and iOS.
*
* @example
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* const action = Dynatrace.enterAutoAction('Purchase Transaction');
* action.reportDoubleValue('Transaction Amount', 99.99);
* action.reportDoubleValue('Tax Amount', 8.50);
* action.leaveAction();
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#report-values
*/
reportDoubleValue(valueName: string, value: number, platform?: Platform): void;
/**
* Completes this action and prepares the collected data for transmission in the next sending interval.
*
* **Note:** When a parent action is exited, all nested child actions are automatically closed.
*
* @param platform Optional platform filter. Defaults to both Android and iOS.
*
* @example
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* const action = Dynatrace.enterAutoAction('User Login');
* action.reportEvent('Credentials Validated');
* action.reportIntValue('Login Attempts', 1);
* action.leaveAction();
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#report-values
*/
leaveAction(platform?: Platform): void;
/**
* Cancels this action and discards all collected data. Similar to `leaveAction()`, but the data
* and all unfinished child actions are discarded instead of being sent to Dynatrace.
*
* Use this when an action was started incorrectly or should not contribute to monitoring data
* (e.g., test actions, debug sessions, pre-production validation).
*
* @param platform Optional platform filter. Defaults to both Android and iOS.
*
* @example
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* const action = Dynatrace.enterAutoAction('Data Processing');
* action.reportEvent('Processing Started');
*
* // Cancel if running in development or test mode
* if (__DEV__) {
* action.cancel(); // Don't send test data to production monitoring
* } else {
* action.leaveAction(); // Send the action data
* }
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#cancel-actions
*/
cancel(platform?: Platform): void;
/**
* Generates a Dynatrace request tag for manual web request tagging. This tag must be added as an
* HTTP header to link the web request with this mobile action. The header key can be obtained
* using `getRequestTagHeader()`.
*
* The tag value is evaluated by the Dynatrace web server agent, which links server-side PurePath
* data with this mobile user action for end-to-end tracing.
*
* **Note:** The returned string may be empty if the Dynatrace agent is disabled or not started yet,
* if communication with the Dynatrace server fails, or if privacy settings do not allow monitoring of requests.
*
* @param {string} url The URL of the request you want to track
* @returns {Promise<string>} The request tag value to be used as the HTTP header value
*
* @example
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* const action = Dynatrace.enterAutoAction('API Request');
* const requestTag = await action.getRequestTag('https://api.example.com/data');
* const headerName = action.getRequestTagHeader();
*
* // Attach to your HTTP request
* fetch('https://api.example.com/data', {
* headers: {
* [headerName]: requestTag,
* 'Content-Type': 'application/json'
* }
* });
*
* action.leaveAction();
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#manual-web-request-tagging
*/
getRequestTag(url: string): Promise<string>;
/**
* Returns the HTTP header name required for manual web request tagging. Use this in combination
* with `getRequestTag()` to link web requests with mobile actions.
*
* @returns {string} The name of the HTTP header to use for request tagging
*
* @example
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* const action = Dynatrace.enterAutoAction('Data Fetch');
* const headerName = action.getRequestTagHeader();
* const headerValue = await action.getRequestTag('https://api.example.com/users');
*
* // Use in your HTTP client
* const response = await fetch('https://api.example.com/users', {
* headers: {
* [headerName]: headerValue
* }
* });
*
* action.leaveAction();
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#manual-web-request-tagging
*/
getRequestTagHeader(): string;
}
type Primitive = string | number | boolean;
type JSONArray = JSONValue[];
type JSONValue = Primitive | JSONArray | JSONObject;
/**
* JSON Object which can be used for sendEvent API
*/
interface JSONObject {
[key: string]: JSONValue;
}
/**
* Log level enum to control the verbosity of plugin logging.
*/
declare enum LogLevel {
/**
* Enables verbose diagnostic logging. Use this level when troubleshooting issues or during development.
*
* **Configuration options:**
* - Via `dynatrace.config.js`: Set `react.debug` to `true`
* - Via code (manual startup): Use the `ConfigurationBuilder`
*
* @example
* ```ts
* import { ConfigurationBuilder, Dynatrace, LogLevel } from '@dynatrace/react-native-plugin';
*
* const config = new ConfigurationBuilder('beaconUrl', 'applicationId')
* .withLogLevel(LogLevel.Debug);
* await Dynatrace.start(config.buildConfiguration());
* ```
*/
Debug = 0,
/**
* Enables standard informational logging. This is the default log level and provides essential information
* without excessive detail.
*
* **Note:** Since this is the default, explicit configuration is not required.
*
* **Configuration options:**
* - Via `dynatrace.config.js`: Set `react.debug` to `false`
* - Via code (manual startup): Use the `ConfigurationBuilder`
*
* @example
* ```ts
* import { ConfigurationBuilder, Dynatrace, LogLevel } from '@dynatrace/react-native-plugin';
*
* const config = new ConfigurationBuilder('beaconUrl', 'applicationId')
* .withLogLevel(LogLevel.Info);
* await Dynatrace.start(config.buildConfiguration());
* ```
*/
Info = 1
}
/**
* Configuration interface for Dynatrace agent startup.
* Use this interface when configuring the agent programmatically instead of using auto-startup.
*/
interface IConfiguration {
/**
* The beacon URL used to communicate with the Dynatrace beacon endpoint. This value is mandatory.
*
* **Note:** This value is only used for manual startup. For auto-startup, configure this through
* the native agent configuration.
*/
readonly beaconUrl: string;
/**
* The application ID used to identify and report data for this application. This value is mandatory.
*
* **Note:** This value is only used for manual startup. For auto-startup, configure this through
* the native agent configuration.
*/
readonly applicationId: string;
/**
* Enables crash reporting. Defaults to `true` if not specified.
*
* **Note:** This value is only used for manual startup. For auto-startup, configure this through
* the native agent configuration.
*/
readonly reportCrash: boolean;
/**
* Enables the React Native error/crash handler. Defaults to `true` if not specified.
*
* **Note:** This value is only used for manual startup. For auto-startup, configure this through
* the `react` configuration block in the `dynatrace.config.js` file.
*/
readonly errorHandler: boolean;
/**
* Determines whether fatal errors are reported as crashes or errors.
*
* - When `true` (default): Unhandled fatal errors are reported as crashes and end the current session
* - When `false`: Unhandled fatal errors are reported as errors and the current session continues
*
* **Note:** This value is only used for manual startup. For auto-startup, configure this through
* the `react` configuration block in the `dynatrace.config.js` file.
*/
readonly reportFatalErrorAsCrash: boolean;
/**
* The log level for the Dynatrace plugin during application runtime. Defaults to `LogLevel.Info` if not specified.
*/
readonly logLevel: LogLevel;
/**
* Enables tracking of component update cycles in lifecycle actions. Defaults to `false` if not specified.
*
* **Warning:** Enabling this option generates significantly more monitoring data.
*/
readonly lifecycleUpdate: boolean;
/**
* Activates privacy mode when set to `true`. User consent must be queried and configured separately.
* Privacy settings for data collection and crash reporting can be changed by calling
* `Dynatrace.applyUserPrivacyOptions(userPrivacyOptions)`. Defaults to `false` if not specified.
*
* **Note:** This value is only used for manual startup. For auto-startup, configure this through
* the native agent configuration.
*
* @see Data privacy documentation for more details on privacy settings
*/
readonly userOptIn: boolean;
/**
* Activates privacy mode for Touchables and Buttons. When set to `true`, specific control names
* are hidden and replaced with generic component types (e.g., "Touch on Login" becomes "Touch on Button").
*
* **Note:** This setting is ignored when a `dtActionName` prop is explicitly set on the component.
* Defaults to `false` if not specified.
*/
readonly actionNamePrivacy: boolean;
/**
* The bundle name used as a prefix for internal action IDs. Optional.
*/
readonly bundleName?: string;
/**
* The bundle version used for events. This is mandatory for proper crash reporting and source map symbolication.
*
* **Important:** Without a bundle version, source maps cannot be applied to crash reports.
*/
readonly bundleVersion?: string;
/**
* Returns a string representation of the configuration.
*
* @returns A formatted string containing the configuration details
*/
toString(): string;
}
/**
* Interface which declares event modification through modifyEvent
* Implement this interface and register it via Dynatrace.addEventModifier(IEventModifier) to modify events.
*/
interface IEventModifier {
/**
* Event as JSONObject is received and can be modified.
*
* Returning null discards the event and prevents future modifier functions from being executed.
*
* Certain reserved fields and namespaces cannot be modified in any way (added, removed, or overridden),
* while others are open for modification.
*
* Open for modification:
* - url.full
* - exception.stack_trace
*
* Open for modification or can be added:
* - event_properties.*
* - session_properties.*
*
* See the public documentation for a detailed list of reserved/open fields.
* @param event Event as JSONObject
* @returns Either the modified event or null if you want to cancel the event
*
* @example
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* Dynatrace.addEventModifier({ modifyEvent(event) {
* event['event_properties.modified'] = 'modified';
* return event;
* }});
* ```
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-custom-events#event-modifiers
*/
modifyEvent(event: JSONObject): JSONObject | null;
}
/**
* Represents the allowed types for event property values.
*/
type EventProperty = string | number | boolean;
/**
* Base interface for all events.
*/
interface IBaseEvent {
/**
* Converts the event into a JSON event object.
*
* @returns The built event as a JSONObject.
*
* @internal
*/
toJSON(): JSONObject | null;
}
interface IHttpRequestEventData extends IBaseEvent {
/**
* Sets the duration of the HTTP request in milliseconds.
*
* @param duration The request duration in milliseconds. Only positive numbers are valid.
* @returns The event instance for method chaining
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventData } from '@dynatrace/react-native-plugin';
*
* const requestEvent = new HttpRequestEventData('https://api.example.com/data', 'GET')
* .withDuration(250);
* Dynatrace.sendHttpRequestEvent(requestEvent);
* ```
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-web-request-performance#manual-http-request-reporting
*/
withDuration(duration: number): this;
/**
* Sets the HTTP response status code.
*
* @param statusCode The HTTP status code (e.g., 200, 404, 500). Only positive numbers are valid.
* @returns The event instance for method chaining
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventData } from '@dynatrace/react-native-plugin';
*
* const requestEvent = new HttpRequestEventData('https://api.example.com/data', 'GET')
* .withStatusCode(200);
* Dynatrace.sendHttpRequestEvent(requestEvent);
* ```
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-web-request-performance#manual-http-request-reporting
*/
withStatusCode(statusCode: number): this;
/**
* Sets the HTTP response reason phrase.
*
* @param reasonPhrase The reason phrase (e.g., "OK", "Not Found"). Maximum 5000 characters; longer values will be trimmed.
* @returns The event instance for method chaining
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventData } from '@dynatrace/react-native-plugin';
*
* const requestEvent = new HttpRequestEventData('https://api.example.com/data', 'GET')
* .withReasonPhrase('OK');
* Dynatrace.sendHttpRequestEvent(requestEvent);
* ```
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-web-request-performance#manual-http-request-reporting
*/
withReasonPhrase(reasonPhrase: string): this;
/**
* Associates an error with the HTTP request event.
*
* @param error A standard JavaScript Error object representing the request failure
* @returns The event instance for method chaining
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventData } from '@dynatrace/react-native-plugin';
*
* try {
* // Request code
* } catch (error) {
* let requestEvent = new HttpRequestEventData('https://api.example.com/data', 'GET');
*
* if (error instanceof Error) {
* requestEvent.withError(error);
* }
*
* Dynatrace.sendHttpRequestEvent(requestEvent);
* }
* ```
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-web-request-performance#manual-http-request-reporting
*/
withError(error: Error): this;
/**
* Sets the number of bytes sent in the request.
*
* @param bytesSent The number of bytes sent in the request payload. Only positive numbers are valid.
* @returns The event instance for method chaining
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventData } from '@dynatrace/react-native-plugin';
*
* const requestEvent = new HttpRequestEventData('https://api.example.com/data', 'POST')
* .withBytesSent(1024);
* Dynatrace.sendHttpRequestEvent(requestEvent);
* ```
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-web-request-performance#manual-http-request-reporting
*/
withBytesSent(bytesSent: number): this;
/**
* Sets the number of bytes received in the response.
*
* @param bytesReceived The number of bytes received in the response payload. Only positive numbers are valid.
* @returns The event instance for method chaining
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventData } from '@dynatrace/react-native-plugin';
*
* const requestEvent = new HttpRequestEventData('https://api.example.com/data', 'GET')
* .withBytesReceived(2048);
* Dynatrace.sendHttpRequestEvent(requestEvent);
* ```
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-web-request-performance#manual-http-request-reporting
*/
withBytesReceived(bytesReceived: number): this;
/**
* Adds a W3C traceparent header for distributed tracing.
*
* @param traceparentHeader A valid traceparent header according to the W3C Trace Context specification.
* Format: `00-<trace-id>-<parent-id>-<trace-flags>` where trace-id is 32 hex digits, parent-id is 16 hex digits.
* @returns The event instance for method chaining
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventData } from '@dynatrace/react-native-plugin';
*
* const requestEvent = new HttpRequestEventData('https://api.example.com/data', 'GET')
* .withTraceparentHeader('00-80e1afed08e019fc1110464cfa66635c-7a085853722dc6d2-01');
* Dynatrace.sendHttpRequestEvent(requestEvent);
* ```
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-web-request-performance#manual-http-request-reporting
*/
withTraceparentHeader(traceparentHeader: TraceparentHeader): this;
/**
* Adds a custom event property to the request event.
* @param key The property key. See property requirements below.
* @param value The property value. Cannot contain functions, undefined, Infinity, or NaN (they will be replaced with null).
*
* **Property Requirements:**
* - Only properties prefixed with `event_properties.*` are allowed
* - Maximum of 50 custom properties per event
* - If the limit is exceeded, properties are sorted alphabetically by key and excess properties are dropped deterministically
* - String properties are limited to 5000 characters (exceeding characters are truncated)
* - Field names must contain only alphabetic characters, numbers, underscores, and dots
* - Each dot must be followed by an alphabetic character
* - Each underscore must be followed by an alphabetic character or number
*
* @returns The event instance for method chaining
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventData } from '@dynatrace/react-native-plugin';
*
* const requestEvent = new HttpRequestEventData('https://api.example.com/data', 'GET')
* .addEventProperty('event_properties.user_id', '12345')
* .addEventProperty('event_properties.api_version', 'v2');
* Dynatrace.sendHttpRequestEvent(requestEvent);
* ```
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-web-request-performance#manual-http-request-reporting
*/
addEventProperty(key: `event_properties.${string}`, value: EventProperty): this;
}
type TraceparentHeader = `00-${string}-${string}-0${'0' | '1'}`;
type AllowedRequestMethods = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH' | 'get' | 'head' | 'post' | 'put' | 'delete' | 'connect' | 'options' | 'trace' | 'patch';
type Url = `http://${string}` | `https://${string}`;
type EventPropertyKey = `event_properties.${string}`;
declare class HttpRequestEventData implements IHttpRequestEventData {
private url;
private requestMethod;
private static readonly allowedRequestMethods;
private duration;
private statusCode?;
private reasonPhrase?;
private bytesReceived?;
private bytesSent?;
private error?;
private traceparentHeader?;
private rawEventProperties;
private hasDroppedProperties;
private triedToOverwriteDuration;
/**
* Creates a new HTTP request event.
*
* @param url The request URL. Must be a valid URL according to the WHATWG URL Standard, starting with
* `http://` or `https://`. Maximum 5000 characters; longer values will be trimmed.
* @param requestMethod The HTTP request method. Allowed values: GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS,
* TRACE, PATCH (case-insensitive).
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventData } from '@dynatrace/react-native-plugin';
*
* const requestEvent = new HttpRequestEventData('https://api.example.com/data', 'GET');
* Dynatrace.sendHttpRequestEvent(requestEvent);
* ```
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-web-request-performance#manual-http-request-reporting
*/
constructor(url: Url, requestMethod: AllowedRequestMethods);
withDuration(duration: number): this;
withStatusCode(statusCode: number): this;
withReasonPhrase(reasonPhrase: string): this;
withError(error: Error): this;
withBytesSent(bytesSent: number): this;
withBytesReceived(bytesReceived: number): this;
withTraceparentHeader(traceparentHeader: TraceparentHeader): this;
addEventProperty(key: EventPropertyKey, value: EventProperty): this;
toJSON(): JSONObject | null;
private hasValidMandatoryAttributes;
private isInvalidUrl;
private sanitizeStatusCode;
private sanitizeDuration;
private sanitizeBytesSent;
private sanitizeBytesReceived;
private isStatusCodeError;
private parseTraceparent;
private allZeros;
}
/**
* Interface for building events with event properties and duration.
*
* Events can include custom properties and duration information.
* Use implementations of this interface with `Dynatrace.sendEvent()`.
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-custom-events#send-custom-events
*/
interface IEventData extends IBaseEvent {
/**
* Sets the duration of the event in milliseconds.
*
* @param duration The event duration in milliseconds. Only positive numbers are valid.
* @returns The event instance for method chaining
*
* @example
* ```typescript
* import { Dynatrace, EventData } from '@dynatrace/react-native-plugin';
*
* const customEvent = new EventData()
* .addEventProperty('event_properties.operation', 'data_sync')
* .withDuration(250);
* Dynatrace.sendEvent(customEvent);
* ```
*/
withDuration(duration: number): this;
/**
* Adds a custom event property to the event.
*
* Event properties allow you to attach custom key-value pairs to events for better
* analysis and filtering in Dynatrace.
*
* @param key - The property key. Must be prefixed with `event_properties.*`
* @param value - The property value (string, number, or boolean). Invalid values will be replaced with null.
* @returns The event instance for method chaining
*
* @remarks
* **Property Requirements:**
* - Only properties prefixed with `event_properties.*` are allowed
* - Maximum of 50 custom properties per event
* - If the limit is exceeded, properties are sorted alphabetically by key and excess properties are dropped deterministically
* - String properties are limited to 5000 characters (exceeding characters are truncated)
* - Field names must contain only alphabetic characters, numbers, underscores, and dots
* - Each dot must be followed by an alphabetic character
* - Each underscore must be followed by an alphabetic character or number
*
* @example
* ```typescript
* import { Dynatrace, EventData } from '@dynatrace/react-native-plugin';
*
* const customEvent = new EventData()
* .addEventProperty('event_properties.user_id', '12345')
* .addEventProperty('event_properties.action_type', 'purchase')
* .addEventProperty('event_properties.amount', 99.99)
* .addEventProperty('event_properties.is_premium_user', true);
* Dynatrace.sendEvent(customEvent);
* ```
*/
addEventProperty(key: `event_properties.${string}`, value: EventProperty): this;
}
declare class EventData implements IEventData {
private rawEventProperties;
private duration?;
addEventProperty(key: `event_properties.${string}`, value: EventProperty): this;
withDuration(duration: number): this;
toJSON(): JSONObject | null;
}
/**
* Interface for building session property events.
*
* Session properties are key-value pairs that persist throughout the entire
* user session and are attached to all subsequent events in that session.
* Use implementations of this interface with `Dynatrace.sendSessionPropertyEvent()`.
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-custom-events#send-session-property-events
*/
interface ISessionPropertyEventData extends IBaseEvent {
/**
* Adds a custom session property to the event.
*
* Session properties allow you to attach custom key-value pairs that persist throughout
* the entire user session. These properties will be automatically attached to all
* subsequent events in the current session.
*
* @param key - The property key. Must be prefixed with `session_properties.*`
* @param value - The property value (string, number, or boolean). Invalid values will be replaced with null.
* @returns The event instance for method chaining
*
* @remarks
* **Property Requirements:**
* - Only properties prefixed with `session_properties.*` are allowed
* - Maximum of 50 custom properties per event
* - If the limit is exceeded, properties are sorted alphabetically by key and excess properties are dropped deterministically
* - String properties are limited to 5000 characters (exceeding characters are truncated)
* - Field names must contain only alphabetic characters, numbers, underscores, and dots
* - Each dot must be followed by an alphabetic character
* - Each underscore must be followed by an alphabetic character or number
*
* @example
* ```typescript
* import { Dynatrace, SessionPropertyEventData } from '@dynatrace/react-native-plugin';
*
* const sessionPropertyEvent = new SessionPropertyEventData()
* .addSessionProperty('session_properties.user_id', 'user_12345')
* .addSessionProperty('session_properties.user_type', 'premium')
* .addSessionProperty('session_properties.feature_flags_enabled', true)
* .addSessionProperty('session_properties.session_score', 95.5);
* Dynatrace.sendSessionPropertyEvent(sessionPropertyEvent);
* ```
*/
addSessionProperty(key: `session_properties.${string}`, value: EventProperty): this;
}
declare class SessionPropertyEventData implements ISessionPropertyEventData {
private rawSessionProperties;
addSessionProperty(key: `session_properties.${string}`, value: EventProperty): this;
toJSON(): JSONObject | null;
}
/**
* Interface for building exception events with event properties.
*
* This interface defines the contract for creating exception events that can be sent
* to Dynatrace. Exception events can include custom properties.
* Use implementations of this interface with `Dynatrace.sendExceptionEvent()`.
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-error-crash-reporting#send-exception-event
*/
interface IExceptionEventData extends IBaseEvent {
/**
* Adds a custom event property to the exception event.
*
* Event properties allow you to attach additional contextual information to the exception.
* Properties must follow the naming convention `event_properties.*` and support string,
* number, and boolean values.
*
* @param key The property key. Must start with "event_properties."
* @param value The property value (string, number, or boolean)
* @returns The event instance for method chaining
*
* @remarks
* **Property Requirements:**
* - Only properties prefixed with `event_properties.*` are allowed
* - Maximum of 50 custom properties per event
* - If the limit is exceeded, properties are sorted alphabetically by key and excess properties are dropped deterministically
* - String properties are limited to 5000 characters (exceeding characters are truncated)
* - Field names must contain only alphabetic characters, numbers, underscores, and dots
* - Each dot must be followed by an alphabetic character
* - Each underscore must be followed by an alphabetic character or number
*
* @example
* ```typescript
* import { Dynatrace, ExceptionEventData } from '@dynatrace/react-native-plugin';
*
* try {
* // Some operation that might throw an error
* throw new Error('Something went wrong');
* } catch (error) {
* if (error instanceof Error) {
* const exceptionEvent = new ExceptionEventData(error)
* .addEventProperty('event_properties.exception_type', 'RuntimeError')
* .addEventProperty('event_properties.stack_depth', 15)
* .addEventProperty('event_properties.handled', true);
*
* Dynatrace.sendExceptionEvent(exceptionEvent);
* }
* }
* ```
*/
addEventProperty(key: string, value: EventProperty): this;
}
declare class ExceptionEventData implements IExceptionEventData {
private rawEventProperties;
private readonly error;
constructor(error: Error);
addEventProperty(key: `event_properties.${string}`, value: EventProperty): this;
toJSON(): JSONObject | null;
}
interface IDynatrace$1 {
/**
* Adds an event modifier that is executed just before the event is transferred.
* This allows you to modify the event to some extent.
*
* Returning null discards the event and prevents future modifier functions from being executed.
*
* Certain reserved fields and namespaces cannot be modified in any way (added, removed, or overridden),
* while others are open for modification.
*
* Open for modification:
* - url.full
* - exception.stack_trace
*
* Open for modification or can be added:
* - event_properties.*
* - session_properties.*
*
* See the public documentation for a detailed list of reserved/open fields.
*
* @param eventModifier The modifier function to modify a given JSONObject
* @returns The registered event modifier instance
*
* @example
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* const modifier = Dynatrace.addEventModifier({
* modifyEvent(event) {
* event['event_properties.modified'] = 'modified';
* return event;
* }
* });
* ```
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-custom-events#event-modifiers
*/
addEventModifier(eventModifier: IEventModifier): IEventModifier;
/**
* Removes an event modifier so it will no longer modify events.
*
* @param eventModifier The modifier function to be removed
* @returns True if the modifier was successfully removed, false otherwise
*
* @example
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* const modifier = Dynatrace.addEventModifier({ modifyEvent: (event) => event });
* const removed = Dynatrace.removeEventModifier(modifier);
* ```
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-custom-events#remove-event-modifiers
*/
removeEventModifier(eventModifier: IEventModifier): boolean;
/**
* Sends an exception event for error tracking and monitoring.
*
* @param exceptionEventData The exception event data built using ExceptionEventData
*
* @example
* ```ts
* import { Dynatrace, ExceptionEventData } from '@dynatrace/react-native-plugin';
*
* try {
* // Code that may throw an error
* throw new Error('Something went wrong');
* } catch (error) {
* if (error instanceof Error) {
* const exceptionEvent = new ExceptionEventData(error)
* .addEventProperty('event_properties.custom_key', 'custom_value')
* .addEventProperty('event_properties.error_context', 'user_action');
*
* Dynatrace.sendExceptionEvent(exceptionEvent);
* }
* }
* ```
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-error-crash-reporting#send-exception-event
*/
sendExceptionEvent(exceptionEventData: ExceptionEventData): void;
/**
* Sends a custom event with event properties and optional duration.
*
* @param eventData The event data built using EventData
*
* @example
* ```ts
* import { Dynatrace, EventData } from '@dynatrace/react-native-plugin';
*
* const customEvent = new EventData()
* .addEventProperty('event_properties.user_action', 'button_click')
* .addEventProperty('event_properties.screen_name', 'checkout')
* .addEventProperty('event_properties.item_count', 3)
* .withDuration(150);
*
* Dynatrace.sendEvent(customEvent);
* ```
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-custom-events#send-custom-events
*/
sendEvent(eventData: EventData): void;
/**
* Starts a new view context. All events reported after this call will be associated
* with this view until a new view is started.
*
* **Note:** Only one view context can be active at a time. Starting a new view will
* automatically stop any currently active view context.
*
* @param name Name of the view (e.g., screen name, page title)
*
* @example
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* // Start tracking a specific screen
* Dynatrace.startView('HomeScreen');
* ```
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-app-performance#view-monitoring
*/
startView(name: string): void;
/**
* Sends a session properties event. Session properties apply to all events in the current session.
*
* **Note:** While you can send multiple session properties at once, if you report the same
* property multiple times, session aggregation will only use one of the values (first or last).
*
* @param sessionPropertyEventData The session property event data built using SessionPropertyEventData builder
*
* @example
* ```ts
* import { Dynatrace, SessionPropertyEventData } from '@dynatrace/react-native-plugin';
*
* // Set session-level properties
* const sessionEvent = new SessionPropertyEventData()
* .addSessionProperty('session_properties.user_tier', 'premium')
* .addSessionProperty('session_properties.app_version', '2.1.0')
* .addSessionProperty('session_properties.device_type', 'mobile');
*
* Dynatrace.sendSessionPropertyEvent(sessionEvent);
* ```
*
* @see https://docs.dynatrace.com/docs/shortlink/react-native-custom-events#send-session-property-events
*/
sendSessionPropertyEvent(sessionPropertyEventData: SessionPropertyEventData): void;