apsl_ads_flutter 0.0.5 copy "apsl_ads_flutter: ^0.0.5" to clipboard
apsl_ads_flutter: ^0.0.5 copied to clipboard

Apsl Ads is a wrapper around famous ad packages which let you integrate ads easily

Apsl Ads Flutter #

Show some 💙, 👍 the package & ⭐️ the repo to support the project

To easily integrate ads from different ad networks into your flutter app.

Features #

  • Google Mobile Ads (banner, appOpen, interstitial, rewarded ad)
  • Facebook Audience Network (banner, interstitial, rewarded ad)
  • Unity Ads (banner, interstitial, rewarded ad)
  • AppLovin Max Ads (banner, interstitial, rewarded ad)

Admob Mediation #

  • This plugin supports admob mediation See Details to see Admob Mediation Guide.
  • You just need to add the naative plaatform setting for admob mediation.

Platform Specific Setup #

iOS #

Update your Info.plist

  • The keys for AppLovin and Google Ads are required in Info.plist.

Update your app's ios/Runner/Info.plist file to add two keys:

<key>AppLovinSdkKey</key>
<string>YOUR_SDK_KEY</string>
<key>GADApplicationIdentifier</key>
<string>YOUR_SDK_KEY</string>
  • You have to add SKAdNetworkItems for all networks provided by Apsl-ads-flutter info.plist you can copy paste SKAdNetworkItems in your own project.

Android #

Update AndroidManifest.xml

<manifest>
    <application>
        <meta-data android:name="applovin.sdk.key"
            android:value="YOUR_SDK_KEY"/>
        <!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
    </application>
</manifest>

Initialize Ad Ids #

import 'dart:io';

import 'package:apsl_ads_flutter/apsl_ads_flutter.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';

class TestAdIdManager extends IAdIdManager {
  const TestAdIdManager();

  @override
  AppAdIds? get admobAdIds => AppAdIds(
    appId: Platform.isAndroid
        ? 'ca-app-pub-3940256099942544~3347511713'
        : 'ca-app-pub-3940256099942544~1458002511',
    appOpenId: Platform.isAndroid
        ? 'ca-app-pub-3940256099942544/3419835294'
        : 'ca-app-pub-3940256099942544/5662855259',
    bannerId: 'ca-app-pub-3940256099942544/6300978111',
    interstitialId: 'ca-app-pub-3940256099942544/1033173712',
    rewardedId: 'ca-app-pub-3940256099942544/5224354917',
  );

  @override
  AppAdIds? get unityAdIds => AppAdIds(
    appId: Platform.isAndroid ? '4374881' : '4374880',
    bannerId: Platform.isAndroid ? 'Banner_Android' : 'Banner_iOS',
    interstitialId:
    Platform.isAndroid ? 'Interstitial_Android' : 'Interstitial_iOS',
    rewardedId: Platform.isAndroid ? 'Rewarded_Android' : 'Rewarded_iOS',
  );

  @override
  AppAdIds? get appLovinAdIds => AppAdIds(
    appId:
    'OeKTS4Zl758OIlAs3KQ6-3WE1IkdOo3nQNJtRubTzlyFU76TRWeQZAeaSMCr9GcZdxR4p2cnoZ1Gg7p7eSXCdA',
    bannerId: Platform.isAndroid ? 'b2c4f43d3986bcfb' : '80c269494c0e45c2',
    interstitialId:
    Platform.isAndroid ? 'c48f54c6ce5ff297' : 'e33147110a6d12d2',
    rewardedId:
    Platform.isAndroid ? 'ffbed216d19efb09' : 'f4af3e10dd48ee4f',
  );

  @override
  AppAdIds? get fbAdIds => AppAdIds(
    appId: 'YOUR_APP_ID',
    interstitialId: 'VID_HD_16_9_15S_LINK#YOUR_PLACEMENT_ID',
    bannerId: 'IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID',
    rewardedId: 'VID_HD_16_9_46S_APP_INSTALL#YOUR_PLACEMENT_ID',
  );
}

