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 分最終更新 2ヶ月前
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 callback.
onInitSuccessThe LevelPlay 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 in your code to get informed of ad delivery.
LevelPlayInterstitialAdListener- 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.
@override void onAdLoaded(LevelPlayAdInfo adInfo) { // Provided when the ad is successfully loaded } @override void onAdLoadFailed(LevelPlayAdError error) { // Provided when the ad fails to load. Ad Unit information is included } @override void onAdDisplayed(LevelPlayAdInfo adInfo) { // Provided when the ad is displayed. This is equivalent to an impression } @override void onAdDisplayFailed(LevelPlayAdError error, LevelPlayAdInfo adInfo) { // Provided when the ad fails to be displayed } @override void onAdClicked(LevelPlayAdInfo adInfo) { // Provided when the user clicks on the ad } @override void onAdClosed(LevelPlayAdInfo adInfo) { // Provided when the ad is closed } @override void 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 callback, using .
onAdLoadedshowAd- 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 API:
showAd-
: Returns true if ad was loaded successfully and ad unit is not capped, or false otherwise.
isAdReady -
: Returns true when a valid placement is capped. If the placement is not valid, or not capped, this API will return false.
isPlacementCapped
// 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 method to serve the ad for a specific placement.
showAd// 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.
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: