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 theonInitSuccessfinal LevelPlayInterstitialAd _interstitialAd = LevelPlayInterstitialAd(adUnitId: [YOUR_AD_UNIT]);@overridevoid initState() { super.initState(); _interstitialAd.setListener(this);}
Set Interstitial Listener
Implement theLevelPlayInterstitialAdListener- 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 useloadAd_interstitialAd.loadAd();
Show Interstitial Ad
Show an interstitial ad after you receive theonAdLoadedshowAd- 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 theshowAd-
: 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 theshowAd// 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...