# AdMob Mediation

## Introduction <a href="#hyprmxmobilesdkadmob-unity-adapteroverview-introduction" id="hyprmxmobilesdkadmob-unity-adapteroverview-introduction"></a>

The HyprMX Unity AdMob Adapter Plugin allows you to integrate HyprMX in your AdMob rewarded, interstitial, and banner/MREC waterfalls.

If you're upgrading from an older version, please refer to the [Upgrade Guide](#upgrading-to-6.4.2.0). If you're installing the plugin for the first time, please follow our [Setup Guide](#hyprmxmobilesdkadmob-unity-adapteroverview-integratinghyprmxinyourunityproject).

{% hint style="info" %}
This version supports Unity AdMob plugin 8.0.0 and above.
{% endhint %}

{% file src="/files/o7zpqvYlwjSSmmOkch3t" %}

## Upgrading to 6.4.6.0

{% hint style="warning" %}
`User ID` has been removed in HyprMX-AdMob 6.4.2.0+. Please follow the steps below to remove the configuration.
{% endhint %}

{% stepper %}
{% step %}
Remove references to `HyprMXAdapterConfiguration.SetUserId("custom user id");`
{% endstep %}
{% endstepper %}

## Integrating HyprMX in Your Unity Project <a href="#hyprmxmobilesdkadmob-unity-adapteroverview-integratinghyprmxinyourunityproject" id="hyprmxmobilesdkadmob-unity-adapteroverview-integratinghyprmxinyourunityproject"></a>

{% stepper %}
{% step %}
Download the HyprMX Unity [AdMob Adapter Plugin](#hyprmxmobilesdkadmob-unity-adapteroverview-introduction) above.
{% endstep %}

{% step %}
Open your existing application in the Unity IDE.
{% endstep %}

{% step %}
Choose **Assets > Import Package > Custom Package...** to bring up the File Explorer (Windows) or Finder (Mac).
{% endstep %}

{% step %}
Select the HyprMX Unity AdMob Adapter package, and the **Import Unity Package** dialog box displays all the items in the package pre-checked and ready to install.
{% endstep %}

{% step %}
Install the package.
{% endstep %}
{% endstepper %}

## Integrating HyprMX on the AdMob Dashboard Using Custom Events <a href="#hyprmxmobilesdkadmob-unity-adapteroverview-integratinghyprmxontheadmobdashboardusingcustomevents" id="hyprmxmobilesdkadmob-unity-adapteroverview-integratinghyprmxontheadmobdashboardusingcustomevents"></a>

{% stepper %}
{% step %}
Create your Mediation Group on the AdMob dashboard. If you are integrating Interstitial and Rewarded Video, follow these steps for both.
{% endstep %}

{% step %}
In the Ad Sources section, select `Add Custom Event`.
{% endstep %}

{% step %}
In the popup, enter `HyprMX` in the label field and set the default eCPM (e.g. $15.00).
{% endstep %}

{% step %}
Click 'Continue'.
{% endstep %}

{% step %}
Set the adapter Class Name:

| AdMob Ad Format                                                                    | iOS "Class Name"         | Android "Class Name"                             |
| ---------------------------------------------------------------------------------- | ------------------------ | ------------------------------------------------ |
| ​[Rewarded Ads (New API)](https://developers.google.com/admob/unity/rewarded-ads)​ | HYPRAdMobRewardedAdapter | com.hyprmx.android.HyprMXCustomEventRewarded     |
| ​[Interstitial](https://developers.google.com/admob/unity/interstitial)​           | HYPRAdMobVideoAdapter    | com.hyprmx.android.HyprMXCustomEventInterstitial |
| ​[Banner/MREC](https://developers.google.com/admob/unity/banner)​                  | HyprMXCustomEventBanner  | com.hyprmx.android.HyprMXCustomEventBanner       |
| {% endstep %}                                                                      |                          |                                                  |

{% step %}
In the parameter field, enter the distributor ID and placement name assigned to you by your HyprMX account manager.&#x20;

Please reach out to your account manager with what placements you'd like to use in your app and whether they will be rewarded or interstitial. The example below will assume that your account manager has created a "REWARDED" placement.

```
{ "distributorID": "YOUR_DISTRIBUTOR_ID", "placementName": "REWARDED"}
```

{% endstep %}

{% step %}
Click 'Done' and then 'Save'.
{% endstep %}
{% endstepper %}

## iOS Configuration <a href="#hyprmxmobilesdkadmob-unity-adapteroverview-iosconfiguration" id="hyprmxmobilesdkadmob-unity-adapteroverview-iosconfiguration"></a>

{% stepper %}
{% step %}
Configure your iOS Resolver settings to embed Dynamic Frameworks:

* Open Assets -> External Dependency Manager -> iOS Resolver -> Settings
* Enable "**Always add the main target to Podfile**"

<figure><img src="/files/0frHVLPIDldxgrBJlaR6" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}
If you prefer to enable ATS, uncheck the "Allow Downloads over HTTP" checkbox in Player Settings.&#x20;

<figure><img src="/files/utsgQVuBdnLovgPs9NKX" alt="" width="308"><figcaption></figcaption></figure>
{% endstep %}

{% step %}
When the checkbox is unchecked, add the following keys to the exported iOS project's Info.plist:

* NSAllowsArbitraryLoads
* NSAllowsArbitraryLoadsForMedia
* NSAllowsArbitraryLoadsInWebContent
  {% endstep %}
  {% endstepper %}

### Orientation

HyprMX recommends your app support all orientations globally to maximize ad fill, as HyprMX ads may be shown in any orientation, and our view controller needs your app to support that behavior. You can configure this by selecting all possible orientations in your project's Player Settings -> Resolution and Presentation.  For your iOS target, set your Default Orientation to `Auto Rotation` and select all orientation check boxes:

<figure><img src="/files/Jxd9GWUYqgCBIelxODC9" alt=""><figcaption></figcaption></figure>

*Please note, this setup does not require that your Game Scene's interface support all orientations. You just have to configure each of the supported orientations on the `Screen` object when your scene loads:*

```csharp
    public void Start()
    {
#if UNITY_IOS
    Screen.autorotateToPortrait = false;
    Screen.autorotateToPortraitUpsideDown = false;
    Screen.autorotateToLandscapeLeft = true;
    Screen.autorotateToLandscapeRight = true;
#endif
    }
```

### Configuring Privacy Controls  <a href="#hyprmxmobilesdkadmob-unity-adapteroverview-configuringprivacycontrols" id="hyprmxmobilesdkadmob-unity-adapteroverview-configuringprivacycontrols"></a>

iOS requires that the use of a user's camera, calendar, photo library, IDFA, etc. be declared by advertisers in the plist. Add all of the following entries to your app's plist.

```
<key>NSCameraUsageDescription</key>
    <string>${PRODUCT_NAME} requests write access to the Camera</string>
<key>NSPhotoLibraryAddUsageDescription</key>
    <string>${PRODUCT_NAME} requests write access to the Photo Library</string> 
<key>NSUserTrackingUsageDescription</key>
    <string>${PRODUCT_NAME} would like to show you personalized ads</string>
```

Note: Photo Usage and the Photo Add Usage keys are required by the framework to ensure all rich media advertisements are supported.

### SKAdNetwork Identifier <a href="#hyprmxmobilesdkadmob-unity-adapteroverview-skadnetworkidentifier" id="hyprmxmobilesdkadmob-unity-adapteroverview-skadnetworkidentifier"></a>

The HyprMX 6.0.0+ SDK supports Apple's new SKAdNetwork for Attribution. To add the HyprMX SKAdNetwork ID to your info.plist:

```
<key>SKAdNetworkItems</key>
<array>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>nu4557a4je.skadnetwork</string>
    </dict>
    ...
</array>
```

Note: SKAdNetwork IDs are case-sensitive.  For more information about SKAdNetwork please refer to Apple's [documentation](https://developer.apple.com/documentation/storekit/skadnetwork).

## Optional: Tag for Child Directed Treatment <a href="#hyprmxmobilesdkadmobadapteroverview-optional-userid-and-userconsent" id="hyprmxmobilesdkadmobadapteroverview-optional-userid-and-userconsent"></a>

Regional laws and regulations such as COPPA, GDPR, Google Play Store policies, and [Apple's Privacy Policy](https://www.apple.com/privacy/) require child-directed treatment of applicable users.&#x20;

If you participate in [Google Play’s Families Program](https://play.google.com/console/about/programs/families/), are listed in Google Play’s Family section, or include children as one of the target audiences, it is your responsibility as the app developer to ensure compliance with regional laws and regulations, and Google Play's Families Program, including, and not limited to,[ Google Play Families Policies](https://support.google.com/googleplay/android-developer/answer/9893335) to prevent access to the AAID for end-users flagged as children.

For instructions on how to tag the ad request as child-directed, please follow [AdMob's child-directed setting documentation.](https://developers.google.com/admob/unity/targeting#child-directed_setting)&#x20;

## Optional: User Consent <a href="#hyprmxmobilesdkadmob-unity-adapteroverview-optional-useridanduserconsent" id="hyprmxmobilesdkadmob-unity-adapteroverview-optional-useridanduserconsent"></a>

HyprMX provides the `HyprMXAdapterConfiguration.SetHasUserConsent` API to indicate a user’s consent status. This API will be used to indicate a user’s opt-in or opt-out consent for the collection and use of personal data under applicable laws and jurisdictions (GDPR, CPRA, etc.).

On App launch, the HyprMX SDK's Consent value will be `CONSENT_STATUS_UNKNOWN`. You can set `CONSENT_DECLINED` by calling `SetHasUserConsent(false)`, or `CONSENT_GIVEN` with `SetHasUserConsent(true)` depending on the user's consent collected by your application.

It is recommended to set the consent status once on Start and whenever your User changes their consent status.

```java
using GoogleMobileAds.Api.Mediation.HyprMX;

public void Start()
{    
    // User Declined Consent
    HyprMXAdapterConfiguration.SetHasUserConsent(false);
    
    // User Granted Consent
    HyprMXAdapterConfiguration.SetHasUserConsent(true);
}
```

## Optional: Audio Banner Ad Event Callbacks  <a href="#bannerads6.0.0-initializeinitializeabannerview" id="bannerads6.0.0-initializeinitializeabannerview"></a>

Refer to our Banner/MREC Ads guide ([iOS](/sdk-integration-guides/ios/ad-formats/banner-mrec-ads.md), [Android](/sdk-integration-guides/android-amazon/ad-formats/banner-mrec-ads.md)) to learn more about Audio Banner Ads.

### Setting an Audio Listener on HyprMX <a href="#bannerads6.0.0-initializeinitializeabannerview" id="bannerads6.0.0-initializeinitializeabannerview"></a>

To receive audio event callbacks, implement the `IHyprMXAudioListener` interface and set your delegate object to `HyprMXAudioEventBus.Instance.listener`.&#x20;

{% tabs %}
{% tab title="C#" %}

```csharp
public class MyGameObject : MonoBehaviour, IHyprMXAudioListener
{
    public void Start()
    {
        HyprMXAudioEventBus.Instance.listener = this;
    }
    
    #region IHyprMXAudioListener
    public void onAdAudioStart()
    {
        Debug.Log("onAdAudioStart");
    }

    public void onAdAudioEnd()
    {
        Debug.Log("onAdAudioEnd");
    }
    #endregion
}
```

{% endtab %}
{% endtabs %}

### Handling Interruptions <a href="#bannerads6.0.0-initializeinitializeabannerview" id="bannerads6.0.0-initializeinitializeabannerview"></a>

When an Audio Banner Ad begins playing, you will receive an `adAudioWillStart` callback from your `audioChangeDelegate`.  You should use this callback to pause your application's current audio player.

{% tabs %}
{% tab title="C#" %}

```csharp
AudioSource audioSource;
public void onAdAudioStart()
{
    audioSource.Pause();
}
```

{% endtab %}
{% endtabs %}

### Refresh Requirements <a href="#bannerads6.0.0-initializeinitializeabannerview" id="bannerads6.0.0-initializeinitializeabannerview"></a>

An Audio Banner Ad must remain on screen for the duration of the audio playback. In order to ensure the banner placement is not refreshed until the audio is complete, please set the refresh interval in your mediator's dashboard to 30 seconds or greater.

### Clearing Interruptions <a href="#bannerads6.0.0-initializeinitializeabannerview" id="bannerads6.0.0-initializeinitializeabannerview"></a>

When an Audio Banner Ad has completed playback, you will receive an `adAudioDidEnd` callback from your `audioChangeDelegate`. You should use this callback to resume your application's audio player.

{% tabs %}
{% tab title="C#" %}

<pre class="language-csharp"><code class="lang-csharp">AudioSource audioSource;
<strong>public void onAdAudioEnd()
</strong>{
    audioSource.Play();
}
</code></pre>

{% endtab %}
{% endtabs %}

## License

By integrating the HyprMX SDK, you are agreeing to the [End User License Agreement](https://www.hyprmx.com/eula).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.hyprmx.com/sdk-integration-guides/unity/admob-mediation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
