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 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 we explained above, if many consecutive failures are received and the interstitialDidFailToLoadAd function is frequently called, then the MoPub SDK triggers rate limiting, and immediately fails the requests. This again causes interstitialDidFailToLoadAd 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:

- (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, and prevents rate limiting from being triggered.

Last updated August 24, 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.)