nooralibutt / easy-ads

This repo has the integration of AdMob, AppLovin-Max, UnityAds, and Facebook ads.
https://pub.dev/packages/easy_ads_flutter
BSD 3-Clause "New" or "Revised" License
41 stars 20 forks source link

Set priority for Interstitial/Rewarded Ad #80

Closed Omi231 closed 11 months ago

Omi231 commented 11 months ago

Hi, first of all felt proud that fellow pakistanis are maintaining such useful packages and contributing to open source code.

My problem is I want to prioritize Interstitial/rewarded ads same as like you have added the ability of smart banner which works in a waterfall manner.

I want to prioritize Meta Audience network first and if audience network interstitial ad is not available then show applovin or next network's ad. Right now it is showing me random video ad, whichever is available and ready.

Thanks.

nooralibutt commented 11 months ago

@Omi231 you can easily implement priority based ad, let me send you a code snippet:

bool showPriorityInterstitial() {
    const list = [
      AdNetwork.admob,
      AdNetwork.facebook,
      AdNetwork.unity,
      AdNetwork.appLovin,
      AdNetwork.any
    ];

    for (int i = 0; i < list.length; i++) {
      if (list[i] == AdNetwork.facebook) {
        if (EasyAds.instance.showAd(AdUnitType.interstitial,
            adNetwork: AdNetwork.facebook)) return true;
      } else if (list[i] == AdNetwork.unity) {
        if (EasyAds.instance.showAd(AdUnitType.interstitial,
            adNetwork: AdNetwork.unity)) return true;
      } else if (list[i] == AdNetwork.appLovin) {
        if (EasyAds.instance.showAd(AdUnitType.interstitial,
            adNetwork: AdNetwork.appLovin)) return true;
      } else if (list[i] == AdNetwork.admob) {
        if (EasyAds.instance.showAd(AdUnitType.interstitial,
            adNetwork: AdNetwork.admob)) return true;
      }
    }

    return EasyAds.instance.showAd(AdUnitType.interstitial);
  }