Banner

Main functions

This section describes how to implement the banner.

How to implement

This section describes how to implement the banner.

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

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

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 banner of Geniee SDK just by implementing it using Google Mobile Ads SDK for Unity.

2. Using the Plugin API, register events for banner advertisement

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

using GNSAdSDK.Api;

...

private BannerView bannerView;

...

void RegistBannerAdEventHandler()
{
#if UNITY_ANDROID
    string adUnitId = "Input unit id";
#elif UNITY_IPHONE
    string adUnitId = "Input unit id";
#else
    string adUnitId = "Input unit id";
#endif
    AdSize adSize = AdSize.Banner;
    AdPosition adPosition = AdPosition.Bottom;

    bannerView = new BannerView(adUnitId, adSize, adPosition);
    // Called when an ad request has successfully loaded.
    bannerView.OnAdLoaded += this.HandleAdLoaded;
    // Called when an ad request failed to load.
    bannerView.OnAdFailedToLoad += this.HandleOnAdFailedToLoad;
    // Called when an ad is clicked.
    bannerView.OnAdOpening += this.HandleOnAdOpened;
    // Called when the user returned from the app after an ad click.
    bannerView.OnAdClosed += this.HandleOnAdClosed;
    // Called when the ad click caused the user to leave the application.
    bannerView.OnAdLeavingApplication += HandleOnAdLeavingApplication;
}

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

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

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

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

public void HandleOnAdLeavingApplication(object sender, EventArgs args)
{
    Debug.Log("HandleAdLeavingApplication 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

3. Load banner advertisement

Below is the code necessary for loading banner ads.

using GNSAdSDK.Api;

...

private BannerView bannerView;

...

void RequestLoad()
{
    if (this.bannerView != null) {
        AdRequest request = new AdRequest.Builder()
            //.AddTestDevice("YOUR_DEVICE_ID")
            .Build();
        // Load the banner with the request.
        bannerView.LoadAd(request);
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

4. Finish of banner ad

Below is the code needed to end the banner ad.

using GNSAdSDK.Api;

...

private BannerView bannerView;

...

void finishBanner()
{
    if (this.bannerView != null)
    {
        this.bannerView.Destroy();
        this.bannerView = null;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

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" ];
  2. 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