Skip to content

React Native SDK

Native ads, interstitial ads, and rewarded ads for React Native apps.

New to Simula?

Head to Getting Started first to create your publisher account, get your API key, and set up your first ad unit. Then come back here to integrate the SDK.

Installation

bash
npm install @simula/ads-react-native
# or
yarn add @simula/ads-react-native

Requires React >= 16.8.0 and React Native >= 0.60.0.

Provider Setup

Wrap your application with SimulaProvider to initialize the SDK:

jsx
import { SimulaProvider } from '@simula/ads-react-native';

function App() {
  return (
    <SimulaProvider
      apiKey="YOUR_API_KEY"
      primaryUserID="hashed_user_id"
      devMode={false}
    >
      {/* Your application components */}
    </SimulaProvider>
  );
}

Provider Props

PropTypeDefaultDescription
apiKeystringrequiredYour Simula API key
devModebooleanfalseEnables development mode — always fills, no billing, excluded from ML targeting, and enables debug console logging. Set to false before shipping
primaryUserIDstringHashed user ID for better ad targeting
privacySimulaPrivacyConfigGranular consent configuration. See Privacy
telemetryEnabledbooleantrueEnables SDK performance and error telemetry
adContextSimulaAdContextContextual targeting signals attached to every native ad request
initializeOnMountbooleantrueInitializes the native SDK and opens a session as soon as the provider mounts. Set to false to control timing with SimulaAds.initialize()

Imperative Initialization

For cases where the provider pattern doesn't fit:

jsx
import { SimulaAds } from '@simula/ads-react-native';

await SimulaAds.initialize({
  apiKey: 'YOUR_API_KEY',
  devMode: false,
  primaryUserID: 'hashed_user_id',
});

const isReady = await SimulaAds.isInitialized();

Updating the User ID

Update the primary user identifier at runtime after login or logout:

jsx
SimulaAds.updatePrimaryUserID('new_hashed_id'); // after login
SimulaAds.updatePrimaryUserID(null);            // after logout

Dev mode

Set devMode to true during development. Every ad request returns a test ad (always fills), no impressions are billed, test traffic is excluded from Simula's ML targeting models, and debug logs are printed to the console. Set to false before releasing to production.

Components

ComponentDescriptionGuide
NativeAdInline native ad card for feedsNativeAd
SimulaInterstitialAdFull-screen interstitial ad (imperative)InterstitialAd
useInterstitialAdInterstitial ad hookInterstitialAd
SimulaRewardedAdRewarded ad with play-to-earn gate (imperative)RewardedAd
useRewardedAdRewarded ad hookRewardedAd
CharacterSelectorPre-built character discovery UICharacterSelector

Privacy

The SDK automatically reads IAB CMP consent values from device storage — no setup is required for most apps. This entire section is optional. Only configure privacy manually if you need to override the auto-read values or manage consent outside a CMP.

Control consent at runtime with the SimulaPrivacy API. Explicit configuration takes precedence.

jsx
import { SimulaPrivacy } from '@simula/ads-react-native';

// Replace all consent signals
SimulaPrivacy.apply({
  tcString: '...',
  gdprApplies: true,
  coppaApplies: false,
  enableAdvertisingId: true,
});

// Merge a partial update
SimulaPrivacy.update({ tcString: '...' });

// Clear specific signals (fall back to auto-read IAB values)
SimulaPrivacy.clearConsent({ tcString: true, gdprApplies: true });

// iOS: Prompt for App Tracking Transparency
const status = await SimulaPrivacy.requestTrackingAuthorization();
// "authorized" | "denied" | "restricted" | "not_determined" (iOS)
// "unavailable" (Android)

SimulaPrivacyConfig

