某些广告联盟适配器支持额外的参数,这些参数可以在创建广告请求时传递给适配器。这些内容称为“影音平台额外信息”。
Google 移动广告插件在 Android 和 iOS 上提供了 API,可让您将广告联盟 extra 传递给中介适配器。为此,您需要在 Android 上实现 MediationNetworkExtrasProvider
,在 iOS 上实现 FLTMediationNetworkExtrasProvider
,然后向插件注册 extras 提供程序实现。之后,该插件在 Android 或 iOS 上创建广告请求时,将使用该 ID 传递广告联盟额外参数。
在 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 参考文档中查看不同影音平台支持哪些 extra,以及如何构建这些 extra。
在 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 参考文档中查看不同影音平台支持哪些 extra 以及如何构建这些 extra。