Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Collapsible banner using AdMob

Discussion in 'Unity Ads & User Acquisition' started by PavloSupenko, Sep 8, 2023.

  1. PavloSupenko

    PavloSupenko

    Joined:
    Jul 3, 2018
    Posts:
    2
    Hi there!
    I want to try implement collapsible banner for Unity game. I'm using Google Mobile Ads official SDK.
    I didn't find any official Google guides about implementing this extension for banner ad even for native, only a few threads on some forums like here and here.

    I tried to pass collapsible arguments to request Extras:
    Code (CSharp):
    1. new AdRequest.Builder()
    2.     .AddExtra("max_ad_content_rating", adSettings.ContentRating) // works fine
    3.     .AddExtra("collapsible", "bottom") // do nothing
    4.     .Build();
    But as I understand the native examples by links above I need pass this extra settings not to request but to AdMob network directly by using
    AddMediationExtras
    builder extension. I've created the next implementation with parameters I need:

    Code (CSharp):
    1.         public class CollapsibleBannerMediationExtras : MediationExtras
    2.         {
    3.             // I need to test it firstly on Android so null string here
    4.             public override string IOSMediationExtraBuilderClassName { get; }
    5.             public override string AndroidMediationExtraBuilderClassName => "com.google.ads.mediation.admob.AdMobAdapter";
    6.             public CollapsibleBannerMediationExtras()
    7.             {
    8.                 Extras = new Dictionary<string, string>()
    9.                 {
    10.                     ["collapsible"] = "bottom"
    11.                 };
    12.             }
    13.         }
    And use it for building request:

    Code (CSharp):
    1. new AdRequest.Builder()
    2.     .AddExtra("max_ad_content_rating", adSettings.ContentRating)
    3.     .AddMediationExtras(new CollapsibleBannerMediationExtras())
    4.     .Build();
    But I get the runtime error message:
    Code (CSharp):
    1. UnityEngine.AndroidJavaException: java.lang.NoSuchMethodError: no non-static method with name='buildExtras' signature='(Ljava.util.HashMap;)Ljava/lang/Object;' in class Lcom.google.ads.mediation.admob.AdMobAdapter;
    And, yeah, this class do not have the buildExtras method. So I think I should find the right class to pass it to extras implementation class, but I don't really know what class I need.

    Or maybe this functionality cannot be achieved through Unity.

    Could anyone please help me with that task ?
    Thanks!