React Native SDK
The @growth-rail/react-native package provides native-optimized hooks and components for React Native applications, with support for deep linking, install referrer tracking, and native UI components.
Installation
npm install @growth-rail/react-native @growth-rail/core
# or
yarn add @growth-rail/react-native @growth-rail/core@growth-rail/react-native@2.0.6. Requires React Native 0.72+ and @growth-rail/core as a peer dependency.GrowthRailProvider
Wrap your app root with GrowthRailProvider. This initializes the SDK and provides context to all child components.
import { GrowthRailProvider } from '@growth-rail/react-native';
export default function App() {
return (
<GrowthRailProvider
projectSecretKey="sk_your_project_secret"
userId={userId} // optional: auto-init user
debug={__DEV__} // verbose logging in dev
>
<Navigation />
</GrowthRailProvider>
);
}| Prop | Type | Required | Description |
|---|---|---|---|
projectSecretKey | string | Yes | Your project secret (sk_...). |
userId | string? | No | If provided, automatically calls initAppUser(userId). |
debug | boolean? | No | Enable verbose console logging. |
useGrowthRail Hook
The React Native hook provides all the same methods as the React web hook, plus additional mobile-specific methods and state.
import { useGrowthRail } from '@growth-rail/react-native';
function MyScreen() {
const {
// Methods
initAppUser,
showReferralDashboard,
hideReferralDashboard,
showFloatingButton,
hideFloatingButton,
getReferralTrackingId,
getAttributionToken,
getReferralLink,
// State
isInitialized,
isUserReady,
isLoading,
isDebugEnabled,
error,
} = useGrowthRail();
// ...
}Methods
| Method | Type | Description |
|---|---|---|
initAppUser(userId) | Promise<AppUserType> | Register a user and get their referral code/link. |
showReferralDashboard(options?) | void | Show the referral sharing UI. |
hideReferralDashboard() | void | Dismiss the referral sharing UI. |
showFloatingButton(options) | void | Show the floating trigger button. |
hideFloatingButton() | void | Remove the floating trigger button. |
getReferralTrackingId() | Promise<string | null> | Get the stored referral tracking ID (from async storage). |
getAttributionToken() | Promise<string | null> | Get the opaque token for gr_attribution purchase metadata. |
getReferralLink() | Promise<string | undefined> | Get the current user's referral link. |
State Properties
| Property | Type | Description |
|---|---|---|
isInitialized | boolean | Whether the SDK has completed initialization. |
isUserReady | boolean | Whether initAppUser() has completed. |
isLoading | boolean | Whether an async operation is in progress. |
isDebugEnabled | boolean | Whether debug mode is active. |
error | Error | null | Last error that occurred. |
Native UI Components
The React Native SDK includes pre-built UI components optimized for mobile:
ReferralDashboard
A full-screen or inline referral sharing component with copy-to-clipboard and social sharing.
import { ReferralDashboard } from '@growth-rail/react-native';
function ReferralsScreen() {
return (
<View style={{ flex: 1 }}>
<ReferralDashboard
title="Invite Friends"
onLinkCopied={() => Alert.alert('Link copied!')}
/>
</View>
);
}TriggerButton
A floating action button that opens the referral dashboard when tapped.
import { TriggerButton } from '@growth-rail/react-native';
function HomeScreen() {
return (
<View style={{ flex: 1 }}>
{/* Your screen content */}
<TriggerButton position="bottom-right" />
</View>
);
}Banner
A promotional banner shown to users who arrive via a referral link.
import { Banner } from '@growth-rail/react-native';
function SignupScreen() {
return (
<View style={{ flex: 1 }}>
<Banner position="center-top" />
{/* Your signup form */}
</View>
);
}Deep Linking
The React Native SDK supports deferred deep linking for attributing installs to referrals. When a user clicks a referral link but doesn't have the app installed:
- The user is redirected to the App Store / Play Store
- After installing, the user opens the app
- The SDK uses probabilistic device fingerprint matching to attribute the install
- The referral is tracked automatically
URL Parameter Detection
For direct deep links (user already has the app), the SDK detects referral parameters from the incoming URL:
// The SDK automatically handles deep link URLs like:
// yourapp://open?referralCode=ABC123&rewardEventName=user_signup
// For manual handling with React Navigation:
import { useGrowthRail } from '@growth-rail/react-native';
function DeepLinkHandler({ url }) {
const { trackReferral } = useGrowthRail();
useEffect(() => {
if (url) {
const params = new URLSearchParams(url.split('?')[1]);
const code = params.get('referralCode');
if (code) {
trackReferral(code, params.get('rewardEventName'));
}
}
}, [url]);
}Storage
Unlike the web SDK which uses cookies, the React Native SDK uses AsyncStorage (or your configured storage adapter) to persist referral tracking data across app sessions.
| Key | Purpose |
|---|---|
gr_ref_code | Referral code from the deep link |
gr_tracked_referral | Tracking ID after referral is recorded |
Theme Support
The React Native SDK automatically detects the device's light/dark mode preference and adjusts the built-in UI components accordingly. You can also override the theme via the campaign configuration in the dashboard.
Complete Example
import React, { useEffect } from 'react';
import { View, Button, Alert } from 'react-native';
import { GrowthRailProvider, useGrowthRail } from '@growth-rail/react-native';
// 1. Wrap your app
export default function App() {
return (
<GrowthRailProvider
projectSecretKey="sk_your_project_secret"
debug={__DEV__}
>
<MainScreen />
</GrowthRailProvider>
);
}
// 2. Use the hook in your screens
function MainScreen() {
const {
initAppUser,
showReferralDashboard,
isUserReady,
isLoading,
} = useGrowthRail();
// Register user after auth
useEffect(() => {
initAppUser('user_123');
}, []);
// Show referral UI
const handleInvite = () => {
showReferralDashboard({
title: 'Invite Friends',
description: 'Share your link and earn 500 credits!',
});
};
return (
<View style={{ flex: 1, justifyContent: 'center', padding: 20 }}>
<Button
title="Invite Friends"
onPress={handleInvite}
disabled={!isUserReady}
/>
<Button
title="Track Signup Reward"
onPress={handleSignupComplete}
disabled={isLoading}
/>
</View>
);
}Differences from Web SDK
| Feature | React (Web) | React Native |
|---|---|---|
| Storage | Cookies (30-day expiry) | AsyncStorage (persistent) |
| Deep linking | URL query parameter detection | Universal links, install referrer, fingerprint matching |
| UI rendering | Shadow DOM injection | Native React Native components |
| Theme | CSS-based theming | Auto light/dark mode detection |
hideReferralDashboard() | Not available (modal auto-closes) | Available for programmatic dismissal |
getReferralTrackingId() | Not exposed (cookie-based) | Async method to read from storage |