Skip to main content
skill CX Codex

dt-setup-react-native — Claude Code skill: what it does and install

Configures the Dynatrace plugin in React Native or Expo projects, handling Babel transformations, config files, and privacy options.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add Dynatrace/dynatrace-for-ai --skill dt-setup-react-native -a claude-code
Open on GitHub

What dt-setup-react-native does

The skill checks for dynatrace.config.js to extract applicationId and beaconUrl, validating userOptIn privacy settings across Android and iOS. It adds @dynatrace/react-native-plugin directly to runtime dependencies in package.json, preventing missing tracking code in release builds.

It edits babel.config.js according to the project setup. For bare React Native, it registers BabelPluginDynatrace right before react-native-reanimated/plugin so Reanimated remains last. In Expo environments with babel-preset-expo, it assigns jsxImportSource directly to the preset, avoiding duplicate JSX transform plugins that break builds.

Building for iOS requires macOS with CocoaPods, while Expo managed projects must run npx expo prebuild first to generate the native folders. Without android/ and ios/ directories, setup will fail. The skill handles installation and instrumentation only, so querying RUM metrics or configuring Dynatrace servers is out of scope.

What it helps with

  • integrate Dynatrace monitoring into React Native or Expo apps
  • configure Babel plugins in the correct order alongside Reanimated
  • validate dynatrace.config.js and user privacy opt-in flags
  • install native iOS pod dependencies on macOS

Example prompts for the agent

  • Add Dynatrace to our React Native app
  • Integrate Dynatrace plugin into the Expo project
  • Configure dynatrace.config.js and Babel settings for mobile observability

How to install dt-setup-react-native

1Skills CLI (Vercel)

npx skills add Dynatrace/dynatrace-for-ai --skill dt-setup-react-native -a claude-code

2Manually: put the files in place

~/.claude/skills/dt-setup-react-native/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/dt-setup-react-native/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about dt-setup-react-native

How to install dt-setup-react-native in Claude Code?

Run npx skills add Dynatrace/dynatrace-for-ai --skill dt-setup-react-native -a claude-code in your terminal.

What does dt-setup-react-native do?

It guides the setup of Dynatrace instrumentation across React Native and Expo apps, managing runtime packages, Babel presets, and user opt-in flags.

What are the prerequisites before running this skill?

You need a React Native 0.68+ or Expo 45+ project with android/ and ios/ folders, Node.js 16.0+, and Dynatrace Experience Vitals access. iOS builds require macOS with CocoaPods.

Source text

SKILL.md · Apache-2.0
---
name: dt-setup-react-native
license: Apache-2.0
description: >-
  Integrate the Dynatrace React Native Plugin into a React Native or Expo project —
  dependency setup, dynatrace.config.js, Babel registration, npx instrumentation,
  navigation tracking, user privacy options, and verification. Handles both bare React Native
  and Expo (babel-preset-expo) Babel configuration automatically.
  Trigger: "add Dynatrace to React Native", "React Native plugin setup", "instrument React Native app",
  "integrate Dynatrace RN", "mobile observability React Native", "react-native-plugin",
  "dynatrace react native", "add Dynatrace to Expo", "instrument Expo app", "Dynatrace Expo setup".
  Do NOT use for: querying RN RUM data (use dt-obs-frontends), non-React Native mobile setups,
  or Dynatrace server-side configuration.
---

# Dynatrace React Native Plugin Integration Skill

## Prerequisites

- Node.js 16.0+ and npm available on `PATH`
- An existing React Native project (v0.68+) or Expo project (v45+) with a `package.json` at the project root
- `android/` and `ios/` platform folders present (Expo managed workflow requires `npx expo prebuild` first)
- A Dynatrace environment with access to Experience Vitals (to obtain `applicationId` and `beaconUrl`, or to download `dynatrace.config.js`)
- Console access to Experience Vitals → Mobile to configure app settings (Data Privacy, Enablement and Cost Control)
- macOS with CocoaPods for iOS builds

Work through the steps below in order, interacting with the user at each decision point. Read actual project files before suggesting changes — do not assume the current state.

## Step 1 — Check for existing `dynatrace.config.js`

Before asking the user anything, check whether `dynatrace.config.js` exists at the project root.

