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 = "YOUR_adUnitId"; 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 looks like this: R-M-XXXXXX-Y.
Loading ads
After creating and configuring the object of the Interstitial
class, load ads. To load an ad, use the LoadAd
method, which takes the AdRequest
object as an argument.
interstitial.LoadAd(request);
Copied to clipboard
- About loading ads
- Use the
AdRequest
object to transmit the code received in the Adfox interface (for more information, see Help for Adfox):... // Code from the Adfox interface for working with direct campaigns. private Dictionary<string, string> CreateAdfoxParameters() { Dictionary<string, string> parameters = new Dictionary<string, string>() { {"adf_ownerid", "<example>"}, {"adf_p1", "<example>"}, {"adf_p2", "<example>"}, {"adf_pt", "<example>"}, ... }; return parameters; } ... private void RequestInterstitial() { ... AdRequest request = new AdRequest.Builder() .WithParameters(CreateAdfoxParameters()) .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