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. Đây được gọi là các dịch vụ bổ sung của mạng.
Trình bổ trợ Quảng cáo của Google trên thiết bị di động cung cấp các API trên Android và iOS cho phép bạn truyền
thông tin bổ sung về mạng đến các bộ chuyển đổi dàn xếp. Để làm việc này, bạn cần triển khai MediationNetworkExtrasProvider trên Android và FLTMediationNetworkExtrasProvider trên iOS, sau đó đăng ký cách triển khai trình cung cấp thông tin bổ sung với trình bổ trợ. Sau đó, trình bổ trợ sẽ sử dụng trình bổ trợ này để truyền qua các thành phần bổ sung 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 một phương thức 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ý bằng 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 tính năng bổ sung nào được các mạng khác nhau hỗ trợ và cách xây dựng các tính năng đó trong tài liệu tham khảo về Android cho mạng cụ thể.
Đăng ký FLTMediationNetworkExtrasProvider trên iOS
Tạo một phương thức 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ý bằng 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 tính năng bổ sung nào được các mạng khác nhau hỗ trợ và cách tạo các tính năng đó trong tài liệu tham khảo 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 tham số tuỳ chỉnh trên AppLovin trong một chế độ tích hợp.