managarten/apps-archived/maerchenzauber/apps/mobile/README/ExpoPosthogReadMe.md
Till-JS 61d181fbc2 chore: archive inactive projects to apps-archived/
Move inactive projects out of active workspace:
- bauntown (community website)
- maerchenzauber (AI story generation)
- memoro (voice memo app)
- news (news aggregation)
- nutriphi (nutrition tracking)
- reader (reading app)
- uload (URL shortener)
- wisekeep (AI wisdom extraction)

Update CLAUDE.md documentation:
- Add presi to active projects
- Document archived projects section
- Update workspace configuration

Archived apps can be re-activated by moving back to apps/

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 07:03:59 +01:00

10 KiB
Raw Permalink Blame History

How to set up React Native (Expo) analytics, feature flags, and more Jan 12, 2023

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.

  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 or iOS. This assumes you have Node and Git already installed. If youre on Mac, you also must install 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.

Terminal

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

Now that we are up and running, we can add some functionality to help us showcase the features of PostHog.

  1. 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:

Terminal

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:

JavaScript

// 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 ( <Stack.Navigator> <Stack.Screen name="Home" component={Home} /> </Stack.Navigator> ); }

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:

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.”

JavaScript

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 <Button title="Go to About" onPress={() => navigation.navigate("About")} /> ); }

function About() { return ( Welcome to the About page ); }

const Stack = createNativeStackNavigator();

export default function App() { return ( <Stack.Navigator initialRouteName="Home"> <Stack.Screen name="Home" component={Home} /> <Stack.Screen name="About" component={About} /> </Stack.Navigator> ); }

// ... After setting all this up, reload your app and click the button to go to the About screen page. When there, you see you automatically get a back button added via navigation.

Adding a form We want a form where users can submit their email so we can identify them later. To do this, import the TextInput component and useState from React (so we can keep that value). We then add and style the TextInput, Button, and a Text component to show the submitted value. After doing all of this, your Home() function looks like this:

JavaScript

import { StyleSheet, Text, View, Button, TextInput } from 'react-native'; import { NavigationContainer } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { useState } from 'react';

function Home({ navigation }) { const [text, setText] = useState('') const [submit, setSubmit] = useState('')

function getText() { setSubmit(text) }

return ( Welcome to the home page <Button title="Go to About" onPress={() => navigation.navigate("About")} /> <TextInput style={{ height: 40, borderColor: 'gray', borderWidth: 1 }} placeholder="enter text here" onChangeText={text => setText(text)} />