title_wip

[Edit this page](https://github.com/ClickHouse/clickhouse-docs/blob/main/docs/use-cases/observability/clickstack/ingesting-data/sdks/react-native.md)

The ClickStack React Native SDK allows you to instrument your React Native
application to send events to ClickStack. This allows you to see mobile network
requests and exceptions alongside backend events in a single timeline.

This Guide Integrates:

- **XHR/Fetch Requests**

## Getting started[​](#getting-started "Direct link to Getting started")

### Install via NPM[​](#install-via-npm "Direct link to Install via NPM")

Use the following command to install the [ClickStack React Native package](https://www.npmjs.com/package/@hyperdx/otel-react-native).

```
npm install @hyperdx/otel-react-native
```

### Initialize ClickStack[​](#initialize-clickstack "Direct link to Initialize ClickStack")

Initialize the library as early in your app lifecycle as possible:

```
import { HyperDXRum } from '@hyperdx/otel-react-native';

HyperDXRum.init({
  url: 'http://your-otel-collector:4318',
  service: 'my-rn-app',
  apiKey: '<YOUR_INGESTION_API_KEY>', // Omit for Managed ClickStack
  tracePropagationTargets: [/api.myapp.domain/i], // Set to link traces from frontend to backend requests
});
```

### Attach user information or metadata (Optional)[​](#attach-user-information-metadata "Direct link to Attach user information or metadata (Optional)")

Attaching user information will allow you to search/filter sessions and events
in HyperDX. This can be called at any point during the client session. The
current client session and all events sent after the call will be associated
with the user information.

`userEmail`, `userName`, and `teamName` will populate the sessions UI with the
corresponding values, but can be omitted. Any other additional values can be
specified and used to search for events.

```
HyperDXRum.setGlobalAttributes({
  userId: user.id,
  userEmail: user.email,
  userName: user.name,
  teamName: user.team.name,
  // Other custom properties...
});
```

### Instrument lower versions[​](#instrument-lower-versions "Direct link to Instrument lower versions")

To instrument applications running on React Native versions lower than 0.68,
edit your `metro.config.js` file to force metro to use browser specific
packages. For example:

```
const defaultResolver = require('metro-resolver');

module.exports = {
  resolver: {
    resolveRequest: (context, realModuleName, platform, moduleName) => {
      const resolved = defaultResolver.resolve(
        {
          ...context,
          resolveRequest: null,
        },
        moduleName,
        platform,
      );

      if (
        resolved.type === 'sourceFile' &&
        resolved.filePath.includes('@opentelemetry')
      ) {
        resolved.filePath = resolved.filePath.replace(
          'platform\\node',
          'platform\\browser',
        );
        return resolved;
      }

      return resolved;
    },
  },
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: true,
      },
    }),
  },
};
```

## View navigation[​](#view-navigation "Direct link to View navigation")

[react-navigation](https://github.com/react-navigation/react-navigation) version 5 and 6 are supported.

The following example shows how to instrument navigation:

```
import { startNavigationTracking } from '@hyperdx/otel-react-native';

export default function App() {
  const navigationRef = useNavigationContainerRef();
  return (
    <NavigationContainer
      ref={navigationRef}
      onReady={() => {
        startNavigationTracking(navigationRef);
      }}
    >
      <Stack.Navigator>...</Stack.Navigator>
    </NavigationContainer>
  );
}
```

- [Getting started](#getting-started)
  - [Install via NPM](#install-via-npm)- [Initialize ClickStack](#initialize-clickstack)- [Attach user information or metadata (Optional)](#attach-user-information-metadata)- [Instrument lower versions](#instrument-lower-versions)- [View navigation](#view-navigation)

Was this page helpful?