How to pass custom parameter with CustomEvent

55 views
Skip to first unread message

EdisonLiao

unread,
Apr 24, 2024, 9:54:43 AMApr 24
to Google Mobile Ads SDK Developers
I have wrote a SampleCustomEvent which extends Adapter(com.google.android.gms.ads.mediation.Adapter), and I have override the loadBannerAd method, I see MediationBannerAdConfiguration has a getMediationExtras method, but I cannot  figure out where to set the extras bundle. So how can I pass custom parameter(key,value) and get it?   Thx!!

Admod SDK Version:  com.google.android.gms:play-services-ads:20.2.0

Mobile Ads SDK Forum Advisor

unread,
Apr 24, 2024, 4:34:00 PMApr 24
to liaosh...@gmail.com, google-adm...@googlegroups.com

Hi,

Thank you for contacting the Mobile Ads SDK Support team.

To pass custom parameters, you will leverage the ServerParameters bundle within the MediationBannerAdConfiguration object. Please refer to these Set up a custom event and also Banner ads custom events for more information regarding custom events setup.

This message is in relation to case "ref:!00D1U01174p.!5004Q02tPIaX:ref" (ADR-00232478)

Thanks,
 
Google Logo Mobile Ads SDK Team


EdisonLiao

unread,
Apr 25, 2024, 9:17:20 AMApr 25
to Google Mobile Ads SDK Developers
Thanks for reply, I know MediationBannerAdConfiguration can get ServerParameters bundle, but I wanna pass custom parameters while request ad, how can I do that

EdisonLiao

unread,
Apr 25, 2024, 9:17:30 AMApr 25
to Google Mobile Ads SDK Developers
I wanna pass custom parameters while request ad, which means pass custom parameters dynamic while begin to call loadAd (cuz ServerParameters need to config all key-value before request ad)
在2024年4月25日星期四 UTC+8 04:34:00<Mobile Ads SDK Forum Advisor> 写道:

EdisonLiao

unread,
Apr 25, 2024, 9:17:35 AMApr 25
to Google Mobile Ads SDK Developers
What's more, I use addNetworkExtrasBundle method, and pass the custom Class (SampleCustomEvent which extends Adapter(com.google.android.gms.ads.mediation.Adapter))  and Bundle, but I do not know where to get the bundle

在2024年4月25日星期四 UTC+8 04:34:00<Mobile Ads SDK Forum Advisor> 写道:

Mobile Ads SDK Forum Advisor

unread,
Apr 25, 2024, 4:00:51 PMApr 25
to liaosh...@gmail.com, google-adm...@googlegroups.com

Hi,

Thank you for contacting us.

I am checking your issue, I will get back to you with the solution shortly.

Mobile Ads SDK Forum Advisor

unread,
Apr 25, 2024, 6:11:33 PMApr 25
to liaosh...@gmail.com, google-adm...@googlegroups.com

Hi,

If you are having AdRequest.Builder instance, please follow the below approach:

AdRequest.Builder requestBuilder = new AdRequest.Builder();

requestBuilder.addCustomTargetingParameter(“Key”: “Value”);

If any custom Mediation using, then Create Bundle:

Bundle extras = new Bundle();

extras(“Key”: “Value”);

Set extras on AdRequest.Builder

requestBuilder.setMediationExtras(mediationExtras);

Now you can retrieve them by overriding loadAd

@Override

public void loadAd(MediationBannerAdConfiguration configuration, MediationResponseCallback callback) {

    Bundle extras = configuration.getMediationExtras();

    if (extras != null) {

        String value1 = extras(“Key”);

        String value2 = extras(“Key”);

    // Here you can use value for

    }

    // Handle here as per your mediation network requirements.

}

Kindly reach out to us, if you need any further assistance.

EdisonLiao

unread,
Apr 26, 2024, 5:42:22 AMApr 26
to Google Mobile Ads SDK Developers
Yes, I am using AdRequest.Builder, but I can not find the method "requestBuilder.setMediationExtras(mediationExtras)" which you reply to me, and I am using the ads SDK version is: com.google.android.gms:play-services-ads:20.2.0, what's more, in 23.0.0 version still not find the method "requestBuilder.setMediationExtras(mediationExtras)" . Can you reply me base on the exactly SDK version?

Mobile Ads SDK Forum Advisor

unread,
Apr 26, 2024, 11:34:39 AMApr 26
to liaosh...@gmail.com, google-adm...@googlegroups.com
Hi,

Thank you for providing detail. 

i will check this and get back to you shortly.

Mobile Ads SDK Forum Advisor

unread,
May 2, 2024, 6:55:10 AMMay 2
to liaosh...@gmail.com, google-adm...@googlegroups.com
Hi,

Kindly ignore our previous replies.
 
public static final class MediationExtrasBundleBuilder {

  // Keys to add and obtain the extra parameters from the bundle.
  public static final String KEY_AWESOME_SAUCE = "awesome_sauce";
  public static final String KEY_INCOME = "income";

  /**
   * An extra value used to populate the "ShouldAddAwesomeSauce" property of the Sample SDK's ad
   * request.
   */
  private boolean shouldAddAwesomeSauce;

  /**
   * An extra value used to populate the "income" property of the Sample SDK's ad request.
   */
  private int income;

  public MediationExtrasBundleBuilder setShouldAddAwesomeSauce(
      boolean shouldAddAwesomeSauce) {
    this.shouldAddAwesomeSauce = shouldAddAwesomeSauce;
    return MediationExtrasBundleBuilder.this;
  }

  public MediationExtrasBundleBuilder setIncome(int income) {
    this.income = income;
    return MediationExtrasBundleBuilder.this;
  }

  public Bundle build() {
    Bundle extras = new Bundle();
    extras.putBoolean(KEY_AWESOME_SAUCE, shouldAddAwesomeSauce);
    extras.putInt(KEY_INCOME, income);
    return extras;
  }
}

setup the extras Bundle as mentioned in the above code and pass the adapter class and extras bundle through addNetworkExtrasBundle.

AdRequest request = new AdRequest.Builder()
       .addNetworkExtrasBundle(SampleAdapter.class, extras)
       .build();
// replace SampleAdapter.class with your custom event class.

Kindly refer this GitHub repository for further assistance.

Hope this helps and thank you for your patience.
Reply all
Reply to author
Forward
0 new messages