🎨How to pass predefined custom targeting values in ad request (Only for GAM)

Below are the steps to pass predefined custom targeting value in ad request for GAM (Supported by all ad formats)

  1. Create your AdRequestConfiguration as per the below format

AdRequestConfiguration.Builder configuration = AdRequestConfiguration.Companion.builder(context, "Your_placement_name");
  1. Adding predefined ad targeting parameters to AdRequest

Single key with single value
configuration.addCustomTargetingValue("YOUR_KEY","YOUR_VALUE");
Single key with multiple values
configuration.addCustomTargetingValue("YOUR_KEY",List<String>);
Multiple keys with single value
configuration.addCustomTargetingValue("YOUR_KEY","YOUR_VALUE")
             .addCustomTargetingValue("YOUR_KEY","YOUR_VALUE");
Multiple keys with multiple values
configuration.addCustomTargetingValue("YOUR_KEY",List<String>)
             .addCustomTargetingValue("YOUR_KEY",List<String>);

Custom ad request can be created for all the ad types.

Here is an example of implementation with banner ad.

  1. Call loadAd() method as per below format

  1. Inside the onBannerAdLoaded callback method invoke getView() method of MediationnBannerAd object to add an AdSter banner view to the given layout as shown below

  1. Call MediationBannerAd.destroy() When activity/fragment is destroyed or detached.

Last updated

Was this helpful?