GrowthRailDocs

Installation

bash
npm install @growth-rail/react-native @growth-rail/core
# or
yarn add @growth-rail/react-native @growth-rail/core
Version: Current stable release is @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.

App.tsx
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>
  );
}
PropTypeRequiredDescription
projectSecretKeystringYesYour project secret (sk_...).
userIdstring?NoIf provided, automatically calls initAppUser(userId).
debugboolean?NoEnable 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.

tsx
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

MethodTypeDescription
initAppUser(userId)Promise<AppUserType>Register a user and get their referral code/link.
showReferralDashboard(options?)voidShow the referral sharing UI.
hideReferralDashboard()voidDismiss the referral sharing UI.
showFloatingButton(options)voidShow the floating trigger button.
hideFloatingButton()voidRemove 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

PropertyTypeDescription
isInitializedbooleanWhether the SDK has completed initialization.
isUserReadybooleanWhether initAppUser() has completed.
isLoadingbooleanWhether an async operation is in progress.
isDebugEnabledbooleanWhether debug mode is active.
errorError | nullLast 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.

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

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

tsx
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:

  1. The user is redirected to the App Store / Play Store
  2. After installing, the user opens the app
  3. The SDK uses probabilistic device fingerprint matching to attribute the install
  4. 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:

tsx
// 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]);
}
Install referrer tracking: The SDK automatically uses the Android Install Referrer API and iOS clipboard-based attribution when available. No extra configuration needed.

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.

KeyPurpose
gr_ref_codeReferral code from the deep link
gr_tracked_referralTracking 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

App.tsx
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

FeatureReact (Web)React Native
StorageCookies (30-day expiry)AsyncStorage (persistent)
Deep linkingURL query parameter detectionUniversal links, install referrer, fingerprint matching
UI renderingShadow DOM injectionNative React Native components
ThemeCSS-based themingAuto 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

Troubleshooting