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 MoPub from rate-limiting your ad requests, you can optimize your ad requests and add a minimum wait time of 10 seconds between 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 many consecutive failures are received and OnInterstitialFailedEvent method is frequently called, then the MoPub SDK triggers rate limiting, and immediately fails the requests. This again causes OnInterstitialFailedEvent to be called 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);
}

Such a practice is very likely to trigger rate limiting. 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, and prevents rate limiting from being triggered.

Last updated May 18, 2020

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.

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