On this page, you will learn how to perform initial setup for React Native frontends.
Before you begin, ensure your environment meets the following requirements:
| Requirement | Minimum Version |
|---|---|
React | 16.8 |
React Native | 0.60 |
Node.js | 16.0.0 |
Android SDK version | 21 |
iOS SDK | 12 |
Gradle | 7.0 |
Android Gradle Plugin | 7.0 |
Java | 11 |
Kotlin | 2.0.21 |
Jetpack Compose | 1.4 - 1.10 |
Experience Vitals > Overview.To enable RUM for mobile frontends at the environment level:
Experience Vitals.dynatrace.config.js file and save it into your project root.Install the Dynatrace React Native plugin:
npm install @dynatrace/react-native-plugin
For iOS projects using CocoaPods, navigate to your ios directory and run pod install to install the Dynatrace dependency.
Copy the dynatrace.config.js file you generated in the Dynatrace web UI to your project root.
The configuration file contains your beaconUrl, applicationId, and instrumentation settings. Configure the components you want to monitor for lifecycle instrumentation.
By default, you'll only see application startup and touch events. Define the components you want lifecycle-instrumented in the configuration file to capture additional events.
If you need to create a default configuration file, run:
npx configDynatrace
Add the @dynatrace/react-native-plugin/instrumentation/BabelPluginDynatrace babel plugin and the @dynatrace/react-native-plugin JSX runtime to your babel.config.js file:
module.exports = function (api) {api.cache(true);return {presets: [['babel-preset-expo',{jsxRuntime: 'automatic',jsxImportSource: '@dynatrace/react-native-plugin',},],],plugins: ['@dynatrace/react-native-plugin/instrumentation/BabelPluginDynatrace',],};};
If you're using NativeWind, use 'nativewind' as the importSource for the JSX runtime in babel.config.js. The plugin internally calls the Dynatrace JSX runtime after NativeWind's runtime.
Your app should include a privacy notice for users to configure their privacy preferences. You can insert the following API call to enable Dynatrace monitoring:
import { Dynatrace, DataCollectionLevel, UserPrivacyOptions } from '@dynatrace/react-native-plugin';// Privacy settings configured below are only provided// to allow a quick start with capturing monitoring data.// This has to be requested from the user// (e.g. in a privacy settings screen) and the user decision// has to be applied similar to this example.let privacyConfig = new UserPrivacyOptions(DataCollectionLevel.UserBehavior, true);Dynatrace.applyUserPrivacyOptions(privacyConfig);
For Expo projects, ensure your project contains android and/or ios folders by running:
npx expo prebuild
Run the instrumentation command to configure both Android and iOS projects:
npx instrumentDynatrace
This command modifies your application's *.plist and build.gradle files, enabling auto-instrumentation on Android and writing the configuration for both platforms.
Build and run your application:
react-native run-android# orreact-native run-ios
When you change your configuration in dynatrace.config.js, reset the metro cache using:
react-native start --reset-cache
Metro caches all files, and configuration changes might lead to inconsistent behavior without resetting the cache.
The automated script that runs before every start, run-android, or run-ios command no longer works with React Native 0.70+ or @react-native-community/cli 9.x+. When your dynatrace.config.js changes, manually execute npx instrumentDynatrace beforehand.
After installing and configuring OneAgent, verify that data is being collected:
Open your app and perform several actions (navigate between screens, tap buttons, and make network requests).
Experience Vitals > Overview.This data can also be analyzed directly in Grail using DQL.
It may take a few minutes for data to appear in Dynatrace after the first app launch.
After completing the initial setup, consider exploring the following topics to enhance your monitoring capabilities: