# @poponl/react-native-ads

pop.onl ad mediation for React Native and Expo. Rewarded and interstitial ads from the ad networks' own SDKs, in the
waterfall order set on [pop.onl](https://pop.onl). Wraps the pop.onl Android and iOS SDKs.

## Expo

```bash
npx expo install @poponl/react-native-ads
```

`app.json`:

```json
{
  "expo": {
    "plugins": [
      ["@poponl/react-native-ads", {
        "networks": ["admob", "unityads", "pangle"],
        "admobAndroidAppId": "ca-app-pub-XXXXXXXX~XXXXXXXX",
        "admobIosAppId": "ca-app-pub-XXXXXXXX~XXXXXXXX"
      }]
    ]
  }
}
```

Then `npx expo prebuild` (or an EAS build). It does not run in Expo Go.

## Bare React Native

```bash
npm install @poponl/react-native-ads
```

- Android, `android/gradle.properties`: `poponl.networks=admob,unityads,pangle`, and add `maven { url "https://maven.pop.onl" }`
  (plus the network repositories listed in the Android SDK README) to the project repositories.
- iOS, `ios/Podfile`: `pod 'PopOnlAds/AdMob'` and one line per network, then `pod install`.

## Use

```js
import PopOnlAds from '@poponl/react-native-ads';

PopOnlAds.setConsent(true);                       // from your consent prompt
await PopOnlAds.initialize('po_app_XXXXXXXXXXXXXXXXXXXX');

if (await PopOnlAds.isRewardedReady('revive')) {
  const earned = await PopOnlAds.showRewarded('revive');
  if (earned) giveReward();
}
await PopOnlAds.showInterstitial('level_end');
```

`initialize` resolves once a config is in use; on a first run with no network it waits until one arrives.

Networks: Android has all 17 (admob, unityads, pangle, liftoff, mintegral, inmobi, chartboost, dtexchange, yandex,
bigo, mytarget, smaato, ogury, startio, line, superawesome, ysonetwork). iOS has admob, unityads, pangle, liftoff,
inmobi so far.
