部分聯播網轉接程式支援額外的參數,可在建立廣告請求時傳遞至轉接程式。這些配額稱為網路額外項目,
Google Mobile Ads 外掛程式提供 Android 和 iOS 上的 API,可讓您將聯播網額外項目傳遞至中介服務轉接程式。如要這麼做,您需要在 Android 上實作 MediationNetworkExtrasProvider
並在 iOS 上實作 FLTMediationNetworkExtrasProvider
,然後以該外掛程式註冊額外供應商實作項目。之後,外掛程式就會在 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 參考資料中建構這些額外功能。