Our React Native plugin allows you to auto-instrument your React Native apps with Dynatrace OneAgent for Android and iOS. The plugin provides an API to add manual instrumentation and is compatible with raw, ejected React Native projects.
For detailed technical documentation, see the Dynatrace React Native plugin page on the npm site.
Follow the steps below to set up the Dynatrace React Native plugin for your mobile app.
To create a mobile application in Dynatrace
From the application settings, select Instrumentation wizard > React Native. The instrumentation wizard guides you through the set-up process.
Install the Dynatrace React Native plugin:
React Native 0.60.0+
npm install @dynatrace/react-native-plugin.ios directory and execute pod install to install the new Dynatrace dependency to your Xcode project.From the instrumentation wizard, download the dynatrace.config.js file and place it into the root directory of your project next to app.json. If you're upgrading from a previous version of the Dynatrace React Native plugin, copy the old configuration values from dynatrace.config to the new dynatrace.config.js file.
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 = {presets: [['module:@react-native/babel-preset'], // or 'module:metro-react-native-babel-preset'],plugins: ['@dynatrace/react-native-plugin/instrumentation/BabelPluginDynatrace',['@babel/plugin-transform-react-jsx',{runtime: 'automatic',importSource: "@dynatrace/react-native-plugin"},],],};
Enable user opt-in mode: 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// (for example, in a privacy settings screen) and the user decision// has to be applied similar to this example.const privacyConfig = new UserPrivacyOptions(DataCollectionLevel.UserBehavior, true);Dynatrace.applyUserPrivacyOptions(privacyConfig);
Run npx instrumentDynatrace in the root of your React Native project to apply the configuration set in the dynatrace.config.js file. This command configures both Android and iOS projects.
Execute react-native run-android or react-native run-ios to rebuild and run your app.
If you're upgrading to React Native 0.70+ or using the @react-native-community/cli 9.x+ version, note that our automated script running before every react-native run-android or react-native run-ios command is no longer working. If you've changed the configuration in the dynatrace.config.js file, execute npx instrumentDynatrace to apply the new configuration.
Whenever you change the configuration in the dynatrace.config.js file, run the following commands and then rebuild your app.
npx instrumentDynatrace to apply the new configuration from dynatrace.config.jsreact-native start --reset-cache to reset the cache. Not resetting the cache might result in a mixture of old and new configurations.Specify custom paths via custom arguments.
See User action naming rules for more details on user action naming in Dynatrace.
displayName: Checks if React views have a display name set.class name: If the display name is unavailable, the class name is used by taking the name property from the constructor.If you minify the React Native code, you can use the keep_classname setting to preserve the class name.
Mobile