- **File exists:** Read it, show the `applicationId` and `beaconUrl`, and confirm they match the target environment. If correct, run the `userOptIn` check below and skip to Step 3 (config is already present — Step 2 is not needed).
- **File does not exist:** Proceed to Step 2.

**`userOptIn` check:**

Inspect the file for `userOptIn` (Android block) and `DTXUserOptIn` (iOS block).

- **Present on both platforms:** Trust the value as-is. If `true`, flag Step 9. If `false`, skip Step 9.
- **Absent from either platform:** Ask the user: **"Do you have User Opt-In mode enabled or disabled?"** (If unsure: Experience Vitals → Mobile → [Your App] → Settings → Data Privacy.) Add the missing value to the relevant platform(s), then flag Step 9 if the final value is `true`.

## Step 2 — Obtain `dynatrace.config.js` (only if Step 1 found no file)

Ask the user which approach they prefer:

**Option A — Download from console (recommended):**

1. Open their Dynatrace environment
1. Navigate to: Experience Vitals → New Frontend → Mobile
1. Enter app name and choose **React Native** as the platform
1. On the **Select capability and settings** screen, configure monitoring features (crash reporting, user action monitoring, etc.)
1. Download `dynatrace.config.js` and place it at the project root (same level as `package.json`)

Once the file is in place, apply the `userOptIn` check from Step 1 and flag Step 9 if needed.

**Option B — Provide credentials manually:**
Read `references/config-js.md` for the full template and conditional blocks. Collect all required values from the user before creating any files, then apply the `userOptIn` check and flag Step 9 if needed.

## Step 3 — Install the plugin

Read `package.json` first.

- **Not present:** Run:
  ```bash
  npm install @dynatrace/react-native-plugin
  ```
- **Already under `dependencies`:** No change needed.
- **Under `devDependencies`:** Remove it and run `npm install @dynatrace/react-native-plugin`. The plugin is required at runtime including in release builds.

Note: `npm install` alphabetically sorts the `dependencies` object in `package.json`. Existing entries may appear reordered after this step — this is expected npm behavior, not an error.

## Step 4 — Install iOS pods (macOS only)

If on macOS and targeting iOS, run:

```bash
cd ios && pod install && cd ..
```

Confirm success before continuing. CocoaPods must be installed (`gem install cocoapods` if missing).

## Step 5 — Register Babel plugin in `babel.config.js`

Read `babel.config.js`. Append `BabelPluginDynatrace` to the `plugins` array, **just before** `react-native-reanimated/plugin` if that plugin is present (reanimated must always be last):

```js
module.exports = {
  presets: ['module:@react-native/babel-preset'],
  plugins: [
    // ... existing plugins ...
    '@dynatrace/react-native-plugin/instrumentation/BabelPluginDynatrace',
    // react-native-reanimated/plugin goes here if present — must stay last
  ],
};
```

- If the plugins array already contains `'@dynatrace/react-native-plugin/instrumentation/BabelPluginDynatrace'`: skip this step.
- If `useLegacyJscodeshift: true` is set in `dynatrace.config.js`: the Babel plugin is already applied internally — skip this step.
- If the project already configures `metro.config.js` with `babelTransformerPath: '@dynatrace/react-native-plugin/lib/dynatrace-transformer'`: that is the legacy Metro transformer approach — auto-instrumentation is already handled; skip this step and Step 6.

Common mistakes to flag and correct:

- Placing the plugin in `presets` instead of `plugins`
- Placing `BabelPluginDynatrace` after `react-native-reanimated/plugin` — reanimated must always be the absolute last plugin

## Step 6 — Register JSX runtime in `babel.config.js`

Read `babel.config.js` and determine which preset the project uses — this controls how the JSX runtime is registered.

### Expo (`babel-preset-expo`)

If `babel-preset-expo` appears in `presets`, set `jsxImportSource` **on the preset itself**. Do not add a separate `@babel/plugin-transform-react-jsx` plugin — Expo's preset already owns the JSX transform, and stacking a second JSX plugin over it breaks the instrumentation.

```js
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',
      'react-native-reanimated/plugin',  // stays last
    ],
  };
};
```

