Rate Limiting

Understand Rate Limiting

The MoPub SDK imposes minimum wait times between consecutive ad requests. If frequent ad requests result in no fill, MoPub rate-limits the number of outgoing requests. When this happens, the MoPub SDK immediately fails any subsequent requests and notifies publishers via ad failure callbacks.

To prevent rate-limiting from causing an endless ad request loop, you should implement a minimum wait time of 10 seconds between consecutive unfilled ad requests.

Example

Here’s an example of imposing wait times before re-requesting interstitial ads on Unity, using C#:

On the class where you handle interstitial lifecycle events (the class that also registers to OnInterstitialFailedEvent), you request ads using the MoPub.RequestInterstitialAd function. Each ad request can either result in success and trigger the OnInterstitialLoadedEvent callback, or in a failure and trigger the OnInterstitialFailedEvent callback.

As described previously, if there is a failed ad request, for example no fill, then the MoPub SDK triggers rate limiting, and immediately fails the requests. When this happens OnInterstitialFailedEvent is called again and can create a loop of failing requests.

This is likely to happen if you are immediately re-requesting an ad on fail callback, like this:

After binding the fail event to a local method like this:

MoPubManager.OnInterstitialFailedEvent += OnInterstitialFailedEvent;

You implement the fail scenario like this:

private void OnInterstitialFailedEvent(string adUnitId, string error)
{
    MoPub.RequestInterstitialAd(adUnitId);
}

Instead of allowing MoPub.RequestInterstitialAd to be called immediately, wait for some time. There are many ways to achieve this.

As an example, on Unity with a 10-second delay, you can use Unity’s Coroutine pattern:

void OnInterstitialFailedEvent(string adUnitId, string error)
{
    StartCoroutine(LoadInterstitialDelayed(adUnitId));
}

bool isRequestingInterstitialDelayed = false;

private float interstitialRequestDelay = 10.0f;

IEnumerator LoadInterstitialDelayed(string adUnitId)
{
    if (isRequestingInterstitialDelayed)
        yield break;

    isRequestingInterstitialDelayed = true;

    yield return new WaitForSeconds(interstitialRequestDelay);

    MoPub.RequestInterstitialAd(adUnitId);

    isRequestingInterstitialDelayed = false;
}

This approach re-requests an interstitial ad 10 seconds later instead of immediately.


Last updated July 14, 2021

TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.

© 2021 MoPub (a division of Twitter, Inc.)