ネットワーク アダプタによっては、広告リクエストの作成時にアダプタに渡すことができる追加のパラメータをサポートしています。これらはネットワーク エクストラと呼ばれます。
Google Mobile Ads プラグインは、ネットワーク エクストラをメディエーション アダプタに渡すことができる API を Android と iOS で提供します。そのためには、Android で MediationNetworkExtrasProvider
、iOS で FLTMediationNetworkExtrasProvider
を実装し、プラグインに extras プロバイダの実装を登録する必要があります。その後、プラグインは Android または iOS で広告リクエストを作成するときに、ネットワークの追加パラメータを渡すためにこの値を使用します。
Android で MediationNetworkExtrasProvider を登録する
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 リファレンスをご覧ください。
GitHub のサンプルコードの全文
このサンプルでは、統合で AppLovin にカスタム パラメータを設定する方法を示します。