พารามิเตอร์คำขอเฉพาะเครือข่าย

อแดปเตอร์เครือข่ายบางตัวรองรับพารามิเตอร์เพิ่มเติมซึ่งส่งไปยัง อแดปเตอร์ได้เมื่อสร้างคำขอโฆษณา ซึ่งเรียกว่าส่วนเสริมของเครือข่าย

ปลั๊กอินโฆษณาในอุปกรณ์เคลื่อนที่ของ Google มี API ใน Android และ iOS ที่ช่วยให้คุณส่ง ข้อมูลเพิ่มเติมของเครือข่ายไปยังอะแดปเตอร์สื่อกลางได้ โดยคุณต้องใช้ MediationNetworkExtrasProvider ใน Android และ FLTMediationNetworkExtrasProvider ใน iOS จากนั้นลงทะเบียนการติดตั้งใช้งานผู้ให้บริการ ส่วนเสริมกับปลั๊กอิน หลังจากนั้นปลั๊กอินจะใช้พารามิเตอร์นี้ เพื่อส่งต่อข้อมูลเพิ่มเติมของเครือข่ายเมื่อสร้างคำขอโฆษณาใน Android หรือ iOS

ลงทะเบียน MediationNetworkExtrasProvider ใน Android

สร้างการติดตั้งใช้งาน 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 สำหรับเครือข่ายที่เฉพาะเจาะจง

ลงทะเบียน FLTMediationNetworkExtrasProvider ใน iOS

สร้างการติดตั้งใช้งาน 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 ในการผสานรวม

สื่อกลาง