- If `babel-preset-expo` already has `jsxImportSource: '@dynatrace/react-native-plugin'`: no change needed.
- If a different `jsxImportSource` is already set: replace it with `'@dynatrace/react-native-plugin'`.
- Remove any existing `@babel/plugin-transform-react-jsx` plugin entry — it must not coexist with the preset-level `jsxImportSource` on `babel-preset-expo`.

### Bare React Native (`@react-native/babel-preset` or `metro-react-native-babel-preset`)

For metro 0.72.0+ (React Native 0.71+), add `@babel/plugin-transform-react-jsx` with the Dynatrace `importSource` **before** `BabelPluginDynatrace` in the plugins array:

```js
module.exports = {
  presets: [
    ['module:@react-native/babel-preset', { unstable_transformProfile: 'hermes-stable' }],
  ],
  plugins: [
    ['@babel/plugin-transform-react-jsx', {
      runtime: 'automatic',
      importSource: '@dynatrace/react-native-plugin',
    }],
    '@dynatrace/react-native-plugin/instrumentation/BabelPluginDynatrace',
    'react-native-reanimated/plugin',  // stays last
  ],
};
```

The required plugin order is:

1. `@babel/plugin-transform-react-jsx` (JSX runtime — first)
1. `BabelPluginDynatrace` (auto-instrumentation — before reanimated)
1. `react-native-reanimated/plugin` (must be absolutely last)

- If the project already has `@babel/plugin-transform-react-jsx` with `importSource: '@dynatrace/react-native-plugin'`: no change needed.
- If a different `importSource` is set: replace it with `'@dynatrace/react-native-plugin'`.

After any Babel change, reset Metro cache on next build:

```bash
npx react-native start --reset-cache
```

## Step 7 — Run `npx instrumentDynatrace`

```bash
npx instrumentDynatrace
```

This reads `dynatrace.config.js` and automatically configures Android `build.gradle` and iOS `Info.plist`. **Must be re-run whenever `dynatrace.config.js` changes.**

Common mistakes to flag and correct:

- Skipping this step after changing `dynatrace.config.js`
- Using `react-native instrument-dynatrace` — same effect but deprecated for RN 0.70+
- Manual edits to `build.gradle` or `Info.plist` — not needed, the script handles it

If `android/` and `ios/` folders exist but automatic plist discovery fails, pass explicit paths:

```bash
npx instrumentDynatrace plist=ios/YourApp/Info.plist
```

**Expo only:** If `android/` and `ios/` folders do not yet exist, run `npx expo prebuild` first, then re-run `npx instrumentDynatrace`.

## Step 7a — Manual SDK startup (only if `autoStart: false`)

**Skip this step if `autoStart` is `true` or absent in `dynatrace.config.js` — the SDK starts automatically.**

Check `dynatrace.config.js` for `autoStart: false` in the `react` block. If present, the SDK will not start on its own and no data will be collected until `Dynatrace.start()` is called explicitly.

Add the startup call at the top level of the app entry file (for example `App.tsx` or `index.js`). Any logic that depends on the SDK being ready goes after the `await`:

```ts
import { Dynatrace, ConfigurationBuilder } from '@dynatrace/react-native-plugin';

await Dynatrace.start(
  new ConfigurationBuilder('<BEACON_URL>', '<APPLICATION_ID>').buildConfiguration()
);
// SDK is initialized — place any SDK-dependent logic here
```

Replace `<BEACON_URL>` and `<APPLICATION_ID>` with **the exact same values** from `dynatrace.config.js` — they must match or the SDK will report to the wrong environment.

**Important:** Even with `autoStart: false`, the `beaconUrl` and `applicationId` must still be present in `dynatrace.config.js` (used by `npx instrumentDynatrace` to configure the native files). The values passed to `ConfigurationBuilder` at runtime take effect — values in the config file are ignored when manual startup is used.

**Tradeoff:** Manual startup causes the SDK to miss the native application start event and any interactions that happen before `start()` is called. Use `autoStart: true` (the default) unless runtime credential injection is a hard requirement.

## Step 8 — Enable navigation tracking

Check `dynatrace.config.js` for the `react.navigation` block and check `package.json` for `@react-navigation/native`.

If `@react-navigation/native` is present and `navigation.enabled` is not set to `true`, add it:

