Unity SDK: 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 of rewarded video

User Data

To specify user data, use the CustomParams property on the created API instance.

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

Samples

Integration samples is a part of unitypackage.
Was this article helpful?
Да
Нет