Unity SDK: Interstitial Ads

The myTarget SDK provides the ability to display an interstitial ads in your app. The myTarget SDK provides two ways to display interstitial ads: in a separate Page or in a dialog box. We recommend that you display ads in a separate Page.

Initialization

To display interstitial ad in your app, create an instance of the InterstitialAd class. You must specify your slotId when creating an instance. Each platform has its own slotId.
private InterstitialAd CreateInterstitialAd()
{
    UInt32 slotId = 0;
#if UNITY_ANDROID
    slotId = ANDROID_SLOT_ID;
#elif UNITY_IOS
    slotId = IOS_SLOT_ID;
#endif
 
    // Enabling debug mode
    // InterstitialAd.IsDebugMode = true;
    // Create an instance of InterstitialAd
    return new InterstitialAd(slotId);
}

Loading ads

To receive notifications (such as ad loaded, ad clicked, ad dismissed), you must set handlers to corresponding events. Then you can start loading ad.
private InterstitialAd _interstitialAd;
 
private void InitAd()
{
    // Create an instance of InterstitialAd
    _interstitialAd = CreateInterstitialAd();
     
    // Set event handlers
    _interstitialAd.AdLoadCompleted += OnLoadCompleted;
    _interstitialAd.AdDismissed += OnAdDismissed;
    _interstitialAd.AdDisplayed += OnAdDisplayed;
    _interstitialAd.AdVideoCompleted += OnAdVideoCompleted;
    _interstitialAd.AdClicked += OnAdClicked;
    _interstitialAd.AdLoadFailed += OnAdLoadFailed;
     
    // Start loading ad
    _interstitialAd.Load();
}
 
private void OnLoadCompleted(Object sender, EventArgs e)
{
     
}
 
private void OnAdDismissed(Object sender, EventArgs e)
{
     
}
 
private void OnAdDisplayed(Object sender, EventArgs e)
{
      
}
  
private void OnAdVideoCompleted(Object sender, EventArgs e)
{
 
}
  
private void OnAdClicked(Object sender, EventArgs e)
{
          
}
  
private void OnAdLoadFailed(Object sender, ErrorEventArgs e)
{
    Debug.Log("OnAdLoadFailed: " + e.Message);
}

Displaying ads

After the ad has loaded successfully, you can start displaying interstitial ad.
private void OnLoadCompleted(Object sender, EventArgs e)
{
    // in a separate Page
    _interstitialAd.Show();
 
    // or in dialog box
    // _interstitialAd.ShowDialog();
}
Example of an interstitial banner
Was this article helpful?
Yes
No