Ad Formats Unity

Banners

Initialization

To display 320x50, 300x250 and 728x90 banners in your app, you must create an instance of the MyTargetView class. To create an instance of MyTargetView, specify your slotId. To specify the format, you must set one of AdSize values. The default format is 320x50.

private MyTargetView _myTargetView;
private void Awake()
{
    UInt32 slotId = 0;
#if UNITY_ANDROID
    slotId = ANDROID_SLOT_ID;
#elif UNITY_IOS
    slotId = IOS_SLOT_ID;
#endif
 
    // Enabling debug mode
    // MyTargetView.IsDebugMode = true;
 
    // Create an instance of MyTargetView, 320x50 format
    _myTargetView = new MyTargetView(slotId);
  
    // Create an instance of MyTargetView, 300x250 format
    // _myTargetView = new MyTargetView(slotId, AdSize.Size300x250);
}

Loading and displaying ads

To receive notifications (such as ad load succeeded, ad load failed, or ad clicked), you must set handlers to corresponding events. After ad has loaded successfully, you can start displaying ad.

private readonly Object _syncRoot = new Object();
private MyTargetView _myTargetView;
private void Awake()
{
    if (_myTargetView != null)
    {
        return;
    }  
    lock (_syncRoot)
    {
        if (_myTargetView != null)
        {
            return;
        }  
         
        // Create an instance of MyTargetView
        _myTargetView = new MyTargetView(YOUR_SLOT_ID);
     
        // Set event handlers
        _myTargetView.AdClicked += OnAdClicked;
        _myTargetView.AdLoadFailed += OnAdLoadFailed;
        _myTargetView.AdLoadCompleted += OnAdLoadCompleted;
        _myTargetView.AdShown += OnAdShown;
 
        // Start loading ad
        _myTargetView.Load();
    }
}
  
private void OnAdClicked(Object sender, EventArgs eventArgs) { }
 
private void OnAdShown(Object sender, EventArgs eventArgs) { }
 
private void OnAdLoadFailed(Object sender, ErrorEventArgs errorEventArgs) { }
  
private void OnAdLoadCompleted(Object sender, EventArgs eventArgs)
{
    // The ad is successfully loaded
  
    // Set position on the screen
    _myTargetView.X = 0;
    _myTargetView.Y = 0;
         
    // Start displaying ad
    _myTargetView.Start();
}
  
private void OnDestroy()
{
    if (_myTargetView == null)
    {
        return;
    }
    lock (_syncRoot)
    {
        if (_myTargetView == null)
        {
            return;
        }
        _myTargetView.Dispose();
        _myTargetView = null;
    }
}

Rotation

Ads are rotated every 60 seconds. You can disable automatic ad rotation by specifying the optional isRefreshAd parameter when creating the instance. Rotation is only available for 320x50 and 728x90 formats.


// Disable automatic ad rotation
_myTargetView = new MyTargetView(YOUR_SLOT_ID, AdSize.Size320x50, false)
Example Banner 320x50

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 Interstitial Banner

Rewarded video

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

Initialization

To display video 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.AdDisplayed += OnAdDisplayed;
    _interstitialAd.AdDismissed += OnAdDismissed;
    _interstitialAd.AdVideoCompleted += OnAdVideoCompleted;
    _interstitialAd.AdClicked += OnAdClicked;
    _interstitialAd.AdLoadFailed += OnAdLoadFailed;
     
    // Start loading ad
    _interstitialAd.Load();
}
 
private void OnLoadCompleted(Object sender, EventArgs e)
{
     
}
private void OnAdDisplayed(Object sender, EventArgs e)
{
     
}
 
private void OnAdDismissed(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 video ad.


private void OnLoadCompleted(Object sender, EventArgs e)
{
    // in a separate Page
    _interstitialAd.Show();
 
    // or in dialog box
    // _interstitialAd.ShowDialog();
}
Example Rewarded video

User Data

Для задания пользовательских данных вам нужно воспользоваться свойством CustomParams созданного экземпляра API.

To set custom data, you need to use the CustomParams property of the created API instance.

private InterstitialAd _ad;
 
private void InitAd()
{
    // Create instance InterstitialAd
    _ad = new InterstitialAd(YOUR_SLOT_ID);
 
    // Set age
    _ad.CustomParams.Age = 23;
    // Set gender
    _ad.CustomParams.Gender = CustomParams.GenderEnum.Male;    
}

Samples

You can see examples in unitypackage.
Was this article helpful?