FieldTypeDefaultDescription
tcStringstringIAB TCF v2.2 consent string
uspStringstringIAB US Privacy (CCPA), e.g. "1YNN"
gppStringstringIAB Global Privacy Platform string
gppSidstringGPP section IDs, comma-separated
gdprAppliesbooleanWhether GDPR applies
tcfPurpose1ConsentbooleanExplicit TCF Purpose 1 (storage) consent
coppaAppliesbooleanfalseChild-directed treatment (COPPA)
enableAdvertisingIdbooleanfalseOpt-in for IDFA/GAID collection

Ad Context

Pass contextual targeting signals via adContext to improve native ad relevance. The more context you provide, the better the ad targeting.

SimulaAdContext

FieldTypeDescription
searchTermstringCurrent search or query term in the feed
tagsstring[]Content tags (backend keeps at most 10)
categorystringFeed category
titlestringTitle of the surrounding feed item
descriptionstringDescription of the surrounding feed item
userProfilestringOpaque user-profile signal
userEmailstringUser email, if available
customContextRecord<string, unknown>Arbitrary JSON key-values
nsfwbooleanWhether surrounding content is NSFW. Default false

All fields are optional. The customContext field accepts nested objects, arrays, strings, numbers, and booleans — use it for platform-specific data like recently interacted characters.

jsx
import { SimulaProvider } from '@simula/ads-react-native';

function App({ user }) {
  const adContext = {
    category: 'ai-chat',
    customContext: {
      recentCharacters: [
        { id: 'reze-01', name: 'Reze', description: 'The Bomb Devil from Chainsaw Man' },
        { id: 'power-02', name: 'Power', description: 'The Blood Fiend from Chainsaw Man' },
      ],
      preferredGenre: 'anime',
    },
  };

  return (
    <SimulaProvider
      apiKey="YOUR_API_KEY"
      primaryUserID={hashedUserId}
      adContext={adContext}
    >
      <MainScreen />
    </SimulaProvider>
  );
}

Update context at runtime when the user navigates to a new feed or chat:

jsx
import { SimulaAds } from '@simula/ads-react-native';

SimulaAds.updateContext({
  category: 'ai-chat',
  customContext: {
    recentCharacters: [
      { id: 'reze-01', name: 'Reze', description: 'The Bomb Devil from Chainsaw Man' },
    ],
  },
});

// Clear context
SimulaAds.updateContext(null);

updateContext is a full replacement

Calling updateContext replaces the entire context — it does not merge with the previous value. Omitted fields are removed. Pass the complete context every time.

Error Handling

All ad errors are reported as a SimulaAdError object:

typescript
interface SimulaAdError {
  code: string;           // stable error code from the table below
  message: string;        // human-readable description
  retryInSeconds?: number; // seconds until load() unblocks (duplicate_request only)
}

Error Codes

CodeDescription
not_initializedSDK not initialized
no_sessionSession creation failed
no_fillNo ad available for this placement
not_readyshow() called before ad finished loading
staleLoaded ad expired (1-hour limit)
duplicate_requestload() called while a request is in flight. retryInSeconds field indicates when to retry
already_showingshow() called while an ad is already on screen
no_presentation_contextNo Activity/window available to present the ad
networkNetwork connectivity error
ad_unit_not_foundAd unit ID is not registered for this app (check the publisher dashboard)
unsupported_platformPlatform not supported (iOS only)
verification_failedReward verification failed (rewarded ads only)

AdValue

Revenue data surfaced on PAID events and NativeAd.onPaid. All figures are serve-time estimates derived from the backend floor CPM.

typescript
interface AdValue {
  valueMicros: number;
  currencyCode: string;
  precisionType: AdValuePrecision;
  expectedCpm: number;
  expectedRevenue: number;
}
FieldTypeDescription
valueMicrosnumberPer-impression revenue in micros (5000 = $0.005)
currencyCodestringISO-4217 currency code, e.g. "USD"
precisionTypeAdValuePrecisionEstimate quality — currently always "ESTIMATED"
expectedCpmnumberEstimated CPM (valueMicros / 1_000)
expectedRevenuenumberEstimated per-impression revenue (valueMicros / 1_000_000)