This is an example React Native app demonstrating the integration of the Sift React Native SDK.
The example app serves multiple purposes:
- Testing & Development: Provides a working React Native environment to test the SDK's native modules (iOS and Android) during development
- Integration Demo: Shows developers how to integrate the SDK into their own React Native apps
- Debugging: Allows contributors to debug native code and test changes before publishing
- Documentation: Serves as living documentation of SDK usage patterns
The example app is set up as a workspace package, allowing it to use the local development version of the SDK rather than the published npm package.
This guide will help you set up and run the sift-react-native example app from scratch.
Before you begin, ensure you have the following installed:
- Node.js 20.19.0+ (use nvm or check
.nvmrcfile) - Yarn 3.6.1+ (will be installed automatically via Corepack)
- React Native development environment:
- For iOS: Xcode 16.1+, CocoaPods, and iOS Simulator
- For Android: Android Studio, Android SDK, and Android Emulator
- Watchman (recommended for file watching)
- Git
- Homebrew (macOS only, for installing rbenv and other dependencies)
For detailed React Native environment setup, see the React Native Environment Setup guide.
git clone https://github.com/SiftScience/sift-react-native.git
cd sift-react-nativeThe project uses Yarn 3.6.1 with workspaces. Dependencies will be installed automatically:
# Install all dependencies (root + example app)
yarn installThis will:
- Install root project dependencies
- Install example app dependencies
- Link the workspace packages
Build the TypeScript source code and generate type definitions:
# Build the library
yarn prepare
# or
npx react-native-builder-bob buildThis creates the lib/ directory with compiled JavaScript and TypeScript definitions.
If you don't have a Ruby version manager installed, install rbenv:
# Install rbenv using Homebrew
brew install rbenv
# Initialize rbenv in your shell
rbenv init
# Install Ruby (check .ruby-version file for required version)
rbenv installAfter installation, restart your terminal or run source ~/.zshrc (or ~/.bash_profile for bash).
cd ios
bundle install # Install Ruby dependencies including CocoaPods
bundle exec pod install
cd ..Make sure you have an iOS Simulator available. You can list available simulators:
xcrun simctl list devicesEnsure your Android SDK is properly configured. The example app will use the SDK path from your environment or ANDROID_HOME variable.
If needed, create android/local.properties:
sdk.dir=/path/to/your/android/sdkReplace /path/to/your/android/sdk with your actual Android SDK path:
- macOS: typically
~/Library/Android/sdk - Windows: typically
%LOCALAPPDATA%\Android\Sdk - Linux: typically
~/Android/Sdk
Start an Android emulator or connect a physical device:
# List available emulators
emulator -list-avds
# Start an emulator (replace with your AVD name)
emulator -avd YourAVDNameIn the example directory, start the Metro bundler:
# Using npm
npm start
# OR using Yarn
yarn start
# OR from root directory
yarn start:exampleKeep this terminal running.
In a new terminal:
# From example directory
yarn ios
# OR from root directory
yarn ios:exampleIn a new terminal:
# From example directory
yarn android
# OR from root directory
yarn android:exampleIf everything is set up correctly, you should see the app running in the Android Emulator, iOS Simulator, or your connected device.
Once the app launches:
-
The example app displays a form with fields for:
- Account ID: Your Sift account ID
- Beacon Key: Your Sift beacon key
- User ID: A test user identifier
- Server URL Format: The Sift API endpoint URL
-
Fill in your Sift credentials and tap "UPLOAD" to test the integration.
-
The app will initialize the Sift SDK and upload device data.
Open App.tsx in your text editor and make changes. The app will automatically reload thanks to Fast Refresh.
To manually reload:
- Android: Press R twice or Ctrl + M (Windows/Linux) / Cmd ⌘ + M (macOS) to open Dev Menu
- iOS: Press R in iOS Simulator
If you make changes to the SDK source code in the parent directory:
-
Rebuild the library:
cd .. yarn prepare cd example
-
Restart Metro bundler with cache reset:
yarn start --reset-cache
From the root directory:
# Run all tests
yarn test
# Run tests in watch mode
yarn test --watch# Lint the codebase
yarn lint# Type check TypeScript files
yarn typecheck# Clean all build artifacts
yarn cleanIf you encounter module resolution errors:
# Clear Metro cache
yarn start --reset-cache# Clean and reinstall pods
cd ios
rm -rf Pods Podfile.lock
bundle exec pod install
cd ..If you still have issues, try cleaning the Xcode build folder:
- Open the project in Xcode
- Go to Product > Clean Build Folder (Shift + Cmd + K)
# Clean Android build
cd android
./gradlew clean
cd ..If you encounter Gradle issues:
# Stop Gradle daemon
cd android
./gradlew --stop
cd ..If you encounter workspace linking issues:
# From root directory
rm -rf node_modules example/node_modules
yarn installIssue: "Command not found" errors
- Make sure you've run
yarn installin the root directory - Ensure Corepack is enabled:
corepack enable
Issue: Module not found errors
- Rebuild the library:
yarn preparefrom root directory - Clear Metro cache:
yarn start --reset-cache
Issue: Native module errors
- iOS: Reinstall pods (see iOS Build Issues above)
- Android: Clean and rebuild (see Android Build Issues above)
For more troubleshooting help, see the React Native Troubleshooting guide.
example/
├── src/ # Example app source code
│ └── App.tsx # Main app component
├── ios/ # iOS native app
│ ├── Podfile # CocoaPods dependencies
│ └── SiftReactNativeExample.xcworkspace
├── android/ # Android native app
│ ├── app/
│ └── build.gradle
├── package.json # Example app dependencies
└── README.md # This file
To learn more about React Native and Sift, check out these resources:
- Sift Documentation: Sift Developer Docs
- React Native: React Native Website
- React Native Basics: Learn the Basics
- Main SDK Documentation: See ../README.md for SDK usage and API reference