文档

支持

LevelPlay SDK - Flutter

Interstitial integration for Flutter

Integrate full-screen interstitial ads in your Flutter app using the Unity LevelPlay SDK, supporting both static and video formats.
阅读时间3 分钟最后更新于 7 天前

The LevelPlay Interstitial is a full-screen ad unit, usually served at natural transition points during the app lifecycle. Unity supports both static and video interstitials.

Prerequisites

  • Ensure that you have correctly integrated the LevelPlay Flutter Plug-in into your app.
  • Ensure that you initialize the SDK using LevelPlay Initialization API.
  • Find the AdUnitID in LevelPlay dashboard.

Create Interstitial and Register to Events

Create the interstitial object after your receive the
onInitSuccess
 callback.
The ironSource SDK fires several events to inform you of your Interstitial activity. To receive these events, register the listeners of the ad unit. Make sure you set the listeners before initializing the SDK to prevent any loss of information.
final LevelPlayInterstitialAd _interstitialAd = LevelPlayInterstitialAd(adUnitId: [YOUR_AD_UNIT]);@overridevoid initState() { super.initState(); _interstitialAd.setListener(this);}

Set Interstitial Listener

Implement the 
LevelPlayInterstitialAdListener
 in your code to get informed of ad delivery.
  • The recommended best practice is to set the listener before loading the interstitial ad.
  • Each interstitial ad must have its own listener implementation.
  • Callbacks run on the main thread.
@overridevoid onAdLoaded(LevelPlayAdInfo adInfo) { // Provided when the ad is successfully loaded}@overridevoid onAdLoadFailed(LevelPlayAdError error) { // Provided when the ad fails to load. Ad Unit information is included}@overridevoid onAdDisplayed(LevelPlayAdInfo adInfo) { // Provided when the ad is displayed. This is equivalent to an impression}@overridevoid onAdDisplayFailed(LevelPlayAdError error, LevelPlayAdInfo adInfo) { // Provided when the ad fails to be displayed}@overridevoid onAdClicked(LevelPlayAdInfo adInfo) { // Provided when the user clicks on the ad}@overridevoid onAdClosed(LevelPlayAdInfo adInfo) { // Provided when the ad is closed}@overridevoid onAdInfoChanged(LevelPlayAdInfo adInfo) { // Provided when the ad info is updated. Available when another ad has loaded, and includes a higher CPM/Rate}

Load Interstitial Ad

To load an interstitial ad use 
loadAd
.
_interstitialAd.loadAd();

Show Interstitial Ad

Show an interstitial ad after you receive the
onAdLoaded
callback, using
showAd
.
  • It is required to share Activity
  • If using placements, pass the placement name in the showAd API as shown in the Placements section below.
  • After the ad has been successfully displayed to the user, you can load another ad by repeating the loading step. 
// Show ad without placement _interstitialAd.showAd(); // Show ad with placement _interstitialAd.showAd(placement: [YOUR_PLACEMENT]);

Check Ad is Ready

To avoid show failures, and to make sure the ad worked correctly, the recommended best practice is to use the following API before calling the
showAd
API:
  • isAdReady
    : Returns true if ad was loaded successfully and ad unit is not capped, or false otherwise.
  • isPlacementCapped
    : Returns true when a valid placement is capped. If the placement is not valid, or not capped, this API will return false.
// Check that ad is ready and that the placement is not capped if(_interstitialAd.isAdReady() && !LevelPlayInterstitialAd.isPlacementCapped([YOUR_PLACEMENT])) { _interstitialAd.showAd(placement:[YOUR_PLACEMENT]); }

Placements

Unity supports placements pacing and capping for interstitial on the LevelPlay dashboard.  If you have set up placements for interstitial ads, call the 
showAd
 method to serve the ad for a specific placement.
// Check that ad is ready and that the placement is not capped if(_interstitialAd.isAdReady() && !LevelPlayInterstitialAd.isPlacementCapped([YOUR_PLACEMENT])) { _interstitialAd.showAd(placement:[YOUR_PLACEMENT]); }

Full Implementation Example of Interstitial Ads

// Start of the widget...final LevelPlayInterstitialAd _interstitialAd = LevelPlayInterstitialAd(adUnitId: 'YOUR_AD_UNIT_ID'); @override void initState() { super.initState(); _interstitialAd.setListener(this); _interstitialAd.loadAd(); } @override void onAdClicked(LevelPlayAdInfo adInfo) { // Implement your logic here... } @override void onAdClosed(LevelPlayAdInfo adInfo) { // Implement your logic here... } @override void onAdDisplayFailed(LevelPlayAdError error, LevelPlayAdInfo adInfo) { // Implement your logic here... } @override void onAdDisplayed(LevelPlayAdInfo adInfo) { // Implement your logic here... } @override void onAdInfoChanged(LevelPlayAdInfo adInfo) { // Implement your logic here... } @override void onAdLoadFailed(LevelPlayAdError error) { // Implement your logic here... } @override void onAdLoaded(LevelPlayAdInfo adInfo) { // Implement your logic here, for example showing the ad _interstitialAd.showAd(); } // Rest of the widget // End of widget...

LevelPlay Mediation Demo App

The Integration Demo application demonstrates how to integrate interstitial Ad Unit APIs in your app. Download Flutter Demo Application Verify your integration with the Integration Test Suite.

Next steps

Follow the Flutter integration guides to integrate additional Interstitial Ad networks or configure additional ad formats: