Interstitial ads
This is an archived version of the documentation. Actual documentation for all platforms can be found here.
An interstitial ad is a configurable ad that covers the entire screen and responds to clicks.
Adding Interstitial
to the project
To enable advertising, create an Interstitial
object in the script (in C#) that is attached to the GameObject
.
... using YandexMobileAds; using YandexMobileAds.Base; ... public class YandexMobileAdsInterstitialDemoScript : MonoBehaviour { private Interstitial interstitial; ... private void RequestInterstitial() { string adUnitId = "demo-interstitial-yandex"; interstitial = new Interstitial(adUnitId); } ... }
Copied to clipboard
The Interstitial
constructor contains the adUnitId
parameter, which is a unique identifier that is assigned in the Partner interface and takes the format R-M-XXXXXX-Y.
Loading ads
Once you have created and configured the Interstitial
class object, load your ads. To load an ad, use the LoadAd
method, accepting the AdRequest
object as a parameter.
... private void RequestInterstitial() { ... AdRequest request = new AdRequest.Builder().Build(); interstitial.LoadAd(request); ... } ...
Copied to clipboard
Displaying ads
After the ad has loaded, you can display it:
... private void ShowInterstitial() { if (this.interstitial.IsLoaded()) { interstitial.Show(); } else { Debug.Log("Interstitial is not ready yet"); } } ...
Copied to clipboard
Interstitial ad events
To track events that occur in interstitial ads, register a delegate for the appropriate EventHandler
, as shown below:
... private void RequestInterstitial() { ... interstitial.OnInterstitialLoaded += HandleInterstitialLoaded; interstitial.OnInterstitialFailedToLoad += HandleInterstitialFailedToLoad; interstitial.OnReturnedToApplication += HandleReturnedToApplication; interstitial.OnLeftApplication += HandleLeftApplication; interstitial.OnAdClicked += HandleAdClicked; interstitial.OnInterstitialShown += HandleInterstitialShown; interstitial.OnInterstitialDismissed += HandleInterstitialDismissed; interstitial.OnImpression += HandleImpression; interstitial.OnInterstitialFailedToShow += HandleInterstitialFailedToShow; ... } public void HandleInterstitialLoaded(object sender, EventArgs args) { MonoBehaviour.print("HandleInterstitialLoaded event received"); } public void HandleInterstitialFailedToLoad(object sender, AdFailureEventArgs args) { MonoBehaviour.print( "HandleInterstitialFailedToLoad event received with message: " + args.Message); } public void HandleReturnedToApplication(object sender, EventArgs args) { MonoBehaviour.print("HandleReturnedToApplication event received"); } public void HandleLeftApplication(object sender, EventArgs args) { MonoBehaviour.print("HandleLeftApplication event received"); } public void HandleAdClicked(object sender, EventArgs args) { MonoBehaviour.print("HandleAdClicked event received"); } public void HandleInterstitialShown(object sender, EventArgs args) { MonoBehaviour.print("HandleInterstitialShown event received"); } public void HandleInterstitialDismissed(object sender, EventArgs args) { MonoBehaviour.print("HandleInterstitialDismissed event received"); } public void HandleImpression(object sender, ImpressionData impressionData) { var data = impressionData == null ? "null" : impressionData.rawData; MonoBehaviour.print("HandleImpression event received with data: " + data); } public void HandleInterstitialFailedToShow(object sender, AdFailureEventArgs args) { MonoBehaviour.print( "HandleInterstitialFailedToShow event received with message: " + args.Message); }
Copied to clipboard
Clearing ads
When an ad object is no longer needed, you can delete it. To do this, call the Destroy
method:
interstitial.Destroy();
Copied to clipboard