Main functions

  • Mediation display of RewardVideo ad for Geniee SDK from GoogleMobileAds RewardVideo advertisement
  • Geniee SDK displayed from GoogleMobileAds RewardVideo advertisement Callback support for RewardVideo advertisement

System operating environment

  • Android
    • Android SDK 4.1 or later
  • iOS
    • iOS 9.0 or later
    • 64bit for iOS

Development environment

  • Unity 2019.2.12f1
  • JDK 1.8 or later
  • SDK build target 28

Plugin Installation Procedure

Geniee Video Rewards to Unity GoogleMobileAds Advertisement SDK Describes the Unity Plugin installation procedure.

  1. Import Google Mobile Ads Unity plugin into Unity project
  2. Import GNSAdSDK-UnityPlugin-Google-Reward-5.0.0 to Unity project
  3. Set Google MobileAds app Id
  4. Register events for RewardVideo advertisement using Plugin API
  5. Load RewardVideo advertisement
  6. Display of RewardVideo advertisement
  7. About pre-call advertisement
  8. Test device ID setting method
  9. About Android package name

1. Import the Google Mobile Ads Unity plugin into the Unity project

  1. Download the GoogleMobileAds-v5.4.0.unitypackage from https://developers.google.com/admob/unity/start.
  2. Open the Unity project that incorporates the plugin.
  3. Select Assets -> Import Package -> Custom Package from the menu bar.
  4. Select the downloaded 'GoogleMobileAds-v5.4.0.unitypackage` file.
  5. Make sure all files' checkboxes are checked and click Import.

2. Import GNSAdSDK-UnityPlugin-Google-Reward plugin to Unity project

  1. Open the Unity project that incorporates the plugin.

  2. Select Assets -> Import Package -> Custom Package from the menu bar.

  3. Select the GNSAdSDK-UnityPlugin-Google-Reward-5.0.0.package file in the Dist folder.

  4. Make sure that the check box of the following file is checked and click on Import.

    • PlayServicesResolver
      • Editor
        • GNDependencies.xml
    • Plugins
      • Android
        • AndroidManifest.xml
        • GNSExtendsDfpUnityPlayerActivity.jar
        • mainTemplate.gradle

3. Set Google MobileAds app Id

Please set the app Id from Assets / GoogleMobileAds / Settings...

  • Check AdMob if you are using AdMob.
  • Check AdManager if you are using AdManager.

Please refer to the following site for detailed implementation procedures. https://developers.google.com/admob/unity/start?hl=en

4. Using the Plugin API, register events for RewardVideo advertisement

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

using GoogleMobileAds.Api;

...

static bool isRegistedRewardVideoEventHandler = false;
void RegistRewardVideoAdEventHandler()
{
    if (!isRegistedRewardVideoEventHandler)
    {
        // Get singleton reward based video ad reference.
        RewardBasedVideoAd rewardBasedVideo = RewardBasedVideoAd.Instance;
        // Called when an ad request has successfully loaded.
        rewardBasedVideo.OnAdLoaded += HandleRewardBasedVideoLoaded;
        // Called when an ad request failed to load.
        rewardBasedVideo.OnAdFailedToLoad += HandleRewardBasedVideoFailedToLoad;
        // Called when an ad is shown.
        rewardBasedVideo.OnAdOpening += HandleRewardBasedVideoOpened;
        // Called when the ad starts to play.
        rewardBasedVideo.OnAdStarted += HandleRewardBasedVideoStarted;
        // Called when the user should be rewarded for watching a video.
        rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
        // Called when the ad is closed.
        rewardBasedVideo.OnAdClosed += HandleRewardBasedVideoClosed;
        // Called when the ad click caused the user to leave the application.
        rewardBasedVideo.OnAdLeavingApplication += HandleRewardBasedVideoLeftApplication;
    }
    isRegistedRewardVideoEventHandler = true;
}
public void HandleRewardBasedVideoLoaded(object sender, EventArgs args)
{
    MonoBehaviour.print("HandleRewardBasedVideoLoaded event received");

}
public void HandleRewardBasedVideoFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
    MonoBehaviour.print(
        "HandleRewardBasedVideoFailedToLoad event received with message: "
                         + args.Message);
}
public void HandleRewardBasedVideoOpened(object sender, EventArgs args)
{
    MonoBehaviour.print("HandleRewardBasedVideoOpened event received");
}
public void HandleRewardBasedVideoStarted(object sender, EventArgs args)
{
    MonoBehaviour.print("HandleRewardBasedVideoStarted event received");
}
public void HandleRewardBasedVideoClosed(object sender, EventArgs args)
{
    MonoBehaviour.print("HandleRewardBasedVideoClosed event received");
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
    string type = args.Type;
    double amount = args.Amount;
    RewardBasedVideoAd rewardBasedVideo = RewardBasedVideoAd.Instance;
    MonoBehaviour.print(
        "HandleRewardBasedVideoRewarded event received for "
        + amount.ToString() + " " + type + " " + rewardBasedVideo.MediationAdapterClassName());
}
public void HandleRewardBasedVideoLeftApplication(object sender, EventArgs args)
{
    MonoBehaviour.print("HandleRewardBasedVideoLeftApplication event received");
}


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
  • The RewardBasedVideoAd instance is a singleton object for manipulating RewardVideo advertisements.
  • Since RewardBasedVideoAd instance is a singleton object, we recommend that you register events only once to avoid event duplication.

Reward possesses the following properties.

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

AdFailedToLoadEventArgs possesses the following properties.

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

5. Load RewardVideo advertisement

Below is the code necessary for loading RewardVideo ads.

using GNSAdSDK.Api;

...

void LoadRewardVideoAd()
{
    string defaultUnitId = "";
#if UNITY_ANDROID
        defaultUnitId = "Please put UnitId here";
#elif UNITY_IPHONE
        defaultUnitId = "Please put UnitId here";
#endif
    RewardBasedVideoAd rewardBasedVideo = RewardBasedVideoAd.Instance;
    AdRequest request = new AdRequest.Builder()
                               // .AddTestDevice("YOUR_TEST_DEVICE_ID")
                               .Build();
    rewardBasedVideo.LoadAd(request, defaultUnitId);
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  • The RewardBasedVideoAd instance is a singleton object for manipulating RewardVideo advertisements.
  • Loading may take more than a few seconds, please load RewardVideo ads early.
  • If you want to show another RewardVideo after the completion of playback of one RewardVideo, you need to load again.

6. Display RewardVideo advertisement

The code below is necessary for displaying RewardVideo advertisement. After loading the RewardVideo, you can call ShowAd ().

using GNSAdSDK.Api;

...

void ShowRewardVideoAd()
{
    RewardBasedVideoAd rewardBasedVideo = RewardBasedVideoAd.Instance;
    // Confirm whether video can be displayed
    if (rewardBasedVideo.IsLoaded())
    {
        // Show RewardVideo
        rewardBasedVideo.Show();
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

7. About preload for advertisement

Points to note when you want to load the next ad before showing advertisement

Implement rewardBasedVideo.LoadAd (request, adUnitId); into the ad close event (HandleRewardBasedVideoClosed), not within the reward grant event (HandleRewardBasedVideoRewarded).

8. 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();
rewardBasedVideo.LoadAd(request, defaultUnitId);
1
2
3
4
5

9. About Android package name

Please correct package name in Assets/Plugins/Android/AndroidManifest.xml as appropriate.

package="jp.co.geniee.GNSUnitySampleDfpRewardVideo"
1
2
Last Updated: 7/21/2020, 4:39:55 PM