# pop.onl Ads for Unity

Free ad mediation. One app key from pop.onl, a waterfall you edit on the web, and the networks' own SDKs doing the ads.

## Install

1. Install the ad network SDKs you use. pop.onl is the mediation, so add networks, not another mediation
   (remove LevelPlay or MAX if you switch).
   - AdMob: Google Mobile Ads Unity plugin 9.0+ (`com.google.ads.mobile` or the .unitypackage). Put your AdMob app id
     in its settings (Assets > Google Mobile Ads > Settings).
   - Unity Ads: `com.unity.ads` 4.x (Package Manager, "Advertisement Legacy").
2. Add this package. Package Manager > + > Add package from git URL:
   `https://github.com/poponl/sdk.git?path=unity/com.poponl.sdk`
   or from disk (`Packages/manifest.json`):
   `"com.poponl.sdk": "file:../path/to/com.poponl.sdk"`
3. Adapters switch on by themselves when their network SDK is present (the editor adds `POPONL_ADMOB`,
   `POPONL_UNITYADS` defines).

### Android: every network

On Android the package can also run pop.onl's native adapters, so any of the 17 networks works without a Unity
plugin from that network: AdMob, Unity Ads, Pangle, Liftoff, Mintegral, InMobi, Chartboost, DT Exchange, Yandex,
BIGO Ads, myTarget, Smaato, Ogury, Start.io, LINE (FiveAd), SuperAwesome, YSO Network.

1. Install the External Dependency Manager (`com.google.external-dependency-manager`; the AdMob plugin already has it).
2. Menu pop.onl > Android networks: tick the networks, Save. This writes
   `Assets/PopOnl/Editor/PopOnlAndroidDependencies.xml`.
3. Assets > External Dependency Manager > Android Resolver > Resolve.

If a network's Unity plugin is in the project (AdMob, Unity Ads), leave that network off in the list: the C# adapter
is used and the native one would only add a second copy of the SDK.

## Use

```csharp
using PopOnl;

void Start()
{
    PopOnlAds.SetConsent(true);                      // from your consent prompt
    PopOnlAds.Initialize("po_app_XXXXXXXXXXXXXXXXXXXX");
}

void OnRewardButton()
{
    if (!PopOnlAds.IsRewardedReady("revive")) return;
    PopOnlAds.ShowRewarded("revive", earned =>
    {
        if (earned) GiveReward();
    });
}

void OnLevelEnd() => PopOnlAds.ShowInterstitial("level_end");
```

- `placement` is matched to the ad unit that lists it on pop.onl; otherwise the first unit of that format is used.
- Callbacks run on Unity's main thread.
- Options: `new PopOnlOptions { Verbose = true }` logs each waterfall step; `ApiBaseUrl` points to another server.

## How it works

- `GET /sdk/v1/config` (header `X-PO-App-Key`) returns network ids and the waterfall for the device's country. It is
  saved and refreshed every 10 minutes, so ads keep working offline with the last copy.
- Each ad unit keeps one ad loaded: lines are tried in order and lines priced under the floor are skipped. When all
  fail it retries after 30 s, doubling to 5 min.
- Events (request, fill, no_fill, show, impression with revenue, click, reward, close) go to `POST /sdk/v1/events` in
  batches. The device id is a random id made on first run, not an advertising id.

## Not yet

Banners, server-side reward checks (S2S), native adapters on iOS.
