> For the complete documentation index, see [llms.txt](https://pub-star.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pub-star.gitbook.io/docs/1.6.0/ios-sdk/mediation-admob.md).

# AdMob Mediation

This guide explains how to connect **PubStar** to **Google AdMob Mediation** on iOS using custom events.

> **AdMob must already be integrated in your iOS app**
>
> PubStar runs inside AdMob mediation waterfall. Finish base AdMob setup first (Google Mobile Ads SDK, App ID, ad units, test ads), then add PubStar SDK and adapter.
>
> **Recommended guides:**
>
> * [AdMob iOS quick start](https://developers.google.com/admob/ios/quick-start)
> * [AdMob mediation overview (iOS)](https://developers.google.com/admob/ios/mediation)
> * [PubStar iOS SDK integration](/docs/1.6.0/ios-sdk/integration.md)

## Requirements

* iOS 13.0+
* Xcode 15+ recommended
* AdMob account and working GMA SDK integration on iOS
* PubStar App ID from [PubStar Dashboard](https://pubstar.io/)
* PubStar placement keys per ad format

## Installation (CocoaPods)

### Podfile

```ruby
platform :ios, '13.0'

target 'YourAppTarget' do
  use_frameworks! :linkage => :static

  pod 'Pubstar', '~> 1.6.0'
  pod 'PubStarMediationAdmobAdapter', '~> 1.6.0'
end
```

Run `pod install`, then open `.xcworkspace`.

## Configuration

### 1. Add PubStar App ID to Info.plist

Please refer to the [Info.plist Configuration Guide](/docs/1.6.0/ios-sdk/integration.md#1-update-your-infoplist) to set up your PubStar App ID.

### 2. Consent (GDPR / UMP) — gather before init

For users in regions that require consent (EEA, UK, etc.), you must gather consent **before** initializing the SDK. PubStar uses Google's **User Messaging Platform (UMP)**. If consent has not been resolved, `initAd()` does not start and reports `ErrorCode.CONSENT_NOT_SETTING` (`-10`) in `onError`.

Correct order: `gatherConsent(...)` → then `initAd()` inside the completion callback.

```swift
import Pubstar

PubStarAdManager.gatherConsent(
    from: self, // UIViewController
    listener: ConsentGatheringCompleteHandler(onComplete: { error in
        // error is nil on success; the consent form (if required) has already been shown.
        // Initialize PubStar only after consent has been gathered.
        PubStarAdManager.getInstance()
            .setInitAdListener(InitAdListenerHandler(
                onDone: {
                    // ready to load and show ads
                },
                onError: { code in
                    // init error
                }
            ))
            .initAd()
    })
)
```

* `gatherConsent(...)` requests the latest consent info and automatically shows the consent form if required, then calls the completion listener.
* Call this from a `UIViewController` (the consent form is a UI dialog), typically on your splash/loading screen.
* The completion's `Error?` is the UMP form error (`nil` on success). UMP ships with the Google Mobile Ads SDK that PubStar already uses (declared via the `GoogleUserMessagingPlatform` dependency).
* To exercise the form on a test device, enable debug mode before gathering:

  ```swift
  GoogleMobileAdsConsentManager.shared.setDebug(
      enabled: true,
      geography: .EEA,
      testDeviceIdentifiers: ["<YOUR_TEST_DEVICE_ID>"]
  )
  ```
* Outside consent-required regions, `GoogleMobileAdsConsentManager.shared.canRequestAds()` is already `true`, so you can call `initAd()` directly — but routing every launch through `gatherConsent(...)` first is safe everywhere and avoids `CONSENT_NOT_SETTING`.

***

## AdMob Mediation Console Setup (iOS)

1. Create mediation group per format.
2. Choose platform **iOS**.
3. Add PubStar as **Custom Event**.
4. Use class name and parameter below.

### Mediation group setup

#### Step 1: Create Mediation Group

In AdMob, go to `Mediation` and click `Create Mediation Group`:

<figure><img src="https://979046149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FySAgekVO4tt5BNM5yESo%2Fuploads%2Fgit-blob-ea3de284e1c50ab0fb113426baa0430848a18057%2Fstep1-create-mediation-group.png?alt=media" alt="Create Mediation Group"><figcaption><p>Create Mediation Group.</p></figcaption></figure>

Select ad format, choose **iOS** platform, then continue and set group properties.

<figure><img src="https://979046149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FySAgekVO4tt5BNM5yESo%2Fuploads%2Fgit-blob-eb39aafa89823c443502e0496b5683e2cfddc71d%2Fstep1-mediation-group-properties.png?alt=media" alt="Mediation group properties"><figcaption><p>Mediation group properties.</p></figcaption></figure>

Click **ADD AD UNITS** and attach iOS ad units:

<figure><img src="https://979046149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FySAgekVO4tt5BNM5yESo%2Fuploads%2Fgit-blob-f95edb21ad628a04448cf2b5e2617aba57b5ab5d%2Fstep1-add-ad-units.png?alt=media" alt="Add ad units"><figcaption><p>Add ad units.</p></figcaption></figure>

#### Step 2: Add Custom Events

Add one or more PubStar custom events (for example by eCPM tier):

<figure><img src="https://979046149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FySAgekVO4tt5BNM5yESo%2Fuploads%2Fgit-blob-3a0a7dc8922bc390a0c5a512b83501e1f600f7a9%2Fstep2-add-ad-sources.png?alt=media" alt="Add ad sources"><figcaption><p>Add ad sources.</p></figcaption></figure>

Click **ADD CUSTOM EVENT**, set label and eCPM:

<figure><img src="https://979046149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FySAgekVO4tt5BNM5yESo%2Fuploads%2Fgit-blob-3b5606d0ba287ec1b1f064c242d72aec76b080bf%2Fstep2-custom-event-label-ecpm.png?alt=media" alt="Custom event label and eCPM"><figcaption><p>Custom event label and eCPM.</p></figcaption></figure>

### Custom event values

* **Class Name**

  ```
  PubStarGADMediationAdapter
  ```

  If your project requires module-qualified Swift name, use: `PubStarMediationAdmobAdapter.PubStarGADMediationAdapter`.
* **Parameter** — PubStar placement key (plain text), for example: `1233/99228313580` (banner)

<figure><img src="https://979046149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FySAgekVO4tt5BNM5yESo%2Fuploads%2Fgit-blob-ba597ebbd2bbac2fa2bc15c95ee55ca14c370a40%2Fstep2-custom-event-class-parameter.png?alt=media" alt="Class Name and Parameter"><figcaption><p>Class Name and Parameter.</p></figcaption></figure>

<figure><img src="https://979046149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FySAgekVO4tt5BNM5yESo%2Fuploads%2Fgit-blob-489efd3a7e941214b42f4cebef17cb4147011f32%2Fstep2-custom-events-list.png?alt=media" alt="Custom events list"><figcaption><p>Custom events list.</p></figcaption></figure>

### Supported ad formats

| AdMob format | Test placement key |
| ------------ | ------------------ |
| Banner       | `1233/99228313580` |
| Interstitial | `1233/99228313582` |
| Rewarded     | `1233/99228313584` |
| App Open     | `1233/99228313583` |

These test keys pair with `pub-app-id-1233`. Use production keys before release. **Native Advanced** is not listed: native mediation only works with a **real native placement key** from your PubStar Dashboard (test native keys are not supported).

### Validation checklist

* `Pubstar` and `PubStarMediationAdmobAdapter` pods are installed.
* `io.pubstar.key` exists in app `Info.plist`.
* AdMob mediation group platform is iOS.
* Class Name is correct and Parameter is not empty.
* Placement key format matches the ad format.

### Troubleshooting

**No callback to custom event:** verify waterfall order/eCPM and class name spelling.

**No fill:** verify placement key + format mapping with PubStar support.

**Native Advanced not loading / no fill** — PubStar native in AdMob mediation **only works with a real native placement key** from your PubStar Dashboard for this app. Do **not** use shared test native keys (for example `1233/99228313581` with `pub-app-id-1233`); they will not serve. Create or copy your production native placement key, set it as the custom event **Parameter**, and confirm the mediation group format is Native Advanced on iOS.

**Recent console changes:** wait 10–15 minutes and relaunch app before retest.
