--- title: 'How to set up React Native (Expo) analytics, feature flags, and more' sidebar: Docs showTitle: true author: - ian-vanagas date: 2023-01-12 featuredTutorial: false tags: - configuration - feature flags - persons - events --- React Native is a popular mobile app framework for writing native mobile apps using React. In this tutorial, we show how to create a basic React Native app using Expo (a suite of dev tools for React Native). We then add PostHog to that app and set up tools like autocapture, user identification, and feature flags. > Already know how to set up a React Native app? [Click here to skip to the PostHog setup](/tutorials/react-native-analytics#3-adding-posthog-to-our-react-native-app). ## 1. Creating the basic React Native app with Expo To start, we need a directory for the app to live in, the Expo CLI installed, and the Expo Go app on either [Android](https://play.google.com/store/apps/details?id=host.exp.exponent&pli=1) or [iOS](https://apps.apple.com/app/expo-go/id982107779). This assumes you have [Node](https://nodejs.org/en/) and [Git](https://git-scm.com/) already installed. If you’re on Mac, you also must install [watchman](https://facebook.github.io/watchman/) by running `brew install watchman`. Once done, you can initialize the app by running `create-expo-app` and giving it a name (we are calling ours `rn-tutorial`). Once initialized, you can go into the folder and start the app. ```bash npx create-expo-app rn-tutorial cd rn-tutorial npx expo start ``` Open your Expo Go app, scan the QR code in your terminal, and you should open an app with a white screen and some text. ![Basic app](https://res.cloudinary.com/dmukukwp6/image/upload/v1710055416/posthog.com/contents/images/tutorials/react-native-analytics/basic.png) Now that we are up and running, we can add some functionality to help us showcase the features of PostHog. ## 2. Adding functionality to our React Native app To start, we want a home page, an about page, and a button to go between the two. Navigation is needed to make this happen, and we use the `react-navigation` library to do it. PostHog autocaptures screens from the `react-navigation` library, which makes it the best choice for us. To setup `react-navigation`, first, install it: ```bash npm install @react-navigation/native-stack ``` After this, create a native stack navigator by importing the necessary functions and components from the library. Next, remove the boilerplate React Native code, rework the `App()` function to include navigation, and create a new `Home()` function. After doing all this, your App.js file looks like this: ```js // App.js import { StyleSheet, Text, View } from 'react-native'; import { NavigationContainer } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; function Home() { return ( Welcome to the home page ); } const Stack = createNativeStackNavigator(); export default function App() { return ( ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', alignItems: 'center', }, }); ``` A navigation bar was added to the top of the app and our home page changed: ![](https://res.cloudinary.com/dmukukwp6/image/upload/v1710055416/posthog.com/contents/images/tutorials/react-native-analytics/home.png) We still need a second function for the `About()` page, and a button that uses a `navigation` prop to navigate between the two. Also, set the `initialRouteName` in the `Stack.Navigator` to “Home.” ```js import { StyleSheet, Text, View, Button } from 'react-native'; import { NavigationContainer } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; function Home({ navigation }) { return ( Welcome to the home page