某些网络适配器支持额外的参数,这些参数可在创建广告请求时传递给适配器。这些称为“影音平台加购内容”。
Google 移动广告插件在 Android 和 iOS 上提供了一些 API,可让您将广告资源网路 extras 传递给中介适配器。为此,您需要在 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 参考文档中查看哪些 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 参考文档中查看哪些加购项受支持以及如何构建这些加购项。
GitHub 上的完整示例
我们的示例演示了如何在集成中为 AppLovin 设置自定义参数。