RewardVideo

Main functions

  • Use GoogleMobileAds to display rewarded video ads.

How to implement

This section describes how to implement the video reward.

  1. Introducing of GoogleMobileAds Mediation Ad
  2. Using the Plugin API, register events for video reward advertisement
  3. Load video reward advertisement
  4. Display video reward advertisement
  5. How to set test device ID

For detailed video reward implementation procedures, refer to the following site. https://developers.google.com/admob/unity/banner

1. Introducing of GoogleMobileAds Mediation Ad

Please refer to the following to install the plugin.

Introducing of GoogleMobileAds Mediation Ad

If there is a correct description in GNDependencies.xml, it is possible to display the reward video of Geniee SDK just by implementing it using Google Mobile Ads SDK for Unity.

2. Using the Plugin API, register events for video reward advertisement

The code below is necessary to create a video reward advertisement and register an event. When registering an event, please complete the registration process before loading the movie.

using GoogleMobileAds.Api;

...

private RewardedAd rewardedAd;

...

void RegistRewardVideoAdEventHandler()
{
#if UNITY_ANDROID
    string adUnitId = "Input unit id";
#elif UNITY_IPHONE
    string adUnitId = "Input unit id";
#else
    string adUnitId = "Input unit id";
#endif

        this.rewardedAd = new RewardedAd(adUnitId);
        // Called when an ad request has successfully loaded.
        this.rewardedAd.OnAdLoaded += HandleRewardedAdLoaded;
        // Called when an ad request failed to load.
        this.rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
        // Called when an ad is shown.
        this.rewardedAd.OnAdOpening += HandleRewardedAdOpening;
        // Called when an ad request failed to show.
        this.rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow;
        // Called when the user should be rewarded for interacting with the ad.
        this.rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
        // Called when the ad is closed.
        this.rewardedAd.OnAdClosed += HandleRewardedAdClosed;
}

public void HandleRewardedAdLoaded(object sender, EventArgs args)
{
    Debug.Log("HandleRewardedAdLoaded event received");
}

public void HandleRewardedAdFailedToLoad(object sender, AdErrorEventArgs args)
{
        Debug.Log(
            "HandleRewardedAdFailedToLoad event received with message: "
                             + args.Message);
}

public void HandleRewardedAdOpening(object sender, EventArgs args)
{
    Debug.Log("HandleRewardedAdOpening event received");
}

public void HandleRewardedAdFailedToShow(object sender, AdErrorEventArgs args)
{
    Debug.Log(
        "HandleRewardedAdFailedToShow event received with message: "
                         + args.Message);
}

public void HandleRewardedAdClosed(object sender, EventArgs args)
{
    Debug.Log("HandleRewardedAdClosed event received");
    this.rewardedAd = null;
}

public void HandleUserEarnedReward(object sender, Reward args)
{
    string type = args.Type;
    double amount = args.Amount;
    Debug.Log(
        "HandleRewardedAdRewarded event received for "
                    + amount.ToString() + " " + type
                    + " " + this.rewardedAd.MediationAdapterClassName());
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

Reward possesses the following properties.

public class Reward : EventArgs
{
    // Amount of money
    public double Amount { get; set; }
    // type
    public string Type { get; set; }
}
1
2
3
4
5
6
7
8

AdErrorEventArgs possesses the following properties.

public class AdErrorEventArgs : EventArgs
{
    // Message
    public string Message { get; set; }
}
1
2
3
4
5
6

3. Load video reward advertisement

Below is the code necessary for loading video reward ads.

using GNSAdSDK.Api;

...

private RewardedAd rewardedAd;

...

void LoadRewardVideoAd()
{
    if (this.rewardedAd != null) {
        AdRequest request = new AdRequest.Builder()
            //.AddTestDevice("YOUR_DEVICE_ID")
            .Build();
        this.rewardedAd.LoadAd(request);
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  • Loading may take more than a few seconds, please load video ads early.
  • If you want to show another movie after the completion of playback of one movie, you need to load again.

4. Display video reward advertisement

The code below is necessary for displaying video reward advertisement. After loading the movie, you can call Show().

using GNSAdSDK.Api;

...

private RewardedAd rewardedAd;

...

void ShowRewardVideoAd()
{
        if (this.rewardedAd != null && this.rewardedAd.IsLoaded())
        {
            this.rewardedAd.Show();
        }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

5. How to set test device ID

  • You can enable test ads during development.
  • If you click many advertisements without putting it in the test mode, there is a danger that the account will be invalid.
  • Please be sure to delete this setting at the time of actual release.
  1. To set up such a message first check the console or logcat output.
OS Output example
Android I/Ads: Use AdRequest.Builder.addTestDevice("YOUR_TEST_DEVICE_ID")
iOS request.testDevices = @[ "YOUR_TEST_DEVICE_ID" ];
  1. Add the AddTestDevice method to the Request.
AdRequest request = new AdRequest.Builder()
                           .AddTestDevice("YOUR_TEST_DEVICE_ID")
                           .Build();
1
2
3
4
Last Updated: 7/21/2020, 6:51:48 PM