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 iOS, using Swift:

On the class where you handle interstitial lifecycle events (the class that implements MPInterstitialAdControllerDelegate), you request ads using the loadAd method on your MoPub interstitial view. Each ad request can either result in success and trigger the interstitialDidLoad callback, or in failure and trigger the interstitialDidFailToLoadAd 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 interstitialDidFailToLoadAd 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:

- (void)interstitialDidFailToLoadAd:(MPInterstitialAdController *)interstitial {
    [self.interstitialAd loadAd];
}

Such a practice is very likely to trigger rate limiting. Instead of allowing loadAd to be called immediately, wait for some time. There are many ways to achieve this.

As an example, on iOS with a 10-second delay, you can use iOS’s Dispatch framework to call loadAd using the dispatch_after method:

- (void)interstitialDidFailToLoadAd:(MPInterstitialAdController *)interstitial {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        [self.interstitialAd loadAd];
    });
}

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


Last updated March 30, 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.)