Initialize the SDK #

Before loading ads, have your app initialize the Mobile Ads SDK by calling ApslAds.instance.initialize() which initializes the SDK and returns a Future that finishes once initialization is complete (or after a 30-second timeout). This needs to be done only once, ideally right before running the app.

import 'package:apsl_ads_flutter/apsl_ads_flutter.dart';
import 'package:flutter/material.dart';

const IAdIdManager adIdManager = TestAdIdManager();

ApslAds.instance.initialize(
    adIdManager,
    adMobAdRequest: const AdRequest(),
    // Set true if you want to show age restricted (age below 16 years) ads for applovin 
    isAgeRestrictedUserForApplovin: true,
    // To enable Facebook Test mode ads
    fbTestMode: true,
    admobConfiguration: RequestConfiguration(testDeviceIds: [
      '072D2F3992EF5B4493042ADC632CE39F', // Mi Phone
      '00008030-00163022226A802E',
    ]),
  );

Interstitial/Rewarded Ads #

Load an ad #

Ad is automatically loaded after being displayed or first time when you call initialize. But on safe side, you can call this method. This will load both rewarded and interstitial ads. If a particular ad is already loaded, it will not load it again.

ApslAds.instance.loadAd();

Show interstitial or rewarded ad #

ApslAds.instance.showAd(AdUnitType.rewarded);

Show random interstitial ad #

ApslAds.instance.showRandomAd(AdUnitType.interstitial)

Show appOpen ad #

ApslAds.instance.showAd(AdUnitType.appOpen)

Show Banner Ads #

This is how you may show banner ad in widget-tree somewhere:

@override
Widget build(BuildContext context) {
  Column(
    crossAxisAlignment: CrossAxisAlignment.stretch,
    children: [
      SomeWidget(),
      const Spacer(),
      ApslBannerAd(
          adNetwork: AdNetwork.admob, adSize: AdSize.mediumRectangle),
    ],
  );
}

Show Smart Banner Ad #

Smart Banner will check one by one the priority ad networks provided by you, if any of the priority network failed to load by some reason then it will automatically jump and try to load the next one so we can prevent revenue loss.

If you want to set the priority for Smart Banner, just pass the priorityAdNetworks in ApslSmartBannerAd constructor just like below. Other wise it will set by default as [admob, facebook, appLovin, unity] and default AdSize is AdSize.banner,

This is how you may show banner ad in widget-tree somewhere:

@override
Widget build(BuildContext context) {
  Column(
    crossAxisAlignment: CrossAxisAlignment.stretch,
    children: [
      SomeWidget(),
      const Spacer(),
      const ApslSmartBannerAd(
        priorityAdNetworks: [
          AdNetwork.facebook,
          AdNetwork.admob,
          AdNetwork.unity,
          AdNetwork.appLovin,
        ],
        adSize: AdSize.largeBanner,
      ),
    ],
  );
}

Listening to the callbacks #

Declare this object in the class

  StreamSubscription? _streamSubscription;

We are showing InterstitialAd here and also checking if ad has been shown. If true, we are canceling the subscribed callbacks, if any. Then, we are listening to the Stream and accessing the particular event we need

if (ApslAds.instance.showInterstitialAd()) {
  // Canceling the last callback subscribed
  _streamSubscription?.cancel();
  // Listening to the callback from showInterstitialAd()
  _streamSubscription =
  ApslAds.instance.onEvent.listen((event) {
    if (event.adUnitType == AdUnitType.interstitial &&
        event.type == AdEventType.adDismissed) {
      _streamSubscription?.cancel();
      goToNextScreen(countryList[index]);
    }
  });
}
5
likes
0
points
59
downloads

Publisher

verified publisherappstonelab.com

Weekly Downloads

Apsl Ads is a wrapper around famous ad packages which let you integrate ads easily

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

applovin_max, collection, easy_audience_network, flutter, google_mobile_ads, logger, unity_ads_plugin

More

Packages that depend on apsl_ads_flutter