React Native
Add the Tugboat SDK to your React Native or Expo app.
Add Tugboat to a React Native app, with or without Expo. You'll need your app's SDK keys (one for Android, one for iOS). See SDK overview.
Requirements
- React Native 0.88 or later, with the New Architecture
- Android 7.0 (API 24) or later
- iOS 15.1 or later
- For Expo: Expo SDK 58 or later, with a development build. Expo Go isn't supported.
Install
npm install @tugboat-ai/react-nativeThen, for iOS:
cd ios && pod installDon't also add the Tugboat pod; the package includes what it needs.
Expo
npx expo install @tugboat-ai/react-nativeAdd the plugin to app.json, then rebuild:
{
"expo": {
"plugins": ["@tugboat-ai/react-native"]
}
}npx expo prebuildStart the SDK
Call Tugboat.start once, when your app loads. With Expo Router, put it in your root layout file.
import { Platform } from 'react-native';
import { Tugboat } from '@tugboat-ai/react-native';
Tugboat.start({
collector: {
baseUrl: 'https://collector.gettugboat.com',
apiKey: Platform.OS === 'ios' ? IOS_SDK_KEY : ANDROID_SDK_KEY,
},
app: { name: 'My App' },
enabled: true,
});collector.baseUrl, collector.apiKey and app.name are required. Your app's version, build number and ID are filled in for you.
Turn capture on
Capture is off by default. Either:
- set
enabled: true, as above, to record from launch, or - leave it off and call
Tugboat.activate(activationRequestId)when you want to start recording, andTugboat.deactivate()to stop.
Name your screens
React Navigation: pass the ref you give NavigationContainer:
import { createNavigationContainerRef, NavigationContainer } from '@react-navigation/native';
const navigationRef = createNavigationContainerRef();
Tugboat.trackNavigation(navigationRef);
export default function App() {
return <NavigationContainer ref={navigationRef}>{/* ... */}</NavigationContainer>;
}Expo Router: track the navigation ref in your root layout:
import { Tugboat } from '@tugboat-ai/react-native';
import { useNavigationContainerRef } from 'expo-router';
import { useEffect } from 'react';
const ref = useNavigationContainerRef();
useEffect(() => Tugboat.trackNavigation(ref), [ref]);Other navigators: call Tugboat.setScreen(name) when the screen changes.
Without screen names, sessions have no screens to line up with your Manifest.
testID values on your components are sent as they are, as part of tap targets. Don't build testIDs from user data.
Identify users
Tugboat.setUserId('user-123');
Tugboat.setTraits({ plan: 'pro' });Pass null to setUserId to clear it, for example when someone signs out.
Capture network calls
fetch and XMLHttpRequest calls are recorded automatically. The SDK records each request's path, without its query string. IDs in the path are recorded as they are.
- To record only some hosts, set
networkAllowHosts. - To turn network capture off, set
captureNetwork: false. - With Expo, the global
fetchis replaced by Expo's own and isn't recorded. SetEXPO_PUBLIC_USE_RN_FETCH=1to record it.XMLHttpRequestand axios are recorded either way.
Send events
Custom events aren't available on React Native yet.
Mark sensitive content
All text, images and text inputs are masked by default. To always mask something else, wrap it:
<Tugboat.Sensitive>
<AccountNumber number={account.number} />
</Tugboat.Sensitive>A modal or portal opened from inside it isn't covered. See Privacy and masking.
Verify your setup
- Run a development build with capture turned on and use the app for a minute.
- Check the native logs: Logcat tag
TugboatRNon Android, or[TugboatRN]in the Xcode console on iOS. - Open Findings › Sessions › All sessions in Tugboat and find your session.
Release builds must send sessions over HTTPS.
Pause or stop capture
Tugboat.deactivate()stops recording until you activate again.Tugboat.stop()ends the session.
Troubleshooting
The native module is not linked
Rebuild the native app. If you use Expo, use a development build, not Expo Go.
Custom networking stops working
Tugboat installs its own HTTP handling to record requests. On Android it replaces a custom OkHttp client builder; on iOS it bypasses custom session configuration and certificate pinning. Set captureNetwork: false if you rely on these.
A reload starts a new session
Reloading JavaScript and calling start again starts a new session. This is expected in development.
Configuration options
| Option | Default | Description |
|---|---|---|
enabled | false | Start recording when the SDK starts. |
captureNetwork | true | Record fetch and XMLHttpRequest calls. |
networkAllowHosts | all hosts | Only record requests to these hosts. |
captureFocusChanges | false | Record when a text field gains focus (never what's typed). |
captureSystemInput | false | Record presses of back and hardware buttons (Android). |
durableOutbox | false | Keep unsent recordings on disk and send them later, even after the app restarts. |
More resources
@tugboat-ai/react-nativeon npm.- Source code on GitHub.
Updated about 3 hours ago