```js
module.exports = {
  react: {
    navigation: {
      enabled: true,  // requires @react-navigation/native v5–v7
    },
    // ...
  },
  // ...
};
```

Then re-run `npx instrumentDynatrace`.

**What this does:** When enabled, the plugin hooks into React Navigation's `NavigationContainer` and detects route changes automatically. Each navigation event is reported to Dynatrace as a view change, with the current route represented as a URL-style path (e.g., `/Home`, `/Home/Details`). This populates the screen timeline in Dynatrace user sessions and associates all events with the currently active screen. This setting is enabled by default in the plugin's own config template.

If `@react-navigation/native` is **not** present: inform the user that automatic view tracking requires `@react-navigation/native`. They can use `Dynatrace.startView("ScreenName")` for manual view tracking instead.

## Step 9 — Privacy options call (only if `userOptIn: true`)

**Skip this step if `userOptIn` was not set to `true` during Steps 1 or 2.**

Read `references/user-opt-in.md` for the full guidance on `DataCollectionLevel`, `crashReportingOptedIn`, and placement options. Ask the user the questions defined there, then apply the call to the relevant file.

## Step 10 — Post-setup summary

Confirm to the user what is active:

**Enabled by default** (when `userOptIn` is `false` or absent):

- ✅ Crash reporting
- ✅ User action tracking (Touchables, Buttons, Pressable, Switch)
- ✅ Network monitoring
- ✅ Error handler
- ✅ Auto-start

> When `userOptIn: true`, all data collection — including crash reporting — is gated on the `applyUserPrivacyOptions(...)` call.

**Configured during this setup:**

- Privacy mode: [userOptIn: true — consent call added / opt-out (SDK default)]
- Navigation tracking: [react.navigation.enabled: true / manual via Dynatrace.startView()]

## Step 11 — Verification

Read `references/verification.md` and show the user the verification checklist. If no data appears after 5 minutes, work through the troubleshooting steps in that file.

## Reference Files

- `references/config-js.md` — Full `dynatrace.config.js` template with Grail and userOptIn conditional blocks
- `references/user-opt-in.md` — `applyUserPrivacyOptions` guidance, `DataCollectionLevel` options, placement options
- `references/verification.md` — Post-setup verification checklist and troubleshooting

## External References

- [@dynatrace/react-native-plugin on npm](https://www.npmjs.com/package/@dynatrace/react-native-plugin) — package changelog, API docs, and latest version
- [Dynatrace React Native Installation Docs](https://docs.dynatrace.com/docs/observe/digital-experience/new-rum-experience/mobile-frontends/react-native) — official setup guide

© Dynatrace · Apache-2.0 · Dynatrace/dynatrace-for-ai

Similar skills

Everything for Mobile →

From the same set29

dt-platform-costs Analyzes actual Dynatrace DPS consumption and spend directly from dt.system.events via DQL. Helps teams track cost drivers and chargeback. CX Codex +1 1,400installs dt-obs-ext-monitors Sends third-party test outcomes and CI monitor results to Dynatrace Grail through the events ingest API. Replaces the deprecated synthetic v1 endpoint. CX Codex +1 1,100installs dt-sec-ioc-hunting Hunts indicators of compromise from reports and advisories across Dynatrace logs and spans, then scores threat exposure from 0 to 100. CX Codex +1 1,000installs dt-obs-network-flows A Dynatrace skill that reads network flows from three sources and answers who talks to whom and where connections break. CX Codex +1 912installs dt-obs-network-devices This skill reads SNMP monitoring data in Dynatrace: device inventory, interface state, topology and logs. Useful when a port is down or a switch is saturated. CX Codex +1 907installs dt-obs-compliance-assistant Monitors EU DORA compliance posture using Dynatrace Compliance Assistant. It inspects compliance scores, Critical or Important Functions, and incidents. CX Codex +1 889installs dt-setup-android Instruments an Android app with the Dynatrace Mobile Agent for initial telemetry. Configures Gradle files, agent credentials, and user privacy opt-in. CX Codex +1 857installs dt-setup-flutter Integrates the Dynatrace plugin into Flutter projects: automates dependency configuration and sets up app startup instrumentation. CX Codex +1 852installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor