Installing the Freshpaint React Native SDK
Getting Started
The first step installing the Freshpaint React Native SDK is to install the @freshpaint/freshpaint-react-native
node module. If you are not using Expo and are using the React Native CLI instead, you'll also need to install and link the @react-native-community/async-storage
dependency:
Next, you'll need to setup the Freshpaint React Native babel plugin. This allows Freshpaint to instrument your app without any additional work on your part. To setup the plugin, add the following bit of code to either your .babelrc
or babel.config.json
:
Then to initialize the Freshpaint SDK, you call freshpaint.init
at the top level with your environment ID. This is normally done in the App.js
file. You can get your Freshpaint environment ID from the Freshpaint sources page.
At this point you'll need to clear any build caches for your app:
Then restart the expo app on your phone.
After that Freshpaint will automatically collect the following actions:
Touches
Text Input Edits
Switch Toggles
Text Input Edits are only captured on iOS and Android. They are not captured on React Native Web.
How it Works
Generally, the React-Native integration works by sending the data to Freshpaint, which then captures that data and sends the data to your destination. The data is sent from Freshpaint to your destination server-side, even if your app destination is configured to be client-side. You can read more about server-side and client-side connection modes here.
Capturing Screen Views
If you are using React Native Navigation, Freshpaint can also autocapture screen views. To set this up, wrap the NavigationContainer
provided by React Navigation with Freshpaint.withReactNavigationAutotrack
:
Then use FreshpaintNavigationContainer
in place of NavigationContainer
:
Verifying your Instrumentation
To verify your Freshpaint instrumentation, navigate to the Freshpaint Live View. As you navigate around your app and click on various buttons, you should see events show up in the Live View:
You can click one of the events to dig into the specific properties captured. For example, you can see the full React component hierarchy of the captured event:
Last updated