ネットワーク固有のリクエスト パラメータ

一部のネットワーク アダプタは、広告リクエストの作成時にアダプタに渡すことができる追加パラメータをサポートしています。これらはネットワーク エクストラと呼ばれます。

Google Mobile Ads プラグインには、Android と iOS 向けに、ネットワーク エクストラをメディエーション アダプタに渡すための API が用意されています。そのためには、Android では MediationNetworkExtrasProvider、iOS では FLTMediationNetworkExtrasProvider を実装し、エクストラ プロバイダの実装をプラグインに登録する必要があります。その後、プラグインは Android または iOS で広告リクエストを作成するときに、この ID を使用してネットワーク エクストラを渡します。

MediationNetworkExtrasProvider を Android に登録する

MediationNetworkExtrasProvider の実装を作成します。

class MyMediationNetworkExtrasProvider implements MediationNetworkExtrasProvider {

  @Override
  public Map<Class<? extends MediationExtrasReceiver>, Bundle> getMediationExtras(
      String adUnitId, @Nullable String identifier) {
    // This example passes extras to the AppLovin adapter.
    // This method is called with the ad unit of the associated ad request, and
    // an optional string parameter which comes from the dart ad request object.
    Bundle appLovinBundle = new AppLovinExtras.Builder().setMuteAudio(true).build();
    Map<Class<? extends MediationExtrasReceiver>, Bundle> extras = new HashMap<>();
    extras.put(ApplovinAdapter.class, appLovinBundle);
    // Note: You can pass extras to multiple adapters by adding more entries.
    return extras;
  }
}

次に、これを GoogleMobileAdsPlugin で登録します。

// Register a MediationNetworkExtrasProvider with the plugin.
public class MainActivity extends FlutterActivity {

  @Override
  public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
    super.configureFlutterEngine(flutterEngine);

    // Register your MediationNetworkExtrasProvider to provide network extras to ad requests.
    GoogleMobileAdsPlugin.registerMediationNetworkExtrasProvider(
        flutterEngine, new MyMediationNetworkExtrasProvider());
  }
}

各ネットワークでサポートされているエクストラと、それらのエクストラの作成方法については、特定のネットワークの Android リファレンスをご覧ください。

iOS で FLTMediationNetworkExtrasProvider を登録する

FLTMediationNetworkExtrasProvider の実装を作成します。

@implementation MyFLTMediationNetworkExtrasProvider

- (NSArray<id<GADAdNetworkExtras>> *_Nullable)getMediationExtras:(NSString *_Nonnull)adUnitId
                                       mediationExtrasIdentifier:
                                           (NSString *_Nullable)mediationExtrasIdentifier {
  // This example passes extras to the AppLovin adapter.
  // This method is called with the ad unit of the associated ad request, and
  // an optional string parameter which comes from the dart ad request object.
  GADMAdapterAppLovinExtras *appLovinExtras = [[GADMAdapterAppLovinExtras alloc] init];
  appLovinExtras.muteAudio = NO;
  // Note: You can pass extras to multiple adapters by adding more entries.

  return @[ appLovinExtras ];
}
@end

これを FLTGoogleMobileAdsPlugin で登録します。


@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GeneratedPluginRegistrant registerWithRegistry:self];

  // Register your network extras provider if you want to provide
  // network extras to specific ad requests.
  MyFLTMediationNetworkExtrasProvider *networkExtrasProvider =
      [[MyFLTMediationNetworkExtrasProvider alloc] init];
  [FLTGoogleMobileAdsPlugin registerMediationNetworkExtrasProvider:networkExtrasProvider
                                                          registry:self];
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

@end

各ネットワークでサポートされているエクストラと、それらのエクストラの作成方法については、特定のネットワークの iOS リファレンスをご覧ください。