@dynatrace/react-native-plugin
Version:
This plugin gives you the ability to use the Dynatrace Mobile agent in your react native application.
1,181 lines (1,169 loc) • 85.7 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 } 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__ || isTestEnvironment) {
* 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 this event and prevents future mutator functions to be executed.
*
* Certain reserved fields and namespaces can't be modified in any way (added, removed or overridden),
* while others are open for modification. 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/observe/digital-experience/new-rum-experience/api
*/
modifyEvent(event: JSONObject): JSONObject | null;
}
interface IHttpRequestEventBuilder {
/**
* Sets the duration of the HTTP request in milliseconds.
*
* @param duration The request duration in milliseconds. Only positive numbers are valid.
* @returns The builder instance for method chaining
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventBuilder } from '@dynatrace/react-native-plugin';
*
* const requestEvent = new HttpRequestEventBuilder('https://api.example.com/data', 'GET')
* .withDuration(250);
* Dynatrace.sendHttpRequestEvent(requestEvent);
* ```
*
* @see https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/api
*/
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 builder instance for method chaining
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventBuilder } from '@dynatrace/react-native-plugin';
*
* const requestEvent = new HttpRequestEventBuilder('https://api.example.com/data', 'GET')
* .withStatusCode(200);
* Dynatrace.sendHttpRequestEvent(requestEvent);
* ```
*
* @see https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/api
*/
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 builder instance for method chaining
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventBuilder } from '@dynatrace/react-native-plugin';
*
* const requestEvent = new HttpRequestEventBuilder('https://api.example.com/data', 'GET')
* .withReasonPhrase('OK');
* Dynatrace.sendHttpRequestEvent(requestEvent);
* ```
*
* @see https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/api
*/
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 builder instance for method chaining
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventBuilder } from '@dynatrace/react-native-plugin';
*
* try {
* // Request code
* } catch (error) {
* const requestEvent = new HttpRequestEventBuilder('https://api.example.com/data', 'GET')
* .withError(error);
* Dynatrace.sendHttpRequestEvent(requestEvent);
* }
* ```
*
* @see https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/api
*/
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 builder instance for method chaining
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventBuilder } from '@dynatrace/react-native-plugin';
*
* const requestEvent = new HttpRequestEventBuilder('https://api.example.com/data', 'POST')
* .withBytesSent(1024);
* Dynatrace.sendHttpRequestEvent(requestEvent);
* ```
*
* @see https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/api
*/
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 builder instance for method chaining
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventBuilder } from '@dynatrace/react-native-plugin';
*
* const requestEvent = new HttpRequestEventBuilder('https://api.example.com/data', 'GET')
* .withBytesReceived(2048);
* Dynatrace.sendHttpRequestEvent(requestEvent);
* ```
*
* @see https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/api
*/
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 builder instance for method chaining
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventBuilder } from '@dynatrace/react-native-plugin';
*
* const requestEvent = new HttpRequestEventBuilder('https://api.example.com/data', 'GET')
* .withTraceparentHeader('00-80e1afed08e019fc1110464cfa66635c-7a085853722dc6d2-01');
* Dynatrace.sendHttpRequestEvent(requestEvent);
* ```
*
* @see https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/api
*/
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
* - 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 builder instance for method chaining
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventBuilder } from '@dynatrace/react-native-plugin';
*
* const requestEvent = new HttpRequestEventBuilder('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/observe/digital-experience/new-rum-experience/api
*/
addEventProperty(key: `event_properties.${string}`, value: EventProperty): this;
}
type EventProperty = string | number | boolean;
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';
declare class HttpRequestEventBuilder implements IHttpRequestEventBuilder {
private url;
private requestMethod;
private static readonly allowedRequestMethods;
private static readonly maxReasonPhraseLength;
private duration;
private statusCode?;
private reasonPhrase?;
private bytesReceived?;
private bytesSent?;
private error?;
private traceparentHeader?;
private rawEventProperties;
private hasDroppedTraceparent;
private hasDroppedCustomProperties;
private hasNfnValues;
private triedToOverwriteDuration;
/**
* Creates a new HTTP request event builder.
*
* @param url The request URL. Must be a valid URL according to the WHATWG URL Standard, starting with `http://` or `https://`.
* @param requestMethod The HTTP request method. Allowed values: GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS,
* TRACE, PATCH (case-insensitive).
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventBuilder } from '@dynatrace/react-native-plugin';
*
* const requestEvent = new HttpRequestEventBuilder('https://api.example.com/data', 'GET');
* Dynatrace.sendHttpRequestEvent(requestEvent);
* ```
*
* @see https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/api
*/
constructor(url: `http://${string}` | `https://${string}`, 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: `event_properties.${string}`, value: EventProperty): this;
build(): JSONObject | null;
private hasValidMandatoryAttriutes;
private isInvalidUrl;
private sanitizeStatusCode;
private sanitizeReasonPhrase;
private sanitizeDuration;
private sanitizeBytesSent;
private sanitizeBytesReceived;
private isStatusCodeError;
private isEventPropertyKey;
private includeIfDefined;
private includeIfTrue;
private parseTraceparent;
private allZeros;
}
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.
*
* 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/observe/digital-experience/new-rum-experience/api
*/
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/observe/digital-experience/new-rum-experience/api
*/
removeEventModifier(eventModifier: IEventModifier): boolean;
/**
* Sends an exception event for error tracking and monitoring.
*
* @param {Error} error The error object containing exception information
* @param {JSONObject} properties Optional custom properties for the exception event. Must be a valid JSON object
* and cannot contain functions, undefined, Infinity, or NaN as values (they will be replaced with null).
*
* **Property Requirements:**
* - Only properties prefixed with `event_properties.*` are allowed
* - Additionally, the `duration` property is allowed
* - Maximum of 50 custom properties per event
* - 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
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* try {
* // Code that may throw an error
* throw new Error('Something went wrong');
* } catch (error) {
* Dynatrace.sendExceptionEvent(error, {
* 'event_properties.custom_key': 'custom_value',
* 'event_properties.error_context': 'user_action'
* });
* }
* ```
*
* @see https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/api
*/
sendExceptionEvent(error: Error, fields?: JSONObject): void;
/**
* Sends a custom event with properties in JSON format.
*
* @param {JSONObject} properties Event properties as a valid JSON object. Cannot contain functions, undefined,
* Infinity, or NaN as values (they will be replaced with null). Empty objects are valid.
*
* **Property Requirements:**
* - Only properties prefixed with `event_properties.*` are allowed
* - Additionally, the `duration` property is allowed
* - Maximum of 50 custom properties per event
* - 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
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* Dynatrace.sendEvent({'event_properties.custom_key':'custom_value'});
* ```
*
* @see https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/api
*/
sendEvent(properties: JSONObject): void;
/**
* Starts a new view context. All events reported after this call will be associated
* with this view until `stopView()` is called or 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/observe/digital-experience/new-rum-experience/api
*/
startView(name: string): void;
/**
* Stops the current view context. Events reported after this call will not be
* associated with any view until a new view is started.
*
* @example
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* Dynatrace.startView('HomeScreen');
* // ... user interactions ...
* Dynatrace.stopView();
* ```
*
* @see https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/api
*/
stopView(): 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 {JSONObject} properties Session properties as a valid JSON object. Cannot contain functions,
* undefined, Infinity, or NaN as values (they will be replaced with null). Empty objects are valid.
*
* **Property Requirements:**
* - Only properties prefixed with `session_properties.*` are allowed
* - Additionally, the `duration` property is allowed
* - Maximum of 50 custom properties per event
* - 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
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* // Set session-level properties
* Dynatrace.sendSessionPropertyEvent({
* 'session_properties.user_tier': 'premium',
* 'session_properties.app_version': '2.1.0',
* 'session_properties.device_type': 'mobile'
* });
* ```
*
* @see https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/api
*/
sendSessionPropertyEvent(properties: JSONObject): void;
/**
* Sends an HTTP request event for network activity monitoring.
*
* @param {HttpRequestEventBuilder} httpRequestEventBuilder Builder object containing the HTTP request details
*
* @example
* ```ts
* import { Dynatrace, HttpRequestEventBuilder } from '@dynatrace/react-native-plugin';
*
* // Basic HTTP request event
* const requestBuilder = new HttpRequestEventBuilder('https://api.example.com/users', 'GET');
* Dynatrace.sendHttpRequestEvent(requestBuilder);
*
* // HTTP request with additional details
* const detailedBuilder = new HttpRequestEventBuilder('https://api.example.com/data', 'POST')
* .setResponseCode(200)
* .setRequestHeaders({ 'Content-Type': 'application/json' });
* Dynatrace.sendHttpRequestEvent(detailedBuilder);
* ```
*
* @see https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/api
*/
sendHttpRequestEvent(httpRequestEventBuilder: HttpRequestEventBuilder): void;
}
/**
* Root action that extends the standard IDynatraceAction with the ability to create
* nested child actions for hierarchical action tracking.
*/
interface IDynatraceRootAction extends IDynatraceAction {
/**
* Creates a child action nested under this root action. Child actions allow you to track
* sub-tasks or operations within a larger workflow, providing hierarchical visibility
* into user interactions and application behavior.
*
* **Note:** When the parent action is closed with `leaveAction()` or `cancel()`, all
* child actions are automatically closed as well.
*
* @param {string} name Name of the child action (limited to 250 characters)
* @param {Platform} platform Optional platform filter. Defaults to both Android and iOS.
* @returns {IDynatraceAction} The created child action instance
*
* @example
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* const parentAction = Dynatrace.enterManualAction('User Registration');
*
* const validationAction = parentAction.enterAction('Validate Input');
* validationAction.reportEvent('Email Validated');
* validationAction.leaveAction();
*
* const submitAction = parentAction.enterAction('Submit Form');
* submitAction.reportIntValue('Retry Attempts', 1);
* submitAction.leaveAction();
*
* parentAction.leaveAction();
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#create-custom-sub-actions
*/
enterAction(name: string, platform?: Platform): IDynatraceAction;
}
interface IDynatrace extends IDynatrace$1 {
/**
* Starting the React Native plugin and OneAgent for Android or iOS. This method is only necessary
* in case of manual startup and should be ignored in auto startup scenarios. The start method will
* set the error handler for reporting crashes and will apply the provided configuration globally.
*
* @param {IConfiguration} configuration Configuration for a manual startup of the plugin
*
* @example
* ```ts
* import { ConfigurationBuilder, Dynatrace } from '@dynatrace/react-native-plugin';
*
* const configurationBuilder = new ConfigurationBuilder("beaconUrl", "applicationId");
* // Use several configuration options like withLogLevel(LogLevel.Debug)
* await Dynatrace.start(configurationBuilder.buildConfiguration());
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#plugin-startup
*/
start(configuration: IConfiguration): Promise<void>;
/**
* This call allows to monitor the passed in component. Depending on the type of the component
* (Function Component or Class Component), it will be wrapped and data of renderings will be
* automatically reported.
*
* The name of the Component, which can be passed as parameter, is important because the build
* process will remove the name of a Functional Component. Still this parameter is optional as
* other properties can be used at runtime as well (e.g. dtActionName).
*
* @param Component Functional or Class Component
* @param {string} name The name of the Component
* @returns The Component which was wrapped to be monitored
*
* @example
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* export function MyFunctionalComponent(){
* // Content of component
* }
*
* Dynatrace.withMonitoring(MyFunctionalComponent, "MyFunctionalComponent");
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#monitor-a-component
*/
withMonitoring(Component: React.FunctionComponent | React.ComponentClass, name?: string): React.FunctionComponent | React.ComponentClass;
/**
* Reroutes to `Dynatrace.enterAutoAction`
*
* @deprecated Please use either {@link enterAutoAction}, which is doing the same or alternatively {@link enterManualAction}.
*/
enterAction(name: string, platform?: Platform): IDynatraceAction;
/**
* Creates an Action which will be automatically handled by the plugin. This means that the
* plugin decides about the hierarchy of this action. If there is no open action, the following
* action will be a root action. All other actions created by this method, while a root action
* is open, will be automatically inserted as a child action. Furthermore the plugin will automatically
* link webrequest (if they are not tagged manually) to the open root action.
*
* @param {string} name Name of the action, which will be created. This name must not be empty. (limited to 250 characters)
* @param {Platform} platform Is optional, which means by default this call will be applied on both platforms (Android & iOS).
* @returns {IDynatraceAction} Action that is created. If name was empty a NullAction will be provided,
* which will act as normal action, but has no functionality.
*
* @example
* ```ts
* import { Dynatrace } from '@dynatrace/react-native-plugin';
*
* let myAction = Dynatrace.enterAutoAction("MyButton tapped");
* // Perform the action and whatever else is needed.
* myAction.leaveAction();
* ```
*
* @see https://www.npmjs.com/package/@dynatrace/react-native-plugin#create-custom-actions
*/
enterAutoAction(name: string, platform?: Platform): IDynatraceAction;
/**
* Creates an Action which will NOT be handled by the plugin. This means that you have full control
* about the hierarchy of your actions. This function will create a {@link IDynatraceRootAction} for you,
* which has the ability to create child actions via {@link IDynatraceRootAction.enterAction}. Be aware,
* because of the full manual approach the plugin will not link webrequest automatically. Webrequest
* have to be manually tagged by using the tag provided by the action via {@link IDynatraceAction.getRequestTag}.
*
* @param {string}