Một số bộ chuyển đổi mạng hỗ trợ các tham số bổ sung có thể được chuyển đến bộ chuyển đổi khi yêu cầu quảng cáo được tạo. Các tham số này được gọi là phần phụ của mạng.
Trình bổ trợ Google Mobile Ads cung cấp các API trên Android và iOS cho phép bạn chuyển phần phụ của mạng đến bộ chuyển đổi dàn xếp. Để làm như vậy, bạn cần triển khai
MediationNetworkExtrasProvider trên Android và
FLTMediationNetworkExtrasProvider trên iOS, sau đó đăng ký quá trình triển khai trình cung cấp phần phụ với trình bổ trợ. Sau đó, trình bổ trợ sẽ sử dụng trình cung cấp này để chuyển qua phần phụ của mạng khi tạo yêu cầu quảng cáo trên Android hoặc iOS.
Đăng ký MediationNetworkExtrasProvider trên Android
Tạo quá trình triển khai 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;
}
}
Sau đó, đăng ký quá trình triển khai này với 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());
}
}
Bạn có thể xem những phần phụ được các mạng khác nhau hỗ trợ và cách tạo các phần phụ đó trong tài liệu tham khảo về Android cho mạng cụ thể network.
Đăng ký FLTMediationNetworkExtrasProvider trên iOS
Tạo quá trình triển khai 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
Và đăng ký quá trình triển khai này với 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
Bạn có thể xem những phần phụ được các mạng khác nhau hỗ trợ và cách tạo các phần phụ đó trong tài liệu tham khảo về iOS cho mạng cụ thể đó.
Ví dụ hoàn chỉnh trên GitHub
Mẫu của chúng tôi minh hoạ cách đặt các tham số tuỳ chỉnh trên AppLovin trong quá trình tích hợp.