Launch offer for the first 500 accounts: $10K MTR free for 24 months + $100 credit →
    .io

    React Native SDK Guide

    ⚛️ React Native — native paywalls with a thin JS bridge

    The React Native SDK is a thin bridge: the JS layer delegates to the native BillDog iOS and Android SDKs rather than reimplementing billing logic, so paywalls and purchases behave identically to the native guides.

    View on npmnpm • iOS 15+ • Android 21+ • Autolinking

    1. Install

    Terminal
    npm install @billdog.io/react-native@^1.2.0-beta.1 \
      @react-native-async-storage/async-storage@^1.19.0 \
      react-native-fs@^2.20.0 \
      react-native-svg@^13.0.0 \
      react-native-webview@^13.0.0

    The four packages after the SDK are its peer dependencies. They contain native code, and React Native autolinks only the packages listed in your app’s own package.json — not the dependencies of the packages you install — so they are installed by name, within the ranges the SDK declares. With them in place, no manual native registration is needed. On iOS, install the pods:

    Terminal
    cd ios && pod install

    The local-notification helpers (NotificationScheduler, useDeviceToken, the notification-permission functions) use react-native-push-notification and, on iOS, @react-native-community/push-notification-ios. They are optional peers: install them only if you call those helpers. Without them the app still builds and runs; the helpers fail with a BillDogApiError whose code is NATIVE_MODULE_UNAVAILABLE (their promises reject, and useDeviceToken passes it to onError), and isNotificationSupported() returns false.

    2. Configure

    Configure once, before you render. Note the named import — the package has no default export — and that configure is on BillDogConfiguration, not on BillDog.

    index.js / App.tsx
    import { BillDogConfiguration } from '@billdog.io/react-native';
    
    BillDogConfiguration.configure({
      apiKey: 'YOUR_API_KEY_HERE', // starts with bd_public_test_ or bd_public_live_
    });

    That also starts analytics: the native SDK registers its analytics module when it is configured, so there is no separate initialize step.

    TypeScript
    import { BillDog } from '@billdog.io/react-native';
    
    BillDog.isConfigured(); // -> boolean: did the SDK pick up your key?

    3. Manage customer identity

    Link anonymous sessions to your accounts so entitlements follow the user across devices.

    TypeScript
    import { BillDog } from '@billdog.io/react-native';
    
    // Link this device to your account id
    await BillDog.logIn('user_uuid_123');
    
    // Or identify with attributes for segmentation
    await BillDog.identify('user_uuid_123', { plan: 'trial' });
    
    BillDog.isAnonymous();   // -> boolean
    BillDog.getAppUserId();  // -> string | null
    
    // On logout: continue as a NEW anonymous user (a fresh anonymous id)
    await BillDog.logOut();

    4. Present a paywall

    The recommended entry point is a placement: BillDog decides which paywall (if any) to show, applying your targeting and holdout rules.

    TypeScript
    import { BillDog } from '@billdog.io/react-native';
    
    const result = await BillDog.register('onboarding');
    // result.type: 'entitled' | 'purchased' | 'dismissed' | 'restored'
    //            | 'holdout' | 'withheld' | 'error'

    To render a specific paywall inline instead, use the PaywallView component:

    TSX
    import { PaywallView } from '@billdog.io/react-native';
    
    export function PremiumScreen() {
      return <PaywallView paywallIdentifier="premium_offer" />;
    }

    There is also a usePaywall hook for fetching configuration without rendering, plus useOfferings and usePlacement.

    5. Check entitlements

    Gate features on entitlements rather than on product ids.

    TypeScript
    import { BillDog } from '@billdog.io/react-native';
    
    // Asks the server; false on any error (fails closed)
    if (await BillDog.hasAccessForPlacement('premium_features')) {
      // unlock
    }
    
    // Or read the full customer record
    const info = await BillDog.getCustomerInfo();
    const hasPro = info?.entitlements.some(
      (e) => e.identifier === 'pro' && e.isActive
    );
    
    // Restore purchases (e.g. from a "Restore" button)
    await BillDog.restore();

    6. Track events

    Analytics lives on the AnalyticsManager singleton — BillDog itself has no track method. It is ready once configure() (section 2) has run.

    TypeScript
    import { AnalyticsManager } from '@billdog.io/react-native';
    
    const analytics = AnalyticsManager.getInstance();
    
    await analytics.track('app_opened', { source: 'cold_start' });
    await analytics.trackRevenue({ amount: 9.99, currency: 'USD' });

    7. Sign users in (BillDog Auth)

    Like the rest of the package, auth is a thin bridge. It could have been written in TypeScript — it is plain HTTPS — but then the refresh token would live in AsyncStorage, which is neither encrypted nor excluded from cloud backup. Delegating keeps it in the iOS Keychain and Android EncryptedSharedPreferences. The session token is never handed to JS at all: it lives ninety seconds and the native API clients already attach it.

    TypeScript
    import { BillDogAuth } from '@billdog.io/react-native';
    
    // False when the native module is not linked into the host app.
    if (!BillDogAuth.isAvailable) return;
    
    const restored = await BillDogAuth.restore();   // { signedIn: false } on first launch
    // signedIn: false + hasStoredSession: true → offline or a server error, still signed in
    
    const r = await BillDogAuth.attempt({
      identifier: 'ada@example.com',
      strategy: 'password',
      password,
    });
    
    // Check this BEFORE treating it as a sign-in: against an enrolled account a
    // correct password issues no session.
    if (r.mfaRequired) {
      await BillDogAuth.attempt({
        identifier: 'ada@example.com',
        strategy: 'totp',
        code,
        mfaToken: r.mfaToken,   // proves the first factor was accepted
      });
    }

    Passwordless, and phone numbers

    TypeScript
    // A RETURNING user gets a fresh code from requestCode. Without it a code could
    // only be obtained as a side effect of signing up.
    await BillDogAuth.requestCode({ identifier: '+15551234567', kind: 'phone' });
    
    await BillDogAuth.attempt({
      identifier: '+15551234567',
      kind: 'phone',          // REQUIRED — selects the identity row
      strategy: 'sms_code',
      code,
    });

    The rest of the surface

    isSignedIn(), signUp(...) (below), signOut('this' | 'others' | 'all'), passkeysAvailable(), registerPasskey(label?), signInWithPasskey(), and BillDogAuth.organizations — create, list, members, roles, invitations, domains.

    The token carries the user’s entitlements in the ent claim, capped at 64 with ent_truncated set past that — read Sessions & tokens before you treat ent as a complete list.

    Sign-up requirements, password reset and account deletion

    TypeScript
    // What the project requires before it accepts a sign-up
    const cfg = await BillDogAuth.config();  // { accessMode, botProtection, turnstileSiteKey, ... }
    
    await BillDogAuth.signUp({
      identifier: 'ada@example.com',
      password,
      invitationToken,   // required when cfg.accessMode is 'invite_only'
      captchaToken,      // required when cfg.botProtection is true (a Turnstile token)
    });
    
    // Password reset: send a code, then set the new password with it.
    // Pass the same kind to both calls for a phone number.
    await BillDogAuth.requestPasswordReset({ identifier: 'ada@example.com' });
    await BillDogAuth.resetPassword({ identifier: 'ada@example.com', code, newPassword });
    
    // Delete the signed-in user's own account. Rejects with code REAUTH_REQUIRED
    // when the sign-in is too old: sign the user in again, then retry.
    await BillDogAuth.deleteAccount();

    Next steps

    • Using Expo? See the Expo SDK guide — the config plugin wires the native project for you.
    • The bridge delegates to the native SDKs; for platform behaviour see the iOS and Android guides.
    • BillDog Auth — sign users in, and gate features on the token. Start at the quickstart.
    • SDK glossary — placements, offerings and entitlements explained.

    Was this page helpful?

    Or rate this page:

    We use cookies and process your data to provide our services. By continuing, you agree to our Terms and Privacy Policy.